Introduction: Arduino Light Intensity Lamp
My name is Vigas Balachandran and in this instructable, I will be teaching you how to create your own Arduino Light Intensity Lamp by using a relay. A relay is a type of switch that allows low power electronics to connect with high power devices. In this case, the relay allows the low voltage arduino board connect to the high voltage lightbulb.
Now lets look at the materials needed for this project!
Step 1: Materials Needed
For this project, you will need 6 key components. These components are...
1. Arduino Micro Controller (1)
2. Power source (Battery/Power Supply) (1)
3. Relay (Relay SPDT) (1)
4. Lightbulb (1)
5. Photoresistor (1)
6. 1k Ohm resistor (1)
You will also need wires to connect all of the components together. One optional material is a breadboard, to help with organizing all of your components.
Let's go onto the wiring that needs to be done for this project!
Step 2: Wiring
Now for the wiring, the diagram above can be used as a guide to help since it has all the connections between the components.
1. To start off, you need to connect the power source.
- Connect the positive terminal of power supply with terminal 2 of the light bulb
- Connect the negative terminal of the power supply to terminal 1 of the Relay.
- If you are using a breadboard, connect both the power and ground of the breadboard with the opposite side to circulate the voltage throughout the breadboard (If you are not using a breadboard, skip this step)
2. Relay connections
Since you have all the power connections sorted out, you want to focus on the relay connections since that component is one of the important components.
- Connect terminal 7 of the relay to terminal 1 of the light bulb
- Connect terminal 5 of the relay to one of the digital pins on the Arduino Micro Controller (the pin you choose does not matter, but that spot will be important in the coding)
- Finally, if you are using a bread board, connect terminal 8 into the ground of the breadboard. Then connect the ground of the Arduino Micro controller into the ground of the breadboard. Lastly connect terminal 1 of the Photoresistor into the ground of the breadboard
-If you are not using a breadboard, connect terminal 8 into the ground of the Arduino Micro Controller as well as terminal 1 of the Photoresistor
3. Connect the Resistors
All that's left to do is connect the photoresistor and the 1k Ohm resistor into the circuit
- With terminal 1 of the Photoresistor connected to ground, connect terminal 2 to one of the analog pins (same thing applies from the digital pin) as well as to terminal 1 of the 1k Ohm resistor.
- Connect terminal 2 of the resistor to the 5V of the Arduino Micro Controller
By following these steps, you will have completed the wiring for the Arduino Light Intensity Lamp. Now that the wiring is done, to fully complete this project, we need to finish the coding for the Arduino.
Step 3: Coding
The final task that needs to be completed to finish this project is the coding for the Arduino Micro Controller. In this project, since we are connecting the Arduino to another device, we will need to use serial. The serial controls allow the Arduino to control the device which in this case is the light bulb.
1. Add Variables
The first thing to do is to add the variables from the pins that you have selected from before. Based on the digital pin and the analog pin you chose, create a "const int" variable and name the variable as you please. The key step here is to set the variables equal to what pin you chose.
For ex. In my project, I chose both the digital pin 6 and the analog pin A0. I named the variables both pin6 and analog. I wrote the variables as following...
- const int pin6 = 6;
- const int analog = A0;
2. Setup Method
Now that you have created the variables, they now need to be incorporated into the setup method to actually be connected into the circuit. We need to establish which one is input and output. By using pinMode, you can set the pins to be either input or output. In this case, since the analog pin is connected to the photoresistor, that would mean that it is the input since the photoresistor will be controlling the current that passes through. If the analog pin is the input, then that would mean that the digital pin would be the input
In the setup method, it will look like the following.
- pinMode(analog, INPUT);
- pinMode(pin6, OUTPUT);
A key step that you must do is add the serial connection. As of now, there isn't exactly a connection between the Arduino and the circuit. By putting [Serial.begin(9600)], you establish the serial connection between the Arduino board and the circuit.
3. Loop Method
The last part to add to the code is the loop method. In the loop method is where we add the specific commands to control the device. To start, we need a way to read and display the analog signals that are being inputed from the photoresistor. To do so, you need to add...
- Serial.println(analogRead(analog));
By doing this, the analog signals from the analog variable get read and then displayed in the serial monitor. The serial monitor helps track precise values that are being inputed. Now that the signals can be read, we need a way to modify them from the photoresistor so that the brightness can change. To modify the signals, you need to create an if statement that changes the brightness of the digital pin depending on the analog value. To do so, you need to add...
- if (analogRead(analog) > 500) {
digitalWrite(pin6,LOW);
else{
digitalWrite(pin6,HIGH);
By doing this, you can change the brightness of the lightbulb from the photoresistor. If the photoresistor signal is less than 500, then the lightbulb will not light up. However if the signal is greater than 500, then the lightbulb will light up. In other words, when the photoresistor allows more light, less current is let through and when the photoresistor allows less light, more current is let through.
This can be reversed to serve as a normal lamp simply by changing the voltage of the digital pin in the code. By changing the HIGH to a LOW in the if statement and same thing for the else statement, the light bulb will increase its brightness with more light allowed into the photoresistor.
Step 4: Demo
Now that you have successfully completed this project, to see what the final results appears like, download the .mov file linked below.
To conclude, my name is Vigas Balachandran and congratulations on completing the Arduino Light Intensity Lamp project!