Documente Academic
Documente Profesional
Documente Cultură
ELECTRONICS HUB
P R OJ E C T S | T U TO R I A L S | C O U R S E S | K I T S
YOU ARE HERE: HOME / ARDUINO / AUTOMATIC ROOM LIGHTS USING ARDUINO AND PIR SENSOR
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.
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 1/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
___
Also, with the help of an automatic room light control system, you need not worry about
electricity as the lights get automatically o when there is no person.
So, in this DIY project, we have implemented Automatic Room Lights using Arduino and PIR
Sensor.
Table of Contents
1. Overview
2. Circuit Diagram of Automatic Room Lights using Arduino
3. Components Required for Automatic Room Lights using Arduino
4. Component Description
4.1. PIR Sensor
4.2. Relay Module
5. Circuit Design
6. Code
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 2/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Overview
Automatic Room Lights System using Arduino is a very useful project as you need not worry
about turning on and o 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 ush valves,
hand dryers, etc.
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
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 3/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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).
5V Relay
2N2222 (or BC547) NPN Transistor [Buy Here]
1N4007 PN Junction Diode [Buy Here]
1KΩ Resistor (1/4 Watt) [Buy Here]
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 4/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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.
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.
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 5/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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.
1 int in1 = 9;
2 int sensor = 8;
5
6 void setup()
7 {
8 Serial.begin(9600);
9 pinMode(in1, OUTPUT);
10 pinMode(sensor, INPUT);
11 pinMode(led, OUTPUT);
12
13 digitalWrite(in1,HIGH);
14 digitalWrite(led,LOW);
15
16 while(millis()<13000)
17 {
18 digitalWrite(led,HIGH);
19 delay(50);
20 digitalWrite(led,LOW);
21 delay(50);
22 }
23 digitalWrite(led,LOW);
24
25 }
26
27
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 6/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
28 void loop()
29 {
30 digitalWrite(in1,HIGH);
31 digitalWrite(led,LOW);
32 if(digitalRead(sensor)==HIGH)
33 {
34 t=millis();
35 while(millis()<(t+5000))
36 {
37 digitalWrite(in1,LOW);
38 digitalWrite(led,HIGH);
39 if((millis()>(t+2300))&&(digitalRead(sensor)==HIGH))
40 {
41 t=millis();
42 }
43 }
44 }
45 }
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
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 7/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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
Comments
Amit says
January 31, 2018 at 1:34 am
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 8/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
sdf says
February 2, 2018 at 9:54 pm
me too
Reply
Can u please tell how to program arduino uno .please send the respective instructions or
related vedio to program an arduino uno.
Reply
guru says
February 5, 2018 at 1:38 am
Reply
muhd says
March 16, 2018 at 7:31 pm
excellent project
Reply
ansh says
March 20, 2018 at 5:04 am
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 9/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Reply
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
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
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
Ravi says
April 17, 2018 at 6:47 am
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 10/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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
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
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
Ravi says
April 26, 2018 at 1:43 am
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 11/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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
Ravi says
May 4, 2018 at 2:00 am
Reply
Also have you any suggestions on how to change the program to delay the o 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 o the
light.
Hope it is OK to ask this of you.
Les
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 12/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Ronak says
May 7, 2018 at 5:55 am
Reply
Ravi says
May 7, 2018 at 5:57 am
Only 5V relay.
Reply
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
Venakta says
May 16, 2018 at 10:44 am
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 13/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
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
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
Please I need to study the operation of the project, How will I get the full materials
how will I get it.
Reply
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 gure out how to
change or alter the sensitivity of the sensor.
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 14/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Hery says
June 23, 2018 at 6:20 am
Reply
Piyush says
July 21, 2018 at 8:24 am
Reply
Ravi says
July 30, 2018 at 2:19 am
Hi,
Code is uploaded. Check at the bottom of the post.
Reply
ankush says
October 22, 2018 at 1:46 am
Reply
HI.
i make this project, but my PIR sensor is not working. please solve my proplem.
Thanks
Reply
Abarna says
August 15, 2018 at 11:17 am
Sir ,
How to replace a lamp with led panels (in intension on saving power) ,,with this ac supply
Reply
Great project. My wife no longer complains that I leave the lights in my shop ON.
I used a At-tiny instead of the Adruino. Minor changes to the code to accommodate the
tiny.
Reply
CJ says
September 3, 2018 at 8:14 pm
How much did you invest for the project . And for what price would you sell it out in public .
Let me know . Thanks .
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 16/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
I need an improvised version, Is it possible to make it such that you load times for it to turn
o and on the lights? I want to use it for a poultry farm where I cannot be there all night to
turn on and o the lights according to a schedule. I will really appreciate your input.
Reply
Somay says
September 7, 2018 at 11:10 am
Hello sir
I m interested in this project plz suggest me how I make this and what about it’s cost and
construction plz sir
Reply
Silpa s says
September 16, 2018 at 12:06 am
Reply
Shravan M J says
September 26, 2018 at 9:38 am
I liked the project. Thank you very much for the knowledge.
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 17/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Reply
the project is very nice and useful. can u plzz mention some logical usefulness of this
project plzz??
Reply
sushama says
October 11, 2018 at 6:09 am
I made connecion as per your suggestion but o/p was no come correct
i am running same code but problem for output pls help what exact problem
Reply
What if I use PIR Motion Sensor Grove? What changes should i do?
Reply
Bob-Weke says
November 15, 2018 at 6:25 pm
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 18/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Please, what modi cations would be necessary to implement this for a row of lights which
aren’t simply connected together…. say a system in which each light in a row turns on when
you come under it and turns o 5 seconds after you’re away from it and each of the lights
behaves that way independently of the rest? How many microcontroller or relay modules
will I need? One for each bulb(which would be too expensive)? Please I’m new to
microcontrollers so I don’t know the possibilities and limitations of the devices is why I’m
asking such a funny question. Please, I need it for a school project.
Reply
I like your project very much, This project help us to made automatic light controller with
pir sensor
Reply
Gopinath says
February 21, 2019 at 6:51 am
Reply
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 19/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Reply
arun says
May 23, 2019 at 3:31 am
Reply
Leave a Reply
Your email address will not be published. Required elds are marked *
Comment
Name *
Email *
Website
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 20/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
POST COMMENT
SPONSORED SEARCHES
electronic circuit
4 relay module
electrical relay
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 21/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
PROJECTS BY CATEGORY
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 22/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
KITS
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 23/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
Let's do it! 👍
Type a message
SUBSCRIBE
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 24/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor
TS EAMCET 2019
https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 25/25