• Armaan Created Project

    08/19/2016 | 5:48am

Loading Items

About This Project

In this project Arduino Mega 2560 board will be used to automate lamp. Lamp will glow automatically if sun sets and it will turn off automatically if sun rises or light around the sensor increases from the defined threshold. 
Request Access

Project Info


No skills have been added

Meet The Makers

Join Team
  • Armaan
    • User:Armaan
    • Rank:Tinkerer
    • Projects:1
    • Joined:2016

No Comments yet. Why don't you add one?

.Automatic light that turns on upon darkness / Sun set

.using arduino mega 2560

The Mega 2560 is a microcontroller board based on the ATmega2560. It has 54 digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.

Source: https://www.arduino.cc/en/Main/ArduinoBoardMega2560

In this project, light dependent resistor (LDR) will be used to sense the day light and mega 2560 will be programmed to operate a relay. This relay will turn on and off the light as it will act as a switch. The decision will be made on values obtained from the LDR.

.Relay module

Relay module will be used to obtain a digital signal from the mega 2560 and turn on/ off power of the lamp. Given below picture shows the relay module.

On the input side of relay module, there are three terminals. As from figure, one is 5 volts supply (red cable), second one is ground (black cable) and third one is signal terminal (brown cable). You can use your own cable, I have just changed colors to identify the signals.

.Attaching lamp and mega 2560 to relay module

From the above picture we can make connection of relay module. Steps of making connection to relay module can be described as;

1. On the output side of relay module, we will connect one wire coming from lamp to the normally open (NO marked on module) terminal and common terminal will be connected to AC main line (220Volts or 110Volts as per your country supply voltages) using wire.

2. Second wire of the lamp is also connected to the AC main line to complete the circuit.

After completing both steps circuit will be look like following picture;

Power to the relay module (i.e. 5 volts and ground) is provided directly from the mega 2560 board and digital signal terminal is connected to the port 13 of the board.
Note: Port 06 of mega 2560 will operate relay module.

.Building Light dependent resistor Circuit

LDR have very high resistance in the absence of light. Usually they have near 1 megaOhm resistance in darkness. As light falls on the LDR, it resistance starts decreasing. On a fully shiny surface of LDR, it resistance can drop upto 100 Ohm. Thus, it is placed with 10 kilo Ohm resistor in series with LDR to prepare a light sensing circuit as shown in given below figure.

Note: Connect the analog input from this circuit to A0 pin on the mega 2560 board.
Once you connect the analog input to the mega 2560, you can write code to make the circuit behave in right direction. I have used bread board to demonstrate circuit. However, for outdoor mounting of circuit it is recommended that PCB must designed or proper enclosure must be placed around circuit with a window for daylight to fall on LDR.

The LDR circuit with it's cable obtained for sensing value is shown in given below figure.

A more close-up picture is shown below.

This green cable is connected to analog input of the board. In this project it is connected to the pin A0. This is shown in following picture.

.Project Demo

The complete circuit in OFF state is shown below.

The complete circuit in ON state is shown below.


There are two signal cables in the circuit.
1. Connected between resistor and LDR which is shown as green cable in above diagram. This wire will be connected from sensor to the pin A0 (analog input) of the board.
2. Connected to the relay module PIN (IN). Pin 6 of the board is connected to the IN marked pin on the relay module to drive the relay.
Other four cables are just power to circuit. Two cables are obtained from 5 volts of board and other two are connected as ground to the circuit.
The schematic is shown in given below picture.

A video of working of project is as follows.

Arduino Software

Arduino Software is required to compile the code.
It is available free of cost on official site. | Arduino - Software

  Details Downloads Size Get it


Last updated on 08/19/2016

by Armaan

490 637b
Qty   Item Where to Find Est. Cost More Info
1 Arduino Mega 2560 Item Number: Mega 2560

Arduino Mega 2560

Item #: Mega 2560

1 Single Channel Relay Item Number: SRD-S-124D

Single Channel Relay

Item #: SRD-S-124D

$2.00 1 file  


Updated 6/26/2016 by jamesshawver1
1 Light Dependent Resistor (LDR)

Light Dependent Resistor (LDR)

$4.34 1 file  


Updated 12/22/2016 by swym_admin
1 10k resistor

10k resistor

6 Jumper Wire

Jumper Wire

1 Light Bulb

Light Bulb

1 Lamp Holder

Lamp Holder