Arduino UNO Tutorial NightLight

Posted on Feb 5, 2014

A Light Dependent Resistor (LDR) to create a simple childrens bedroom nightlight which turns on automatically when it gets dark and turns off when it gets light. An LDR`s resistance changes depending upon the amount of light hitting the sensor. For the LDR we are going to use the resistance reduces as the light falling on the device increases. Used in conjunction with a 4. 7K resistor this forms a

Arduino UNO Tutorial NightLight
Click here to download the full size of the above Circuit.

simple voltage divider where the voltage across the LDR changes dependent upon the light. We can then input this into one of the Analog to Digital inputs in the Arduino to measure the voltage. Then its a simple matter of checking whether the value is above or below a threshold value and to turn one of the outputs on or off. The circuit diagram is shown below. As the light increases, the LDR`s resistance drops and hence the voltage across it drops. Thus the voltage across the resistor increases, so the voltage into the Arduino ADC increases. The opposite is true as it gets darker. Below is the Arduino Sketch. In this sketch we are simply turning on the built-in LED if the ADC value drops below a specific value. To make a nightlight, a brighter led (with limiting resistor ~220 ohms) can be connected to the pin 13 output. In the code you will notice that there are some serial output statements that are commented out. If you uncomment these you will see on the serial monitor the current value of the voltage being read by the Arduino ADC input. This value is between 0 and 1024. Cover the LDR with your hand and shine a light on it to see the effect. /* *NightlightLDRtestprogram *Created06Feb2010 * *Thisexamplecodeisinthepublicdomain. * */ int sensorPin = A0; // select the input pin for the ldr unsigned int sensorValue = 0; // variable to store the value coming from the ldr void setup() { pinMode(13, OUTPUT); //Start Serial port...

Leave Comment

characters left:

Related Circuits

  • New Circuits



    Popular Circuits

    8 LED`s Audio VU Meter
    IF Amplifier using NE592
    Courtesy light extender
    Resistive Sensor Head (A2053) Manual
    avc serial to i2c bridge
    Multi Channel Remote Control System
    300w Mosfet Linear Amplifier For 50 Mhz
    USB Performance Monitor
    Effective Load Resistance