Photo resistor
-
Upload
jonadri-bundo -
Category
Business
-
view
76 -
download
1
Transcript of Photo resistor
>_ Things Lab
Photoresistor circuit
Components needed:
• Photoresistor (1)
• LED (1)
• 330 Ohm Resistor (1)
• 104 Ohm Resistor (1)
• Wires (6)
The Circuit
Let’s try to explain simply
- 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
It’s going to be like this
• 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.
The code is:
const int sensorPin = 0;
const int ledPin = 9;
int lightLevel, high = 0, low = 1023;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
lightLevel = analogRead(sensorPin); analogWrite(ledPin, lightLevel);
}
void manualTune()
{
lightLevel = map(lightLevel, 0, 1023, 0, 255); lightLevel = constrain(lightLevel, 0, 255);
}
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);
}