Basic led brightness control circuit with ldr and passive components
Main functionality of the above traditional light dimmer circuit
- Current passing through LDR increases/decreases depending on the amount of light thrown on the light detector. This current is input to the base of NPN transistor.
- Varying current at input base of transistor varies the voltage across led, connected to collector side of transistor.
LED brightness control using Light dependent resistor
- Determine the current/voltage allowed by light sensor to pass through it.
- Output a voltage on its digital pin to fade led. Output voltage is dependent on the current/voltage allowed to pass by light sensor(Or intensity of light).
How to determine the amount of voltage allowed by LDR to pass through it using Arduino Uno?
Arduino has a 10-bit ADC module. It can measure maximum voltage of rating on which arduino is working typically 5 volts precisely. 10-bit ADC max reading value is 1024. So 1024 corresponds to 5 volts. 512 corresponds to 2.5 volts and 0 represents no voltage. Adruino uno has 6 analog channels. We can use any one of them for our project.
To read an analog voltage we use the command
Val = analogRead(analogPin);
Where analogPin is analog channel used(A0—-A5) and Val is variable in which analog value returned by the function is saved.
So we are done with reading the light sensor allowed passing voltage which corresponds to the intensity of light.
How to fade/control brightness of led with arduino uno?
PWM(Pulse width modulation) is basic technique used by microcontrollers to fade or control the brightness of led. PWM actually outputs a varying voltage on digital pins of microcontroller. Varying voltage is generated using the timers of microcontrollers. I assume you people know about PWM. In case no, I am just giving a short introduction.
PWM utilizes timers and a particular pin is switched on and off for a specified period of time. On period is generally know as duty cycle we can compute the output voltage by changing the duty cycle. 100% duty cycle represents full voltage output and 50% duty cycle outputs half voltage.
PWM(Pulse width modulation) using Arduino
In the project below I am going to read analog signal from LDR(light detecting resistor) and then write the signal corresponding pwm value to led in order to fade it. Actually writing means fading led. Analog Write outputs value in the form of PWM(Pulse width modulation). For high values PWM duty cycle will be high and for low values PWM(Pulse width modulation) duty cycle will be low.
Fading led with ardino and light sensor – Project circuit diagram
May be you people are thinking why we connect the wire in between the LDR and 10 k ohm resistor or why we use resistance here. Well their is a big logic behind it. Actually LDR normally has very high resistance and in this condition no current flows through it and when light is thrown on its surface its resistance decreases and it allows the current to flow through it. In the schematic if i directly connect the LDR with the A0 analog pin of Arduino and shine/through some light on it whole of the 9 volt will start appearing across the analog pin of arduino. Which might destroy the arduino analog channel or potentially arduino board. Since arduino operates on 5 volts so its pins can only sink 5 volts. Any voltage greater than the operational voltage(5 v) can destroy the arduino board or produces buggy output. R2 is used to lower down the voltage appearing on the arduino analog channel in its acceptable range(0-5 volts).
Using 9 volts are even dangerous you can reduce it to 5 volts. Since light dependent resistor resistance plays an important role in determining the below of R2. We need some extra resistance calculations which is hard to understand at this level. So its better to use 5 volts as input.
Connect led anode to pin# 9 of arduino and cathode to ground in series with a resistor.
Arduino led brightness control- Project Code
Note: You have a choice to declare arduino analog pin as input or not. It will work if you do not define it but you are bound to define all other pins that are not used as analog input. I did not declared it as input in setup function.
Next in the void loop function i started reading the output voltage value by light sensor from analog channel 0. The code statement int reading=analogRead(sensor) reads the sensor output voltage and place the numeric value in variable reading.
I divided the reading by 4. This is because arduino analog channel outputs analog value ranging from 0 to 1023. Where as arduino PWM function analogWrite() can only output the values ranging from 0 to 255. So to brought the read value in 0 to 255 range i divided the reading by 4. Now 1023 corresponds to 255, like wise 1000 to 250 and 0 to 0. At last I outputted the analog read value corresponding pwm signal on pin 9 using analogWrite() function.
See the Project Video Here…
Arduino light detector – Future Work
- Project logic can be altered, increasing light intensity to decrease led brightness and decreasing light intensity to increase led brightness.
- Project can be used as light detector switch to toggle bulb on and off during night and day time.
- Room security alarm can be made with ldr to detect if some one entered and switched on the light.