Thursday, October 20, 2011

Circuit-09 - Light Resistors

Purpose: To test how photo resistors responds to different amounts of light.

Equipment:
  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC-09 Breadboard Sheet x 1
  • Photo Resistor x 1
  • 330 Ohm Resistor x 1
  • 10k Ohm Resistor x 1
  • LED x 1
  • Wire x 6

References:

Program Details: In this exercise, a Photo resistor is introduced. A photo resistor senses light and returns a voltage value. A photo resistor must be connected to a resistor, an analog pin, as well as to ground but it only has 2 pins. So how can this be done? Well the resistor and the analog pin are both connected to one lead and the ground is connected to the other lead.

Yet again, the programming is very simple. Only two new method are introduced, both which are very easy to understand. First map(lightLevel, 0, 900, 0, 255); what it does is assign a new range to lightLevel. Instead of it going from 0 - 900, it now goes from 0 - 255. Next is constrain(lightLevel, 0, 255); which makes sure that the range of lightLevel is between 0 - 255. The rest of the code is very simple as is the exercise. 

Time to Complete: 10 mins to assemble
                                10 mins to code

Results: The LED turned on and the circuit worked. However, when there is a change in the lighting in the room, the LED only grows dimmer or brighter very slightly. Even when the light was turned off, the LED grew slightly brighter. I think this is because the photo resistor is not the greatest so there was nothing wrong with the circuit or the program.

Photos: 

Circuit 9  with light on
Circuit 9 with light off
Tips:
  • Try controlling 2 or more LEDs rather than just one because this circuit is easy
  • Don't forget to attach a resistor connected to your photo resistor as shown in the schematic 


Further Work:
I will control the LED to do the opposite, so when there is a greater amount of light, the LED will grow brighter and when there is a lower amount of light, the LED will grow dimmer. I will also try to control a small servo using the photo resistor.

Program Modifications: The program is the exact same one from the link below
http://ardx.org/src/circ/CIRC09-code.txt

Program:
int lightPin = 0;   // photoresistor pin is connected to analog pin 0 
int ledPin = 9;    // LED pin is connected to pin 9

void setup()
{
  pinMode(ledPin, OUTPUT);    //sets the led pin as an output
}

void loop()
{
 int lightLevel = analogRead(lightPin);             // The light level from the lightPin is stored in lightLevel
 lightLevel = map(lightLevel, 0, 900, 0, 255); // Changes the range (from 0-900) to 0 - 255 (which is colour) 
 lightLevel = constrain(lightLevel, 0, 255);      // Makes sure that the value is between from 0 - 255
 analogWrite(ledPin, lightLevel);                    // Writes the value into ledPin from lightLevel 
 }// ends loop

No comments:

Post a Comment