Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* PIR Doorbell & Webcam by grist, Jan 2012
- Uses the PIR activated switch from an AEI PIR-9038W to turn on a webcam and activate my doorbell.
- Attiny version.
- Compiles to less than 1k, so could maybe run on an Attiny45. I used an Attiny85.
- */
- // Pins
- const byte pir_in = 2;
- const byte db_pin = 3;
- const byte webcam_pin = 4;
- const byte led_pin = 1; // indicator that webcam is on
- // Globals
- int ttl = 30000; // minimum number of milliseconds to keep the camera active.
- unsigned long end_time; // when to stop capturing. This is reset by any movement during the capture
- void setup() {
- pinMode(pir_in, INPUT);
- pinMode(db_pin, OUTPUT);
- pinMode(webcam_pin, OUTPUT);
- pinMode(led_pin, OUTPUT);
- }
- void loop() {
- digitalWrite(webcam_pin, LOW);
- digitalWrite(led_pin, LOW);
- digitalWrite(db_pin, LOW);
- // Low means either the sensor has tripped or someone has pulled the wires out.
- // Either way we want to start capturing
- if (digitalRead(pir_in) == LOW) {
- end_time = millis() + ttl; // doesn't allow for millis rollover
- digitalWrite(webcam_pin, HIGH); // start the webcam
- digitalWrite(led_pin, HIGH);
- digitalWrite(db_pin, HIGH); // trigger the doorbell
- delay(200);
- digitalWrite(db_pin, LOW);
- // loop until there hasn't been any movement detected for 30 seconds
- while (millis() < end_time) {
- // If the pin is still LOW push the end time out
- if (digitalRead(pir_in) == LOW) {
- end_time = millis() + ttl; // doesn't allow for millis rollover
- }
- }
- // Fallen out of the loop so there's been ${ttl} milliseconds since movement was detected
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement