how to make an automatic night lamp with Arduino | Step by step instructions

 How to make an automatic night lamp with Arduino

            Hello guys, welcome back to another article from SriTu Tech. Today we are going to talk about how to make an automatic light lamp with Arduino. Also, this project is presented step by step, so it can be easily understood by everyone. The LDR sensor is mainly used for this project. Also, this project included an AC-powered light bulb. This bulb uses a relay module to activate it. So, we can use this project for gate and lamp towers.

Automatic light lamp process.

When the lamp is on, it produces less resistance when more light falls on the LDR sensor, and more resistance when less light falls on it. This LDR sensor is connected to the Arduino board by a voltage divider circuit, which causes a voltage change as the resistance increases or decreases. We can get that value with an analog pin. If it is greater than 900, the relay module is active, then the bulb is active, or the bulb is off.
So, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Arduino UNO board.

LDR sensor.

10k Resistor.

Relay module.

AC bulb holder.

AC bulb.

Cardboard.

Jumper wires and wires.

Step 2

Secondly, cut a 4×4 inch piece of cardboard. Then, cut a 1.5 x 4-inch piece to fit the Arduino UNO board. Afterward, glue the two pieces as follows. Use a glue gun for that.

Step 3

Thirdly, attach the Arduino board and relay module as shown below.

Step 4

Then connect the relay module to the Arduino board. For that, use the circuit diagram below.

 

Step 5

Then cut three 1.5 x 4-inch pieces and glue them together as appropriate.

Step 6

Then connect the wire to the Relay module to supply AC power.

Step 7

Next, connect the LDR sensor to the Arduino board.

Step 8

Now take a piece of 4×4 inch size and connect the LDR sensor to it. Then put out the wires that need to connect the AC bulb through it and glue that piece.

Step 9

Afterward, connect the Bulb holder and AC voltage connector.

Step 10

Now we will upload the required program. To do this, connect the Arduino board to the computer. The required program is as follows.
/*Dark active table lamp.
  created by the SriTu Tech team.
  Read the code below and use it for any of your creations.
*/
#define relay 2
#define sensor A2
void setup() {
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
  digitalWrite(relay,HIGH);
}
void loop() {
  int value = analogRead(sensor);
  if (value > 900) {
    digitalWrite(relay, LOW); //Bulb ON
    Serial.println(“Bulb on”);
  } else {
    digitalWrite(relay, HIGH); //Bulb Off
    Serial.println(“Bulb Off”);
  }
}

Code explanation

Firstly, the PINs that connect the Relay module and the LDR sensor are defined.
#define relay 2
#define sensor A2
In the Void setup, the pin connected to the relay module is configured as an OUTput pin. Also, the relay module is turned off. This is because the relay module is activated when the Arduino board is activated. Also, turning the relay module on and off is done in reverse. If you want to ON, you have to LOW. If you want to turn it off, you have to HIGH. Also, the serial monitor is enabled. Because we can also see the readings on the serial monitor.
void setup() {
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
  digitalWrite(relay,HIGH);
}
In the void loop, the LDR sensor reads the value and puts it in a variable named “value”. Then the value is checked by an IF condition and if the value is more than 900, the relay is turned on. The bulb can be turned ON and OFF by turning the relay on and off. These can also be viewed on a serial monitor.
void loop() {
  int value = analogRead(sensor);
  if (value > 900) {
    digitalWrite(relay, LOW); //Bulb ON
    Serial.println(“Bulb on”);
  } else {
    digitalWrite(relay, HIGH); //Bulb Off
    Serial.println(“Bulb Off”);
  }
}
OK, let’s now upload this code, For that, select the correct board and port. Afterward, upload this code.

Step 11

Finally, connect the AC voltage to the relay module. (Be very careful here. If you are a child, seek the help of an adult.) Then apply a voltage of 7 – 12 DC to the Arduino board. Now you can check this out. The full video guide is below. We will meet in the next tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *