Flushduino!

Monitor water level in tank and send sensor reading via XBee to iMac running Python script reading serial input from second XBee radio. When tank level drops and refills, send tweet from iMac to Twitter reporting a flush.

Presentation Slides

Physical Computing with Arduino & ZigBee (4.8MB PDF) - Presented at CPLUG on February 8, 2011

Open Source Hardware Hacking with Arduino (6.8MB PDF) - Presented at BarCamp Harrisburg on April 9, 2011

Parts List

1 x Arduino Uno

2 x Adafruit XBee Adapter Kit [v1.1]

2 x XBee Module – XB24-ACI-001

1 x USB TTL-232 cable – TTL-232R 3.3V

Sensor

Just two wires twisted together for stability, with the ends stripped. When not in water, the values float around 100 - 400. When in water, the values go to around 1000 - 1020.

Arduino Code

#include <NewSoftSerial.h>

NewSoftSerial mySerial =  NewSoftSerial(2, 3);

int sensorPin = 0;
int sensorValue = 0;
int ledPin = 13;

void setup()  {
  pinMode(ledPin, OUTPUT);
  Serial.begin(19200);
  Serial.println("SETUP: PIN 2 = RX, PIN 3 = TX, BAUD = 19200");
  // set the data rate for the SoftwareSerial port
  mySerial.begin(19200);
  mySerial.println("Hello, world!");
}



void loop()                     // run over and over again
{

  Serial.println("Sending ping...");
  sensorValue = analogRead(sensorPin);
  mySerial.println(sensorValue);
  Serial.println(sensorValue);

  delay(1000);
}

Python Code

#!/usr/bin/env python

import tweepy
import serial
from time import gmtime, strftime

consumer_key        = 'xxxxxxxxxxxxxxxxxxxx'
consumer_secret     = 'xxxxxxxxxxxxxxxxxxxx'
access_token_key    = 'xxxxxxxxxxxxxxxxxxxx'
access_token_secret = 'xxxxxxxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
api = tweepy.API(auth)

ser = serial.Serial('/dev/tty.usbserial-FTEPJ3NV', 19200)

print "Flushduino!"
print ser.name, ser.baudrate, ser.bytesize, ser.parity, ser.stopbits

ser.write("Hello, World!")

flushing = False
count = 0
while(1):
    
    line = ser.readline()
    timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    print "%s\t%d\t%s" % (timestamp, count, line),
    try:
        value = int(line)
        if value < 1000 and flushing == False:
            flushing = True
        if value > 1000 and flushing == True:
            count += 1
            api.update_status('Flush completed at %s GMT' % timestamp)
            flushing = False
    except ValueError:
        pass

ser.close()

Related Links

flushduino.txt · Last modified: 2012/02/19 18:28 by john
Trace: flushduino
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0