PIR stands for Passive Infrared
This sensor detects motion by measuring changes of heat in its surroundings. It is easy to connect if you follow carefully this few steps. For this Tutorial you will need:
- 1 Arduino Board
- 1 PIR Sensor
- 1 10kΩ Resistor
- Cables
This is what the sensor looks like.
When hooking up the sensor, note that the red wire is Voltage, the brown wire is Ground and the black wire is Signal. Here a close-up of the sensor:
Start by hooking up 5V to the red wire, GND to the brown wire, and Pin 2 to the black wire with a 10kΩ resistor going back to 5V. If everything is set up correctly it should look like in this sketch:
Code
The code is pretty simple. The signal is either HIGH or LOW, and is easily triggered. You will have to stand VERY still in order to not be detected!
int pirPin = 2; //digital 2 void setup(){ Serial.begin(9600); pinMode(pirPin, INPUT); } void loop(){ int pirVal = digitalRead(pirPin); if(pirVal == LOW){ //was motion detected Serial.println("Motion Detected"); delay(2000); } }
ceewl, sehr hilfreich – danke.