Hardware Reference
In-Depth Information
3. We will modify the example from Adafrui
t that prints the moion sensor events
(
https://learn.adafruit.com/pir-passive-infr
ared-proximity-
motion-sensor/using-a-pir
).
4. Whenever a moion event is detected, we need to send an alert to the
python-
twisted
server launched on Raspberry Pi:
if (client.connect(server, 8000)) {
Serial.println("Motion Detected");
client.println("Motion Detected");
client.println();
//Lets wait for the client to read and
//echo the message
//Note: A second's delay is a bit excessive
delay(1000);
client.stop();
Serial.println("Client Disconnected");
} else {
Serial.println("connection failed");
}
5. In order to take pictures of the bird feeder when there is an incoming moion detecion
event, the camera has to be interfaced to the Raspberry Pi as demonstrated in the
video provided by the Raspberry Pi Foundaion (
https://www.youtube.com/
It can be installed as follows:
sudo apt-get install python-picamera
7. Let's modify the
python-twisted
example,
simpleserv.py
, to import the
picamera
and
datetime
modules (to name the pictures captured by the
camera using a imestamp).
8. If the incoming message is
Motion Detected
, we will take a picture and name
the ile using a imestamp.
9. In the callback method,
DataReceived
, let's capture an image:
with picamera.PiCamera() as camera:
camera.start_preview()
time.sleep(2)
camera.capture('img{timestamp:%Y-%m-%d-%H-%M}.jpg')