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:
int sensor = 8; //pin 8 connected to a sensor signal
void setup(){
Serial.begin(9600); //initialisation of a serial monitor
pinMode(sensor, INPUT); // setting the Arduino pin as input
Serial.println("---- TEST SENSOR MOVEMENT TEST ----");
}
void loop(){
int motion = digitalRead (sensor); //reading the value from the sensor
if(movement === HIGH) // displaying information on a serial monitor
{ // high state means motion detection, low state means no motion
Serial.println("MOVE CHARACTERS!");
}
else {Serial.println("no traffic");}
delay(200); // delay between readings
}
The effects of the programme can be seen below:
Serial screenshot of the monitor.
