Skip to content

Instantly share code, notes, and snippets.

@bassdread
Created May 21, 2013 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bassdread/5619506 to your computer and use it in GitHub Desktop.
Save bassdread/5619506 to your computer and use it in GitHub Desktop.
# Connect to an Arduino attached to a moisture sensor. The code below is
for the Arduino
"""
const int pin = A0; // Analog input pin
unsigned long duration;
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps
pinMode(pin, INPUT);
}
void loop() {
duration = analogRead(pin);
Serial.print("sensor=" );
Serial.println(duration);
delay(1000);
}
"""
import serial
from blinkstick import blinkstick
import time
bs = blinkstick.find_all()[0]
# we are alive!
bs.set_color(name='blue')
while True:
try:
# you need to change /dev/tty.usbmodemfd111
ser = serial.Serial('/dev/tty.usbmodemfd111',9600,timeout=1)
data = ser.readline()
moist = data.split('=')[1]
print moist
if int(moist) > 600:
bs.set_color(name='red')
else:
bs.set_color(name='green')
except:
# we missed never mind
pass
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment