Freitag, 5. Juni 2015

The Mission: Keep the cats secure (DLink, Arduino, Raspberry)

You know, now living in the Netherlands also causes that me and my wife travel back to Germany for a weekend once in a while. Leaving the cats back in Amsterdam creates a bad feeling.This leads to a little bit of coding and playing with various technologies :-)

Centre of the information, cause my wife wants to see the cats, is a D-Link webcam. This is placed in a central room which the cats need to cross when they want to go to eat something, go to the toilet or go to bed :-)
The installation is very simple, basically it results in sending a email with 6 pictures (3x before the event and 3x after the event) to a Gmail address.

 Now, the new apartment does all the heating and cooking with gas. That was an issue too, cause when we are away no one knows what could happen. So I took an arduino and a MQ2 gas sensor. It is really easy cabled as only three wires are needed which can be directly plugged into the arduino
  1. GND (Ground)
  2. Analog output (A1)
  3. 5V power supply

by the way: 3V work too, just lead to a not so good output.

The script to read out the data is very smale an simple.

void setup() {
void loop() {
  float vol;
  int sensorValue = analogRead(A0);
  if (vol > 1.5) {

Than finally, how to get the data? Well honestly, I first bought a network shield which I wanted to use, but like always, when the next trip was three days away, I realized that I will not have it done by that day. So I simply connected it to my raspberry pi which is in use anyway.

So the Arduino usb cable is now connected to the Raspberry USB port. And the data is fetched via the serial console.

The code to get the data is even more simple.

import serial
ser = serial.Serial('/dev/ttyACM1',9600)
import time
import smtplib
import sys

def mail(msg):
        # code to send email via Gmail

while (1) :
        data = ser.readline()
        if  data > 1.5:
                txt = "actual Gas indicator = " + str(data)
                print "Gas: " + data