Arduino motion detection

The example shows how we can detect movement using PIR sensor in combination with Arduino microcontroller.

The example uses the following elements:

Connecting the sensor from Arduino:

The module communicates via a popular bus with one signal output. The connection to Arduino is made as follows:

PIR module Pin Arduino
VCC 5 V
GND GND
OUT 8

Wiring diagram of the sensor from Arduino Uno.

Program for Arduino

The following code was used in the example:

  1. int sensor = 8; //pin 8 connected to a sensor signal
  2.  
  3. void setup(){
  4. Serial.begin(9600); //initialisation of a serial monitor
  5. pinMode(sensor, INPUT); // setting the Arduino pin as input
  6. Serial.println("---- TEST SENSOR MOVEMENT TEST ----");
  7. }
  8.  
  9. void loop(){
  10. int motion = digitalRead (sensor); //reading the value from the sensor
  11. if(movement === HIGH) // displaying information on a serial monitor
  12. { // high state means motion detection, low state means no motion
  13. Serial.println("MOVE CHARACTERS!");
  14. }
  15. else {Serial.println("no traffic");}
  16. delay(200); // delay between readings
  17. }

The effects of the programme can be seen below:

Serial screenshot of the monitor.

Botland.store - shop for makers!