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

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

Hello guys, welcome back to another article from SriTu Hobby. 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.

Process of Automatic light lamp

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.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases

Step 1

Firstly, identify these components.

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, install 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.

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

Step 5

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

Step 6

Next, connect the wires to the Relay module to supply AC power.

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

Step 7

Now, connect the LDR sensor to the Arduino board.

Step 8

Next, 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.

  • The complete program of this project – Download
/*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 Relay module and the LDR sensor pins 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, 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 small child, ask an adult for help.) Then apply a 7 – 12 DC voltage to the Arduino board. Now you can check this. The full video guide is below. See you in the next project. Have a good day.

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

Leave a Comment

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

Shopping Cart
Select your currency
USD United States (US) dollar
EUR Euro
Scroll to Top