--> Project II - 31. Arduino Interface with Pir Sensor | basic arduino tutorial

Thursday, August 17, 2017

Project II - 31. Arduino Interface with Pir Sensor

| Thursday, August 17, 2017
Arduino Interface with Pir Sensor


PIR sensor is a sensor used to detect an object that emit passive infrared rings, as in human body and other objects. PIR itself is an extension of Passive Infra Red. In this project, Arduino will read the movement using the PIR sensor. Here we make a project how to connect and read motion sensor (sensor PIR) with Arduino. The sensor readings are transmitted via serial communication (Serial Monitor).

Hardware Requirement
  • Arduino Uno Board
  • HC-SR501 PIR Sensor Module
  • Power supply +5 Volt
  • Jumper

HC-SR501 PIR Sensor Module | Source


Block Diagram



Schematic



Arduino - PIR Sensor Module Wiring


Source Code/Sketch


int PIR= 7;
int flag_PIR = LOW;
void setup() {
pinMode(PIR, INPUT);
Serial.begin(9600);
Serial.println("Tes Sensor PIR HC-SR501..");
delay(30000);
}
void loop(){
if((digitalRead(PIR)==HIGH)&&(flag_PIR==LOW)){
Serial.println("Ada gerakan terdeteksi PIR...");
flag_PIR = HIGH;
}
else if ((digitalRead(PIR)==LOW)&&(flag_PIR == HIGH)){
Serial.println("Tidak ada gerakan ...");
flag_PIR = LOW;
}
}

How it Works

1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.

3. Add some library if needed
4. Compile and upload the script program above to your arduino.
5. To test the PIR sensor we use Serial Monitor in Arduino IDE. Setting with baudrate 9600 bps.



6. Try moving your hand in front of the sensor then the sensor will detect it.



Video for Project II - 31. Arduino Interface with Pir Sensor




Required file

Related Posts

No comments:

Post a Comment