You are here
Home > IoT Experiments >

Experiment-10:  Automatic Room Lights using Arduino and PIR Sensor

AIM:  Automatic Room Lights using Arduino and PIR Sensor.

Objective:  

We will be able to:

  1. Understand the working of PIR Sensor
  2. Understand the interfacing of PIR with arduino and Relay
  • Develop real time program to Automatically control Room Lights

Requirement :

PC with internet, Arduino board, breadboard, PIR Sensor, Relay, LED, Jumper Wires

 Theory:

PIR Sensor:

A PIR sensor is an electronic sensor used in motion detectors such as automatically triggered lighting devices and protection systems that measure devices emitting infrared light in their field of view.

Each body with a temperature above zero releases heat energy, which is in the form of radiation. PIR sensors detect infrared radiation that is reflected or released from the target instead of measuring or sensing heat.

If the sensor detects an animal, insect, or a person, the temperature at that point in the sensor’s field of view increases to the body temperature of the intruder from the ambient temperature and then back accordingly. The resulting change in the received infrared radiation is translated by the sensor into a change in the output voltage, which activates detection. Usually, the PIR sensors detect general movement. They do not offer specifics and information about what or who moved.

Relay Module:

Relay is an electromechanical device that uses an electric current to open or close the contacts of a switch. The single-channel relay module is much more than just a plain relay, it comprises of components that make switching and connection easier and act as indicators to show if the module is powered and if the relay is active or not.

Interfacing Relay, PIR with Arduino:

Working of the Project

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

Sketch:

int input1 = 9;

int sensor1 = 8;

int led = 7;

unsigned long t=0;

unsigned long use_count=0;

void setup()

{

  //Serial.begin(9600);

  pinMode(input1, OUTPUT);

  pinMode(sensor1, INPUT);

  pinMode(led, OUTPUT);

    digitalWrite(input1,HIGH);

  digitalWrite(led,LOW);

  while(millis()<10000)

  {

    digitalWrite(led,HIGH);

    delay(50);

    digitalWrite(led,LOW);

    delay(50);

  }

  digitalWrite(led,LOW);

  }

void loop()

{

  digitalWrite(input1,HIGH);

  digitalWrite(led,LOW);

  if(digitalRead(sensor1)==HIGH)

  {

   t=millis();

   while(millis()<(t+5000))

   {

   digitalWrite(input1,LOW);

   digitalWrite(led,HIGH);

   flag=1;

       if((millis()>(t+2300))&&(digitalRead(sensor)==HIGH))

      {

       t=millis();

      }

   }

  }

}

 

Summary:

In this project we learnt about the PIR and Relay module and its interfacing with Arduino. We also learnt about programming to switch ON OFF the light which work on higher potential.

Viva Questions

  1. Write the purpose of the PIR sensor, name its pins.
  2. How does the relay module works.
  3. Write the function of the following statements

a. millis()

b. if((millis()>(t+2300))&&(digitalRead(sensor)==HIGH))

c. while(millis()<10000)

Leave a Reply

Top
error: Content is protected !!