# LED Intensity Control Using LDR

20,649

2

1

To automatically control the intensity of led using the ldr and the pwm pins of the arduino.

(further used in automatic street light intensity control)

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Understanding LDR and PWM Pins of Arduino

There are many awesome references to understand the working of PWM pins of ardunio . In simple terms the PWM refers to the pulse with modulation feature of the arduino. In the pwm pins the output signal via a pwm pin will be an analog signal ( at least it behaves like one) acquired as a digital signal from the arduino .It uses the duty cycle of the digital wave to generate the consequent analog value for the signal.

Here is the link for more knowledge on pwm: https://www.arduino.cc/en/Tutorial/PWM

LDR:

light dependent resistor is the sensor which varies the resistance upon the falling of light. The resistance of LDR decreases with the increasing intensity of light and vice versa . The ldr gives analog output values and connected to the analog pin on the arduino . The output from ldr is used to control the intensity of led bulb.

There is an inbuilt ADC(analog to digital converter) present in the arduino uno with 10-bit resolution from (0 to 1023).

The analog value from the ldr is converted to the digital values with the help of inbuilt ADC in arduino to give values in range(0-255) digital values.

## Step 2: Components Required

Following components are required to control the intensity of LED using pwm pin of arduino and LDR :

1. LDR (light dependent resistor)

2. Arduino UNO

3. LED

4. wires (jumper)

5. resistors (1k,100k)

6. Battery (for UNO)

## Step 3: Connection

Connections are very simple,the following connections are to be applied:

Connect the +5V VCC pin of the arduino to the one end of LDR fixed on the breadboard .

Connect other end of the LDR to the resistor (100k) and from this end of ldr itself connect the wire to the analog pin (A0) from the arduino and the other end of the resistor is connected to ground and thus forming a potential divider circuit .(POT. can also be used in its place to det. the best resistance for LDR)

Connect the pwm digital output pin(3) of the arduino to the anode(+) of the LED and the cathode(-)of the LED is connected to ground via 1k resistor.(use different value to get stable brightness).

Connect the power supply to the arduino.

## Step 4: CODE

The code for the automatic intensity varying of light with the help of ldr is attached below . The program is fairly simple . The input from ldr is taken at A0 and supplied via arduino to the pwm pin 3

However we need to lookout for two functions of the arduino code :

constrain() : this function is used to constrain the analog values of the ldr to a specific range (900-1010 for me) and can be different for you and u need to check the value using your serial monitor and then constraint it consequently. If we will not constraint the values then we won`t be able to check the difference in the light intensity of led.

map() : we require this function to map the analog values of the ldr in (0-1023) range to digital (0-255) values with the help of inbuilt adc in arduino and then supplied to pwm pin of the arduino. [ I have used the notation in code as map(value,900,1010,255,0) i.e. smaller value (0) after the larger value(255) to get the desired result for my ldr ,you can use the normal notation and if it won`t work then try mine)

constrain(): https://www.arduino.cc/en/Reference/Constrain

## Step 5: Working Description

The attached photos and an embedded video of the working control system is uploaded.

The intensity of light varies when the hand gets closer to the ldr until it reaches max value(255) for the led and decreases upon removal of hand slowly from above of the ldr as shown in video.

{stay tuned for next instructable on the motion detection using ldr and control of led in accordance with this}

thank you!

References :

https://myvirtualgarage.wordpress.com/2012/07/01/i...

Arduino forum and numerous similar instructables .

## Recommendations

• ### Internet of Things Class

22,754 Enrolled

## Discussions

Welcome to Instructables. Thanks for sharing with the community. You might also take a look at the contest section of the website. These projects would be a good fit for the Sensor contest.