Monitoring the output of a light-dependent resistor, or photoresistor, allows the Arduino to know how light or dark it is. When the light falls below a certain level, the Arduino turns on a couple of LEDs.
A light-dependent resistor, or photoresistor, is a sensor whose resistance decreases as the amount of light falling on it increases. When it is dark, the resistance of a photoresistor may be as high as a few MΩ. When it is light, however, the resistance of a photoresistor may be as low as a few hundred ohms.
In this experiment, we will connect a photoresistor to an Arduino analog input and read the value with the analogRead() function. Depending on the value the Arduino reads, the program will then set pin 3 HIGH or LOW to turn on or turn off the LED night lights. The threshold value is 150. When the analog value read is less than 150, the Arduino will turn the LEDs on. When the analog value it reads is below 150, the Arduino will turn the LEDs off.
- 1 x photoresistor
- 2 x LED
- 2 x 470 ohm resistors
- 1 x 1 kohm resistors
- 1 x Arduino Mega2560
- 1 x breadboard
- jumper wires
You connect the components as shown in the diagram below. Connect the LEDs to pin 3 of the Arduino. The two 470 ohm resistors are current limiting resistors. One lead of the photo resistor is connected to 5V, the other to one lead of the 1 kohm resistor. The other lead of the 10 kohm resistor is connected to ground. This forms a voltage divider, whose output is connected to pin A1 of the Arduino. As the light impinging on the photoresistor gets stronger, the resistance decreases, and the voltage output of the divider increase. The reverse happens, when the impinging light gets weaker.Setup
- Connect one of the two terminals of LDR to 5V and other one to the GND through a one kilo ohm resistor.
- Connect one end of a wire to analog pin A1 and other to 1K resistor’s non-grounded terminal.
- Connect two LEDs in parallel, both through a 470 ohm resistor and with negative terminal grounded as shown in above circuit diagram.
- Connect pin 3 to the positive terminals of LEDs through 470 ohm resistors.
- Connect all the grounded terminals to Arduino’s GND pin.
- Connect the Arduino using Arduino USB cable and upload the program to Arduino using Arduino IDE software.
- Provide power to the Arduino board using power supply, battery or USB cable.
A great sharing for beginners. Thanks for your efforts and I will follow you and keep reading your posts.