Sunteți pe pagina 1din 25

9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

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

HOME PROJECTS MINI PROJECTS ARDUINO FREE CIRCUITS TUTORIALS SYMBOLS

DIY COURSES CONTACT US

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 — 45 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.

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

7. Working of the Project


8. Applications

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.

“ 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

https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 3/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

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 [Buy Here]
PIR Sensor [Buy Here]
5V Relay Module (Relay Board) [Buy Here]
LED [Buy Here]
100Ω Resistor (1/4 Watt)  [Buy Here]
Connecting Wires [Buy Here]
Breadboard [Buy Here]
Power Supply [Buy Here]

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

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. 

“ 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.

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;

3 int led = 13;

4 unsigned long t=0;

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 }

Automatic_Room_Lights_Arduino.ino hosted with by GitHub view raw

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

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

FILED UNDER: ARDUINO, DIY PROJECTS

Comments

Amit says
January 31, 2018 at 1:34 am

I like your project.

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

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

guru says
February 5, 2018 at 1:38 am

nice project very useful as

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

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

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

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

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

Yes. The code is complete and tested.

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

Yes and Yes.

Reply

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/o 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 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

can i use 12v relay for this project

Reply

Ravi says
May 7, 2018 at 5:57 am

Only 5V relay.

Reply

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

Venakta says
May 16, 2018 at 10:44 am

What is the concept of this project?

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

Chibuzor Henry says


April 27, 2019 at 5:12 pm

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

thanks for knowledge…

Reply

Piyush says
July 21, 2018 at 8:24 am

Where is the code ?

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

how much this cost?

Reply

Rehan shah says


https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 15/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

August 13, 2018 at 6:09 pm

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

Rick Hodgson says


August 15, 2018 at 2:48 pm

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

Elorm Rescue says


September 6, 2018 at 4:00 am

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

How much it will cost?

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

Tahmid Daiyan says


October 5, 2018 at 11:15 am

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

Jover Magto says


October 13, 2018 at 9:47 am

What if I use PIR Motion Sensor Grove? What changes should i do?

Reply

Bob-Weke says
November 15, 2018 at 6:25 pm

Thanks for this project. I will try it

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

Oyinlolu Odetoye says


November 21, 2018 at 8:08 am

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

M. Sami Islam says


December 30, 2018 at 8:23 am

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

why can’t we use a 12V relay module

Reply

Chibuzor Henry says


April 28, 2019 at 3:01 pm

https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 19/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

I like this project please how can I get the materials

Reply

arun says
May 23, 2019 at 3:31 am

hw much time it will tke to turn on or o ?

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

Search this website

PCB Assembly Services

Play PUBG Mobile on PC


Flexible control with mouse &
keyboard. Easy way to win the
game

SPONSORED SEARCHES

electronic circuit

led night light

4 relay module

automatic room light using pir sensor

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

Play PUBG Mobile on PC


Flexible control with mouse &
keyboard. Easy way to win the
game

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+)

https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 22/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

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]
RGB LED Strip Light Kits [20]
Best LED Christmas Light Kits [13]

https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 23/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

Hi there! I’m the Haven Beauty


bot. I can help you find the best
beauty product for your skin.

Let's do it! 👍

Type a message

SUBSCRIBE FOR UPDATES

Enter your email address:

SUBSCRIBE

GENERAL PROJECTS PROJECTS

Tutorials Electrical Mini projects

https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 24/25
9/29/2019 Automatic Room Lights using Arduino and PIR Sensor

Symbols Electronics Microcontroller


Courses Embedded Arduino

Calculator Power Solar


Contact Robotics Free circuits
HomeZene ARM Home Automation

IOT Seminar Topics


Electronics Questions

TUTORIALS TUTORIALS FOLLOW US

Capacitors Ampli ers Instagram


Resistors IO Devices Youtube

Filters Thyristors Facebook


Diodes DC Circuits Google Plus
Transistors Number System Twitter

TS EAMCET 2019

Copyright © 2019 Electronicshub.org

https://www.electronicshub.org/automatic-room-lights-using-arduino-pir-sensor/ 25/25

S-ar putea să vă placă și