Arduino Uno : "Using HC-SR501 to make motion-detecting sensors"
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
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)
Software
- Arduino IDE
Knowledge
- Electronics and Robotics Basic
Difficulty
- Basic
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".
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.
Tutorial Contents
Step 1 : Prepare All Parts
You can buy from online store or directly to the Electronics Shop
Step 2 : Build Circuit Architecture
- Prepare resistor (220 Ohm) and LED
- Put the LED to BreadBoard
- Put the Resistor (220 Ohm) to BreadBoard
- Connect the GND to LED
- Connect Pin GND (-) Arduino Uno to (-) LED
- Connect Pin Number 13 Arduino Uno to (+) LED
- Connect the GND to VCC to HC-SR501
- Connect Pin GND (-) Arduino Uno to GND (-) to HC-SR501.
- Connect Pin VCC (+) Arduino Uno to VCC (+) to HC-SR501.
- Out Connect
- 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 . .
andchar . .
in the case we will use#int . .
int pinLED = 13; // initialize pinLED LED
int InPIR = 2; // Vout PIR
int stat = 0; // logical status
int variable = 0; // temporary variable to accommodate the PIR variable
- After Initialize, you Now Set Up the All PinMode
void setup()
void setup() {
Serial.begin(9600); //serial monitor
pinMode(pinLED, OUTPUT); //set pin 13 as output
pinMode(InPIR, INPUT); // set pin 2 as 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.
- Last program is
void loop()
everything about the system can be run continuously.
void loop(){
- Read The input from InPIR
variable = digitalRead(InPIR);
- check if there is movement or motion
if (variable == HIGH) && (stat == LOW))
Turn On LED on The Breadboard
{ digitalWrite(pinLED, HIGH);
Serial.println("Motion detected!"); // Display "Motion detected!" To laptop
stat = HIGH; // high so as not to detect continuously
}
Turn Off LED on The Breadboard
else {
if ((variable == LOW) && (stat == HIGH)){
digitalWrite(pinLED, LOW);
Serial.println("Motion ended!"); // Display “Motion ended!” To laptop
stat = LOW;
}
}
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.
Your contribution cannot be approved because it does not follow the Utopian Rules.
Violated Rule:
My Opinion:
You can contact us on Discord.
[utopian-moderator]