Purpose
The purpose of this circuit is to explore the function and application of a photo resistor.
Equipment
- 1 x Photo Resistor
- 1 x LED
- 1 x 330 Ohm Resistor
- 1 x 10k Ohm Resistor
- 6 x Wires
- 1 x Breadboard & Reference Sheet
- 1 x Arduino Uno
Program Details
The photo resistor is yet another type of resistor, except this time sensitive to light (photons). For this reason, in real life applications, the input value from this resistor can be fairly accurate. Another advantage is that the photo resistor doesn't require us, humans, to manipulate it. It is sensitive to the environment. When the setting is dark, there will be high resistance and no output, vice versa. The code for this program illustrates this more clearly.
However first, the circuit needs to be assembled, which takes 5-9 minutes. Follow the breadboard and attach the photo resistor properly. See the assembled circuit below.
The code for this program doesn't integrate analog and digital signals, it is purely analog. The photo resistor is the input, and the LED is the output. First, the photo resistor assigns a value to 'lightlevel'. This value is then adjusted so that it ranges from 0-255. The 'analogwrite' function can then take this value and use it to change the state of the LED accordingly.
Results
First we assumed that the photo resistor functioned the other way, so as to illuminate dark areas, so we thought we wired it wrong. However upon reading the guide and program, we understood it well. The circuit functions as it should, dimming and brightening according to the resistor. Another new aspect in the program we learnt was the ability to adjust the scale, and check over. This is the first time we've seen the program use a 'check for errors' mechanism with Arduino.
Tips
The only major tip would be to wire the resistor properly for the circuit to function, key aspect. The photo resistor is also a fragile and sensitive piece, so handle with care. With the programming, make sure the numerical values are accurate with the ranges. If the range is too big, the 'analogwrite' function will not work.
Next Steps & Associated Program Modifications
Again, small modifications to the program can change the results to lead to a different output. For instance, we can recreate what our group thought should happen with this circuit, dark room is illuminated, by simply altering the last line. See below.
int lightPin=0; //photo resistor is connected to analog pin 0.
int ledPin=9; //LED is connected to pin 9 (PWM)
void setup()
{ pinMode(ledPin, OUTPUT); } //the LED is output
void loop()
{
int lightLevel = analogRead(lightPin); //assign the input from the photo resistor to this
//new varuable
lightLevel = map(lightLevel, 0, 900, 0, 255); //scale the input to 0-255 instead of 0-900
lightLevel = constrain(lightLevel, 0, 255); //makes sure the scale is correct
analogWrite(ledPin, 255-lightLevel); //subtract the value from 255 and send it as output
//so that the LED functions opposite from the conventional way
}
Another easy modification is using the threshold method to create a switch. This follows the same principles as 'THE SWITCH' in the previous circuit.
Reference: Spark Fun Inventor's Guide