Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.