Dave's Brain

Browse - Programming Tips - How do use a motion detector as input for an Arduino ?

Date: 2009sep11
Platform: Arduino
Language: Processing

Q.  How do use a motion detector as input for an Arduino ?

A.  I used this PIR Motion Sensor

http://creatroninc.com/product.php?ProductID=289 Part Number: SPEDE-028630 Sparkfun: SEN-08630 Model: SE-10
With these connections:
+5V ------------------+---------------------------------- RED | PIR | GND -------- BROWN 10K Resistor | | DIGITAL INPUT --------+---------------------------------- BLACK (eg 5)
With this Sketch:
const int motionIn = 5; const int ledOut = 13; // Builtin unsigned long lastMove = 0L; void setup() { pinMode(motionIn, INPUT); pinMode(ledOut, OUTPUT); } void loop() { int out; if (digitalRead(motionIn) == LOW) { lastMove = millis(); } if ((millis() - lastMove) < 5000L && lastMove != 0) { out = HIGH; } else { out = LOW; } digitalWrite(ledOut, out); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.