Photo resistor

10
>_ Things Lab Photoresistor circuit

Transcript of Photo resistor

Page 1: Photo resistor

>_ Things Lab

Photoresistor circuit

Page 2: Photo resistor

Components needed:

• Photoresistor (1)

• LED (1)

• 330 Ohm Resistor (1)

• 104 Ohm Resistor (1)

• Wires (6)

Page 3: Photo resistor

The Circuit

Page 4: Photo resistor

Let’s try to explain simply

Page 5: Photo resistor

- 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

It’s going to be like this

Page 7: Photo resistor

• 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

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

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

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);

}