Tuesday, 22 October 2024

Capture interruptions with Motion Sensor and Arduino

In this project, we have integrated the motion sensor (HC-SR 501 PIR sensor) with Arduino. The motion sensor detects any interruption caused within its scope (3m to 7m). Whenever an interruption is detected, it is counted with the help of CPP program written with Arduino IDE. This count of interruptions is displayed on the LCD. Also, when an interruption is caused the buzzer rings and the LED glows. As per the instruction manual of Motion Sensor, it takes almost 1 minute to initialize the sensor and to provide correct readings. Hence the silence in the beginning of the video. Let's take a look at the demo of the program below.



Now let's take a look at the components used in the demo and the software used to drive those components. 

Arduino Uno: The microcontroller used to drive the other electronics, which is the LCD, motion sensor, buzzer, LED. The interfacing of these other electronics components is shown in the circuit diagram below. 


Passive Buzzer: This buzzer has two pins "+" and "-", which are connected to Pin 5 and GND of Arduino respectively. The tone required for passive buzzer to produce the sound, is outputted onto pin 5 programmatically. (I will explain the CPP program later in this article). The passive buzzer image is shown below along with its pin identification for reference.




 LCD Display: The LCD display has following connections.
  • Arduino Digital Pin 7 - Connected to pin DB7 of LCD Display
  • Arduino Digital Pin 8 - Connected to pin DB6 of LCD Display
  • Arduino Digital Pin 9 - Connected to pin DB5 of LCD Display
  • Arduino Digital Pin 10 - Connected to pin DB4 of LCD Display
  • Arduino Digital Pin 11 - Connected to pin of LCD Display
  • Arduino Digital Pin 12 - Connected to pin RS of LCD Display
  • Potentiometer '+' pin - Connected to Vcc
  • Potentiometer '-' pin - Connected to GND
  • Potentiometer 'Data' pin - Connected to pin V0 of LCD Display
  • Vcc 5V - Connected to pin LED+ of LCD display (through 220 ohms resistor)
  • GND - Connected to pin LED- of LCD display     
  • Vcc 5V - Connected to pin VDD of LCD display 
  • GND - Connected to pin Vss of LCD Display
  • GND - Connected to pin R/W of LCD Display
An image of the LCD Display compatible with Arduino UNO is as shown below.


NOTE: Please refer to the references section for more information about LCD connections. Although we are giving one useful tip here. LCD's onboard potentiometer is used to control the light intensity of the display, which will make the characters getting displayed more clearly.


LED: As shown in the circuit diagram, the anode (the large leg) of the LED is connected to pin 6 of Arduino. Whereas the cathode (the short leg) of LED is connected to ground of Arduino. 

HC-SR 501 PIR sensor: This sensor can be mounted on the car to detect if another vehicle is present in the detectable range (3 meters to 7 meters) in front of the vehicle. This range is adjustable, based on tuning of a potentiometer present on the board. We have kept the default setting of potentiometer. Please refer to the links in the References section below to get details of this sensor. However the input/output pins are shown in the below picture for reference. The extreme left pin is the Ground pin. The middle pin is Data pin and the extreme right pin is Vcc pin. We have kept the jumper ON. This keeps the sensor in Repeatable Mode. In this mode, The data pin remains HIGH for a specific time interval after the presence of vehicle is sensed in the range. (In the Non-Repeatable Mode, the data pin remains HIGH as long as the presence of vehicle is sensed in the range.) We have not explained the use of potentiometer on the board. However we can understand the use of them with the sites given in the references.





Power Supply: We connect Arduino to laptop which acts as a +5V power source.

Given this hardware background, let us focus on the software to drive the components. The software is CPP program written with Arduino IDE. As with any Arduino program, our program too works with two different functions "setup" and "loop". The setup gets executed only once during the lifecycle of the program and loop gets executed multiple times, as long as it is not terminated by a condition. Please find our code for this program below.

The setup part of the program defines the ledPin as OUTPUT and sets it to be LOW. This makes the LED not glow until a motion is sensed. The data pin of motion sensor which is the pirPin is set to be the INPUT. So we will receive the data for presence of motion over this pin. The LCD can print 16 x 2 characters. Where 16 is the number of columns and 2 is the number of rows. We display the default statement "The interruptions are:" on this LCD display in the setup. 

The loop part of the program keeps reading for the pirValue, which is the data received from the PIR sensor. This pirValue is either 0 or 1 (it is binary). If motion is detected, we receive a 1 and if motion is not detected we receive a 0. So, if motion is detected, the buzzer plays the melody. We increment the number of interruptions. We output this number to LCD. Then we give a delay of 6 seconds and perform the above procedure of reading the pirValue again. This whole process gives us the total number of interruptions on the LCD. 


References: 

No comments:

Post a Comment