Most of you already know about Arduino and programming it, but those of you who do not know about its basics should read THIS instructable first.
It has everything you need to know about Arduino. I have used Mega 2560 in this instructable because it is kind of like the most commonly used model found.
Now about this title, I should tell you that we will be using a light sensor or LDR here and Arduino will be controlling the change in analog values of sensor. As an output we will be getting PWM for varying the intensity of the LED/Light Bulb.
Step 1: LDR
It stands for “Light Dependent Resistor”. It ‘s a type of resistor whose value changes with intensity or the amount of light falling on it. As the amount of light falling on it increases the its resistance decreases and the other way round.
We have made a circuit to give out a logic of 1 or 0 for our Arduino Board. The Circuit can be inverted in order to change the logic.
Step 2: ADC (Analog to Digital Converter)
Any microcontroller or digital operating device can not directly operate on analog voltage. We have to convert analog into digital values and for that we use ADC. Arduino has adc built in it so we just have to plug in a jumper wire for connection.
It takes in an analog value( in this case the voltage across the LDR) and converts it to a 10 bit digital. Since we have 10 bits, the output of the ADC ranges from 0-1023 ( i.e. 1024 values 2^10). Every voltage between 0 – 5V is mapped to a value between 0-1023. Why till 1023? The reason is the resolution of our ADC. Here we represent every value with a combination of 10 bits. As the number of bits used to represent a value increases, the output value gets much more accurate.
Value Bit Representation
0 – 1.25 00
Step 3: PWM (Pulse Width Modulation)
Pulse Width Modulation is a technique in which the width of the pulses can be varied according to the message signal. In this case the led is connected to a PWM output pin of the arduino board and using the analogWrite() function we make the width of the pulses on the pin vary. Varying the width of the pulses can be seen as varying the average voltage on the pin. So although we are only changing the amount of time for which the led is on or off, due to the persistence of vision it is as if we are varying the voltage across the led which causes it to fade and brighten up.
Step 4: Components Required
Now the components needed for this project. I promise these are very cheap and simple items (other than the Arduino Board itself :p )
- Arduino Mega 2560 Board
- LED (I used white and red ones)
- LDR or Photo Diode (I used LDR as it is cheap and easily available)
- 10 K Potentiometer
- 220 Ohm Resistor
- Bread Board or Perf Board (I have used both for testing)
- Jumper Wires
Step 5: Connections / Circuit
The connections are as follows:
- Connect one end of a resistor ( I have a 1k one…you can use any other value if you prefer.. just make sure it is not too high or too low) to the 5V pin of the arduino board. Connect the other end of the resistor to one end of the LDR. The other end of the LDR should be connected to the ground (GND).
- Take a wire from the junction of the resistor & the LDR connected earlier and connect it to the Analog Input 5 on the arduino board.
- Next take a wire from any of the PWM pins on your board and connect it to the Anode of the LED. Connect the cathode of the LED to one end of a resistor with the other end connected to the GND.
Step 6: Programming
The file made in arduino's software is attached if you want help from it.
Step 7: Breadboard Testing
I tested the circuit on Breadboard and found the right adjustment by moving the potentiometer a little. After I was satisfied I made a video which is attached below. Now it was time to make a more reliable and permanent circuit board.
Step 8: Final and Complete Model
So I soldered a more solid board for final experimentation. I used Red LED here as it showed the dimness and brightness light better than crystal light.
I hope you enjoyed reading the instructable as much as I enjoyed making it!!! :D