Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

ELECTRONICS HUB

PROJECTS | TUTORIALS | COURSES | KITS

 HOME
 PROJECTS
o MINI PROJECTS
 TOP ELECTRONICS
 MICROCONTROLLER
o ELECTRICAL
 TOP ELECTRICAL
o ELECTRONICS
 TOP
 LATEST
 LED
 VLSI
 MATLAB
 SENSOR
o ARDUINO
o HOME AUTOMATION
o RASPBERRY PI
o IOT
o EMBEDDED
 8051
 AVR
 PIC
o COMMUNICATION
 DTMF
 GSM
 RFID
 WIRELESS
o POWER ELECTRONICS
o ARM PROJECTS
o ROBOTICS
o SOLAR
 MINI PROJECTS
 FREE CIRCUITS
o MINI PROJECTS
o ELECTRONICS
 555 TIMER
o EMBEDDED
 8051
 AVR
o COMMUNICATION
o ELECTRICAL
o ROBOTICS
o SOLOR
o SENSOR
 TUTORIALS
o CAPACITORS
o RESISTORS
o FILTERS
o OPERATIONAL AMPLIFIERS
o DIODES
o TRANSISTORS
o NUMBER SYSTEMS
o IO DEVICES
o MISCELLANEOUS
o DC CIRCUIT THEORY
o THYRISTORS
o SEQUENTIAL LOGIC CIRCUITS
 SYMBOLS
 DIY
 PROJECT KITS
 COURSES
 CONTACT US
o FOLLOW US
 FACEBOOK
 YOUTUBE
 INSTAGRAM
 GOOGLE PLUS
 TWITTER

YOU ARE HERE: HOME / ARDUINO / AUTOMATIC ROOM LIGHTS USING ARDUINO AND PIR SENSOR

Automatic Room Lights using


Arduino and PIR Sensor
JANUARY 25, 2018 BY RAVI 26 COMMENTS

In this project, we will see the Automatic Room Lights using Arduino and PIR
Sensor, where the lights in the room will automatically turn ON and OFF by detecting
the presence of a human.

Such Automatic Room Lights can be implemented in your garages, staircases,


bathrooms, etc. where we do not need continuous light but only when we are
present.

Also, with the help of an automatic room light control system, you need not worry
about electricity as the lights get automatically off when there is no person.

So, in this DIY project, we have implemented Automatic Room Lights using Arduino
and PIR Sensor. 

Table of Contents
 Overview
  Circuit Diagram of Automatic Room Lights using Arduino
 Components Required for Automatic Room Lights using Arduino
 Component Description
o PIR Sensor
o Relay Module
 Circuit Design
 Code
 Working of the Project
 Applications

Overview
Automatic Room Lights System using Arduino is a very useful project as you need
not worry about turning on and off the switches every time you want to turn on the
lights. The main components of the Automatic Room Lights project are Arduino, PIR
Sensor and the Relay Module.

Out of the three components, the PIR Sensor is the one in focus as it is the main
device that helps in detecting humans and human motion.

In fact, the Automatic Room Lights project can be considered as one major
application of the PIR Sensor. A similar concept is being already implemented in
automatic toilet flush valves, hand dryers, etc.

Also Read: ARDUINO PIR SENSOR TUTORIAL

 Circuit Diagram of Automatic Room Lights using


Arduino
The following image shows the circuit diagram of the project implemented using
Arduino UNO, PIR Sensor and a Relay Module.
If you do not have a relay module, you can make one yourself using very simple
hardware. The following circuit diagram shows the project being implemented with
the help of discrete components for the Relay Module.
CAUTION: The project involves connection with 230V AC Mains (or 110V,
depending on where you live!!!). Be extremely careful when connecting the bulb and
Relay to mains supply. If you are unfamiliar with the connections, I strongly
recommend having an adult supervision (or an expert supervision).    

Components Required for Automatic Room Lights


using Arduino
 Arduino UNO
 PIR Sensor
 5V Relay Module (Relay Board)
 LED
 100Ω Resistor (1/4 Watt)
 Connecting Wires
 Breadboard
 Power Supply

If you do not have a Relay Module, use the following components:


 5V Relay
 2N2222 (or BC547) NPN Transistor
 1N4007 PN Junction Diode
 1KΩ Resistor (1/4 Watt)

Component Description
PIR Sensor
We have already seen about PIR Sensor in the PIR Motion Sensor Tutorial and also
implemented in a variety of projects like Home Security System and Automatic Door
Opener.

Relay Module
A Relay Module is a very useful component as it allows Arduino, Raspberry Pi or
other Microcontrollers to control big electrical loads. We have used a 2-channel
Relay Module in this project but used only one relay in it. The relay module used in
this project is shown below.

In order to control a single relay on the board, we need to use three pins of the relay
module: VCC, GND and IN1. 

Before continuing, read How to use 5V Relay on Arduino

NOTE: The relay module used in this project is as active LOW one i.e. when the IN1
pin is HIGH, the relay is OFF and when it is LOW, the relay is activated. This point is
important while programming the Arduino UNO. 

Circuit Design
PIR Sensor’s Data OUT Pin is connected to Arduino’s Digital I/O Pin 8. An LED is
connected to pin 13 of Arduino to indicate whether the light is turned ON or OFF.
The IN1 pin of the Relay Module is connected to Pin 9 of Arduino. A bulb is
connected to mains supply through relay. One terminal of the bulb is connected to
one wire of the mains supply. The other terminal of the bulb is connected to the NO
(Normally Open) contact of the Relay Module.

COM (Common) contact of the Relay is connected to the other wire of the mains
supply. Be careful when connecting this part of the project.   

Code
The code for the Automatic Room Lights using Arduino and PIR Sensor is given
below.

int in1 = 9;
int sensor = 8;
int led = 13;
unsigned long t=0;

void setup()
{
Serial.begin(9600);
pinMode(in1, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);

digitalWrite(in1,HIGH);
digitalWrite(led,LOW);

while(millis()<13000)
{
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
}
digitalWrite(led,LOW);

}
void loop()
{
digitalWrite(in1,HIGH);
digitalWrite(led,LOW);
if(digitalRead(sensor)==HIGH)
{
t=millis();
while(millis()<(t+5000))
{
digitalWrite(in1,LOW);
digitalWrite(led,HIGH);
if((millis()>(t+2300))&&(digitalRead(sensor)==HIGH))
{
t=millis();
}
}
}
}

view rawAutomatic_Room_Lights_Arduino.ino  hosted with   by GitHub

Working of the Project


The Automatic Room Lights using Arduino and PIR Sensor is a simple project,
where the lights in the room will automatically turn on upon detecting a human
motion and stay turned on until the person has left or there is no motion.

Working of this project is very simple and is explained here.

Initially, when there is no human movement, the PIR Sensor doesn’t detect any
person and its OUT pin stays LOW. As the person enters the room, the change in
infrared radiation in the room is detected by the PIR Sensor.

As a result, the output of the PIR Sensor becomes HIGH. Since the Data OUT of the
PIR Sensor is connected to Digital Pin 8 of Arduino, whenever it becomes HIGH,
Arduino will activate the relay by making the relay pin LOW (as the relay module is
an active LOW module).

This will turn the Light ON. The light stays turned ON as long as there is movement
in front of the sensor.

If the person takes a nap or leaves the room, the IR Radiation will become stable
(there will be no change) and hence, the Data OUT of the PIR Sensor will become
LOW. This in turn will make the Arduino to turn OFF the relay (make the relay pin
HIGH) and the room light will be turned OFF.
Applications
I’ve already mentioned a few applications of the Automatic Room Lights concept.
Some of them are:  

 Garage Lights
 Bathroom Lights
 Hand Dryers
 Toilet Flushers
 Security Lights

FILED UNDER: ARDUINO, DIY PROJECTS

Comments

1. Amit says

JANUARY 31, 2018 AT 1:34 AM

I like your project.

Reply

2. sdf says

FEBRUARY 2, 2018 AT 9:54 PM

me too

Reply
3. Gottimukkala Tarun gopal says

FEBRUARY 3, 2018 AT 3:07 AM

Can u please tell how to program arduino uno .please send the respective
instructions or related vedio to program an arduino uno.

Reply

4. guru says

FEBRUARY 5, 2018 AT 1:38 AM

nice project very useful as

Reply

5. muhd says

MARCH 16, 2018 AT 7:31 PM

excellent project

Reply
6. ansh says

MARCH 20, 2018 AT 5:04 AM

showing an error that ‘lWrite’ was not declared in this scope

Reply

o Ravi says

APRIL 9, 2018 AT 2:20 AM

Sorry. It was a typing mistake. It should be digitalWrite. I’ve made the changes. Thanks
for sharing.

Reply

7. Jo Quaedvlieg says

APRIL 2, 2018 AT 6:32 AM

Nice project, however would it not be useful to connect an light resistor, so that the
light only turn on when it’s dark?

Reply
8. Akhilesh says

APRIL 17, 2018 AT 5:33 AM

Can we use more than one light using this curcuit or we can use only one light

Reply

o Ravi says

APRIL 17, 2018 AT 6:47 AM

Hi,
You can use more number of lights. Just connect a higher channel Relay (like an 8-
channel for 8 lights) and modify the code accordingly.

Reply

 MUHAMMAD ARSALAN WAHID says

APRIL 19, 2018 AT 12:22 PM

Dear sir
Can u write code for 4 lights ?? I want 4 lights to control
And a ckt diagram please help me with this
Reply

9. shambhavi says

APRIL 26, 2018 AT 1:34 AM

Is the code complete? Cause I have tried running this project on proteus and it’s not
working.

Reply

o Ravi says

APRIL 26, 2018 AT 1:43 AM

Yes. The code is complete and tested.

Reply

10. ayap says

MAY 3, 2018 AT 1:39 AM


1. if we replaced the light with small portable fan, does it work out?

2.can we use the same code for 1 chanel only for the relay module?

Reply

o Ravi says

MAY 4, 2018 AT 2:00 AM

Yes and Yes.

Reply

11. Leslie Valmadre says

MAY 7, 2018 AT 4:34 AM

Great project Ravi, thanks.


I am however struggling to understand your use of millis() as I dont see why you
have tied the on/off to the length of time the Arduino board has been running the
current program or am I just being dumb?

Also have you any suggestions on how to change the program to delay the off signal
for say 10 (or perhaps 30) seconds after the PIR detects no motion. That way the
cupborad light where I will be using the sketch will stay on until the door is closed
then turn off the light.
Hope it is OK to ask this of you.
Les
Reply

12. Ronak says

MAY 7, 2018 AT 5:55 AM

can i use 12v relay for this project

Reply

o Ravi says

MAY 7, 2018 AT 5:57 AM

Only 5V relay.

Reply

13. Fakrul Hidayat says

MAY 12, 2018 AT 3:35 AM


Actually , I tested on proteus but cannot working. But I have made connection
between Input of Relay and Output of PIR and it working. And I changes the coding
from Sensor = 8, to sensor = 9 and changes the circuit wire ofoutput sensor connect
to input of relay and connect to arduino at 8. It working. So , maybe it does not
working bexause no connection between PIR and relay . so nothing happen. Thank
You

Reply

14. Venakta says

MAY 16, 2018 AT 10:44 AM

What is the concept of this project?

Reply

15. Drex says

MAY 27, 2018 AT 12:05 PM

Another way to do this is to use an active high relay module and forget about the
arduino. Just take the output of the PIR and tie it to the 1k resistor before the
2N2222.

Reply
o Ravi says

MAY 28, 2018 AT 12:00 AM

That the simplest way to implement this idea. But with Arduino (or any other controller)
you can really control the IO.

Reply

16. TKabz says

JUNE 1, 2018 AT 11:51 AM

nice project,i ran it and added to the application 2 more lights lighting in
sequence..application for a one way corridor..thank you..now trying to figure out how
to change or alter the sensitivity of the sensor.

Reply

17. Hery says

JUNE 23, 2018 AT 6:20 AM

thanks for knowledge…


Reply

18. Piyush says

JULY 21, 2018 AT 8:24 AM

Where is the code ?

Reply

o Ravi says

JULY 30, 2018 AT 2:19 AM

Hi,
Code is uploaded. Check at the bottom of the post.

Reply

Leave a Reply
Your email address will not be published. Required fields are marked *
Comment

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Post Comment

Search

PROJECTS BY CATEGORY

Arduino Projects (200+) 
Electronics Projects (250+) 
Mini Project Circuits (160+) 
Mini Project Ideas (150+) 
ECE Projects (150+) 
EEE Projects (150+) 
8051 Projects (110+) 
Raspberry Pi Projects (101+) 
Electrical Project Ideas (100+) 
Embedded Projects (100+) 
Latest Electronics Ideas (100+) 
Microcontroller Mini Projects (100+) 
Robotics Projects (100+) 
VLSI Projects (100+) 
Solar Projects (100+) 
IOT Projects (100+) 

Communication Projects (70+) 
LED Projects (70+) 
Power Electronics Projects (60+) 
RFID Projects (60+) 
Home Automation Projects (50+) 
Matlab Projects (50+) 
EIE Projects (50+) 
Wireless Projects (50+)
LabView Projects (45+) 
Zigbee Projects (45+)
GSM Projects (40+) 
555 Timer Circuits (40+) 
Sensor Projects (40+) 
ARM Projects (60+) 
DTMF Projects (30+) 
PIC Projects (30+) 
Electrical Mini Projects (25) 
ESP8266 Projects (15) 

KITS

Best Drone Kits [12]


3D Printer Kits [12]
Best Robot Vacuum Clears [14]
Best Waveform Generators [12]

GENERAL

 Tutorials
 Symbols
 Courses
 Calculator
 Contact
PROJECTS

 Electrical
 Electronics
 Embedded
 Power
 Robotics
 ARM
 IOT
PROJECTS

 Mini projects
 Microcontroller
 Arduino
 Solar
 Free circuits
 Home Automation
 Seminar Topics
 Electronics Questions
TUTORIALS

 Capacitors
 Resistors
 Filters
 Diodes
 Transistors
TUTORIALS

 Amplifiers
 IO Devices
 Thyristors
 DC Circuits
 Number System
FOLLOW US

 Instagram
 Youtube
 Facebook
 Google Plus
 Twitter
Copyright © 2018 Electronicshub.org
m

You might also like