What Will I Learn?
- You will learn to use HC-SR501 module
- You will learn how to integrate arduino uno and Sensor PIR HC-SR501
- You will learn how to program arduino uno and HC-SR501 to make motion-detecting sensors
Project Introduction
Here is a tutorial arduino uno combined with PIR HC-SR501 sensor. HC-SR501 functions as an infrared transmitter and detects reflections (if there is an objeck nearby). When the prototype on the run, if you put something can move on the sensor or try to move your hand around the sensor and sensor will define the motion object and LED directly "ON" when detecting the motion , if no motion LED will be "OFF".
Requirements
Hardware
- Arduino Uno
- HC-SR501 Module
- Jumper Wires Male To Male
- LED
- Resistor 220 Ohm
- Breadboard
- USB type A to B cable
- Personal Computer (Laptop)
Component Description
Arduino Uno - is a Atmega32-based microcontroller board. Having many digital and analog pins, the arduino can be easily programmed via a computer or laptop with USB and is designed to facilitate electronic users in various fields. As open source he comes with 2 products namely Hardware Arduino Board and Arduino IDE software.
HC-SR501 Module - is a PIR sensor that is often used in microcontroller applications including arduino uno for the detection of an object on the monitor. HC-SR501 has 3 pin, 1 pin GND (-), 1 pin VCC (+) and Pin OUT. The HC-SR501 senses the object with the help of infrared reflection, which is emitted in a radius of angle of (110°) distance of 5-7 meters.
Software
- Arduino IDE
- Fritzing BETA
Difficulty
- Basic
Tutorial Contents
Step 1 : Prepare All Parts
You can buy from online store or directly to the Electronics Shop
Step 2 : Build Circuit Architecture
Using the fritzing software, we will create our Circuit Architecture. Open The Fritzing Beta - choose BreadBoard.
- Prepare Module
Open fritzing and prepare all part you need to make the Circuit Architecture , you can make the circuit with another program , like proteus, Tinkercad etc.
- Choose BreadBoard On the Fritzing (You can see the Image)
- Choose Arduino uno to the project , you can search or click the arduino Label
- Prepare resistor (220 Ohm) and LED
- Choose the LED to BreadBoard , you can search
- Choose the Resistor (220 Ohm) to BreadBoard , you can search in the search box
- Choose the HC-SR501 module , you can search in the search box
After you Prepare all the part now connect the module (LED & HC-SR501) on the breadBoard to the arduino board using the jumper wire. To add the wire just click the port and drag to another port.
- Connect Pin GND (-) Arduino Uno to (-) LED
- Connect Pin Number 13 Arduino Uno to (+) LED
- Connect Pin GND (-) Arduino Uno to GND (-) to HC-SR501.
- Connect Pin VCC (+) Arduino Uno to VCC (+) to HC-SR501.
- Connect the "pin number 2" of the arduino uno board to "OUT" to HC-SR501.
Step 3 : Programing
- Connect Arduino to the computer with USB .
- Open the Arduino IDE > Chose your Board Type
- first,initialize Variable you can use
#int . .
,#float . .
,#double . .
and#char . .
in the case we will use#int . .
int pinLED = 13;
int InPIR = 2;
int stat = 0;
int variable = 0;
The explenation of the coding :
int pinLED = 13;
to initialize pinLED LED
int InPIR = 2;
to initialize Vout PIR
int stat = 0;
to initialize logical status
int variable = 0;
to initialize temporary variable to accommodate the PIR variable
- After Initialize, you Now Set Up the All PinMode
void setup()
void setup() {
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
pinMode(InPIR, INPUT);
}
In this step you will set up all command when the prototype start to begin. In the Project set Serial.begin(9600);
As serial monitor , pin 2 as input and set pin 13 as output.
The explenation of the coding :
Serial.begin(9600);
to set up serial monitor
pinMode(pinLED, OUTPUT);
to set pin 13 as output
pinMode(InPIR, INPUT);
to set pin 2 as input
- Last program is void loop() everything about the system can be run continuously.
void loop(){
variable = digitalRead(InPIR);
if (variable == HIGH) && (stat == LOW))
{
digitalWrite(pinLED, HIGH);
Serial.println("Motion detected!");
stat = HIGH; }
else {
if ((variable == LOW) && (stat == HIGH)){
digitalWrite(pinLED, LOW);
Serial.println("Motion ended!");
stat = LOW;
}
}
The explenation of the coding :
variable = digitalRead(InPIR);
to Read The input from InPIR
if (variable == HIGH) && (stat == LOW))
to check if there is movement or motion
digitalWrite(pinLED, HIGH);
to Turn On LED on The Breadboard
Serial.println("Motion detected!");
to Display "Motion detected!" To laptop
stat = HIGH;
high so as not to detect continuously
digitalWrite(pinLED, LOW);
to Turn Off LED on The Breadboard
Serial.println("Motion ended!");
to Display “Motion ended!” To laptop
Full program will be like this
After write codes, click the "Verify button" to save and compile the sketch. This will also check for any errors in the program.
If no errors is found , now you can click "Upload button" to start installing the program into the arduino uno board.
Curriculum
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it is a duplicate. It is very similar to a contribution that was already accepted here.
You can contact us on Discord.
[utopian-moderator]
I'm so sorry sir , i do not know about it. I will be careful next time