Photo resistor
-
Upload
jonadri-bundo -
Category
Business
-
view
76 -
download
1
Transcript of Photo resistor
![Page 1: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/1.jpg)
>_ Things Lab
Photoresistor circuit
![Page 2: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/2.jpg)
Components needed:
• Photoresistor (1)
• LED (1)
• 330 Ohm Resistor (1)
• 104 Ohm Resistor (1)
• Wires (6)
![Page 3: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/3.jpg)
The Circuit
![Page 4: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/4.jpg)
Let’s try to explain simply
![Page 5: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/5.jpg)
- The green wire goes into A0 which is analog 0
- The pink wire goes into pin 9
- The red wire goes into 5 volt pin
- The black wire goes into gnd pin which is ground
![Page 6: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/6.jpg)
It’s going to be like this
![Page 7: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/7.jpg)
• After the circuit is built, download SIK Guide Code. Open SIK Guide Code/Circuit_06/Circuit_06.ino and there is the code that you will upload to Arduino so the circuit will work.
![Page 8: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/8.jpg)
The code is:
const int sensorPin = 0;
const int ledPin = 9;
int lightLevel, high = 0, low = 1023;
void setup()
{
pinMode(ledPin, OUTPUT);
}
![Page 9: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/9.jpg)
void loop()
{
lightLevel = analogRead(sensorPin); analogWrite(ledPin, lightLevel);
}
void manualTune()
{
lightLevel = map(lightLevel, 0, 1023, 0, 255); lightLevel = constrain(lightLevel, 0, 255);
}
![Page 10: Photo resistor](https://reader035.fdocuments.us/reader035/viewer/2022071814/55a6a5be1a28abe72e8b464a/html5/thumbnails/10.jpg)
void autoTune()
{
if (lightLevel < low)
{
low = lightLevel;
}
if (lightLevel > high)
{
high = lightLevel;
}
lightLevel=map(lightLevel,low+30,high-30,0,255);
lightLevel=constrain(lightLevel, 0, 255);
}