90 likes | 288 Views
Motion Activated Twitter Webcam. Douglas Drobny University of Idaho. Objective. Detect motion through an Arduino Board Use Python to take a picture with the default windows webcam Post the image to a Twitter account Relatively inexpensive (goal: $80). Budget. Arduino Uno $30
E N D
Motion Activated Twitter Webcam Douglas Drobny University of Idaho
Objective • Detect motion through an Arduino Board • Use Python to take a picture with the default windows webcam • Post the image to a Twitter account • Relatively inexpensive (goal: $80)
Budget • Arduino Uno $30 • Parallax PIR sensor $11 • Breadboard $ 8 • Webcam ~$20 • Total Price: $59
Arduino Uno R-3 • Uses the ATmega16U2 Architecture • USB or 7-12V power • void loop(){val= digitalRead(inputPin); if (val == HIGH) {digitalWrite(ledPin, HIGH); if (pirState == LOW) {Serial.println("Motion detected!");pirState= HIGH; } } else { if (pirState == HIGH){Serial.println("Motion ended!");pirState= LOW; }
Motion Sensor • First try: Generic PIR Motion Sensor • Sparkfun.com • Does not regulate its own voltage • Complex wiring • Second Try: Parallax PIR Motion Sensor • Internal LED that light up on motion detection • 1:1 wiring
Taking the image • Responds to input on a COM port • Uses the PySerial library • ser =serial.Serial('/./COM3‘, timeout=1) • line =ser.readline() • Takes an image • Uses VideoCapture library • from VideoCapture import Device cam = Device() cam.saveSnapshot('image.jpg')
Twitter Authentication • Requires 4 keys • Consumer Key • Consumer Key Secret • Created when adding an App on twitter.com • Access Token • Access Token Secret • Created when user gives permission to an App
Tweepy • Supports the new Oauth authentication for Twitter • Does not support uploading files in a Tweet • https://github.com/laiso/tweepy does • api = tweepy.API('consumer key', 'consumer key secret‘, 'access token', 'access token secret‘) • api.status_update_with_media(filename, text)
Results • https://twitter.com/#!/ScadaProject • It works! • Issues: • Motion sensor detects motion wider than camera range • Motion sensor light isn’t very sneaky • Too many images quickly to Twitter can error out some posts