Arduino Uno : "Using HC-SR501 to make motion-detecting sensors"

in #utopian-io7 years ago (edited)

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

Arduino.png

  • HC-SR501 Module

HC-SR501.png

  • Jumper Wires Male To Male

jumper wires male to male copi.png

  • LED

LED.png

  • Resistor 220 Ohm

220 ohm.png

  • Breadboard

BreadBoard copy.png

  • USB type A to B cable

USB Printer copy.png

  • Personal Computer (Laptop)

Komputer copy.png

Software
  • Arduino IDE

Arduino_IDE.png

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
bahan.png

Step 2 : Build Circuit Architecture
  • Prepare resistor (220 Ohm) and LED

HC-SR501-1.png

  • Put the LED to BreadBoard
  • Put the Resistor (220 Ohm) to BreadBoard
  • Connect the GND to LED

HC-SR501-2.png

  • Connect Pin GND (-) Arduino Uno to (-) LED
  • Connect Pin Number 13 Arduino Uno to (+) LED

  • Connect the GND to VCC to HC-SR501

HC-SR501-3.png

  • Connect Pin GND (-) Arduino Uno to GND (-) to HC-SR501.
  • Connect Pin VCC (+) Arduino Uno to VCC (+) to HC-SR501.

  • Out Connect

HC-SR501-4.png

  • 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
    IDE.png

  • first,initialize Variable you can use #int . . , #float . . , #double . . and char . . 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

Full_Program.png

After write codes, click the "Verify button" to save and compile the sketch. This will also check for any errors in the program.

IDE_1.png

If no errors is found , now you can click "Upload button" to start installing the program into the arduino uno board.

IDE_2.png

Curriculum


Arduino : "Using TCS230 to make Color sensing"

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Violated Rule:

  • Design or video editing related tutorials, gameplay, simple on-screen instructions, ubiquitous functions (Save, Open, Print, etc.) or basic programming concepts (variables, operators, loops, etc.) will not be accepted.

My Opinion:

  • A tutorial must be informative and explanatory, but also "tutor". This tutorial lacks "tutor"ing, and it is nothing more than an explanation of a documentation.

You can contact us on Discord.

[utopian-moderator]