0% found this document useful (0 votes)
33 views8 pages

Automatic Light System with Arduino _ Project with Code

The document describes the design and implementation of an automatic light system for washrooms using Arduino Uno and IR sensors, which automatically turns the light on when a person enters and off when they leave. It details the circuit components, including the use of a relay and transistors for controlling the light, as well as the programming logic required for operation. The project aims to save electricity by preventing lights from being left on unnecessarily.

Uploaded by

kjeeva071213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

Automatic Light System with Arduino _ Project with Code

The document describes the design and implementation of an automatic light system for washrooms using Arduino Uno and IR sensors, which automatically turns the light on when a person enters and off when they leave. It details the circuit components, including the use of a relay and transistors for controlling the light, as well as the programming logic required for operation. The project aims to save electricity by preventing lights from being left on unnecessarily.

Uploaded by

kjeeva071213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Engineering Projects For You 1500+ Electronics Projects For You Arduino DIYs Intermediate Projects

Building Automatic Light System with IR Sensors


By Gowtaman G

February 16, 2021

The automatic light system, based on Arduino Uno and IR sensors is designed to
automatically switch the washroom light on and off, operating on AC mains. Whenever
a person enters the washroom, the light bulb (or tube light) will automatically turn on.

When the person leaves the bathroom, the light will turn off. This will save electricity
charges due to the light remaining on by mistake after the use of the washroom. The
author’s prototype is shown in Fig. 1.

Fig 1: Author’s prototype for Automatic Washroom Light Using IR Sensors

×
Circuit and Working

The circuit diagram of the automated washroom light is shown in Fig. 2. It is built
around Arduino Uno (Borad1), BC547 transistor (T1), infrared (IR) sensor modules
(Module1 and Module2), and relay (RL1).

- Advertis ement -

Fig. 2: Circuit diagram of automated washroom light

Infrared Sensor

The IR sensors (FC-51) used here (refer Fig. 3) are commonly used in obstacle-detection
projects. Two pairs of the IR sensor modules are used to detect a person’s entry or exit
from the washroom.

×
Fig. 3: IR sensor module

Each sensor has three pins, namely, Vcc, Vout, and GND. The Vcc pin is to be provided
with 5V DC supply, which can be taken from 5V pin of the Arduino Uno. The ground pin
(GND) of the sensor can be connected to GND pin of Arduino Uno.

- Advertis ement -

The Vout pins of IR Module1 and IR Module2 are the output pins connected to pins 8
and 7 of Arduino Uno, respectively.

The output of each sensor will be either 5V (high) or 0V (low) based on the detection.
When a person is detected, Vout is low, otherwise it is high (about 5V). These logic levels
of both the sensors are used to find out whether the person is entering or leaving the
washroom.

5V Relay

The 5V electromechanical relay (RL1) is used to switch on and switch off the light bulb. A
typical sugar-cube type 5V relay has five terminals, two of which are used for
energizing the coil. The rest are common (COM), normally closed (NC), and normally
open (NO) terminals.
×
The light bulb is connected between NO and COM contacts of the relay. As is obvious, in
normal condition, NO pin does not have any contact with the COM pin.

When the relay coil is energized, the COM pin touches the NO pin and the light bulb
gets 230V AC mains supply. Pin details of a typical sugar cube relay are shown in Fig. 4.

Fig. 4: Pin details of 5V sugar cube relay

The neutral (N) wire of the 230V AC source is connected to the light bulb through the
relay. The live (L) wire is directly connected to the light bulb.

When the ‘in’ sensor (Module2) detects a person followed by ‘out’ sensor (Module1), the
microcontroller in Arduino assumes that a person is entering the washroom and it
provides 5V at pin 9 of Board1.

The current from the output pin of Arduino is, however, insufficient to energize the
relay. So, NPN transistor T1 (BC547) is used for amplification to control the relay and
switch on the light.

When ‘out’ sensor detects a person followed by ‘in’ sensor, the microcontroller assumes
that a person is leaving and provides 0V at pin 9, which de-energizes the relay. This
disconnects the neutral and the light bulb switches off.

If only one of the two sensors is used, the current state will not change, so you need
both the sensors. The ‘in’ sensor should be placed just outside the washroom near the
door and the ‘out’ sensor should be placed inside the washroom near the door.

You need to install the sensors such that they can easily detect the person
× entering or

leaving the bathroom.


Automatic Light Coding

Arduino Uno is used to compute the logics of the two IR sensors. The circuit is
controlled through the software loaded in internal memory of the Arduino.

The program (bathroom.ino) is written in Arduino programming language. Arduino IDE


1.8.5 is used to compile and upload the program.

ATmega328P on Arduino Uno comes with a pre-programmed bootloader that allows


you to upload a code to it without using an external hardware like programmer kit. In
the IDE, the count (total) is globally initialized to zero.

In the code (bathroom.ino), the ‘void setup’ contains the initialization of digital pins 7 and
8 as input, and digital pin 9 as output. Serial begin in void setup is for serial
communication. Void show ( ) is a function used for serial communication. Void setup is
shown in the Fig. 5.

The main part of the program is void loop, which contains the logic to be executed. First
the ‘in’ sensor is checked for obstruction (person). In case of any obstruction, if
condition is satisfied and while loop is executed. At this stage, the ‘out’ sensor is not yet
subjected to obstruction.
×
When the person obstructs the ‘out’ sensor, the output of the sensor is low, so the
program exits the while loop and count is incremented. The vice versa is framed for
else if part with the count value decremented.

Show ( ) function is used for serial monitor and is unnecessary for practical application.
Void loop is shown in Fig. 5.

Fig. 5: Arduino code void setup ( )

It is assumed that only one person would be using the washroom at a time, so using if
condition, when count (here ‘total’) is checked for the value ‘1’ is shown in Fig. 5.

If total is one, digital pin 9 output will be high only for count one and the relay will be
connected. If not, it will be kept low, that is, the relay will not be energized.

Construction and Testing

A PCB layout for the automated washroom light is shown in Fig. 6 and the layout of its
components in Fig. 7. After assembling the circuit on PCB and uploading the source
code (bathroom.ino) into Arduino Uno, connect a 5V supply across CON1, 230V AC
across CON2, and the light bulb across CON3.

Installation of the sensors near the door is shown in Fig. 8.


×
Fig. 6: PCB layout for the automated washroom light

Fig. 7: Components layout of the PCB

Fig. 8: Sensors’ installation near the door

×
Download PCB and Component layout PDFs: Click Here

Download So urce Co de

Gowtaman G. is an electronics hobbyist. His area of interest includes embedded


programming and automation

You might also like