Devices & Components
SparkFun Soil Moisture Sensor (with Screw Terminals)
ATtiny85
Raspberry Pi Zero
Software & Tools
twidge
Project description
Code
attiny85 code
arduino
Program atTiny85 using Arduino Uno
1#include <SoftwareSerial.h> 2#define RX 1 // D1, Pin 6 3#define TX 2 // D2, Pin 7 4#define sensorPin 3 // D3, Pin 3 5SoftwareSerial toRaspberry(RX, TX); 6void setup() { 7 pinMode(sensorPin, INPUT); 8 toRaspberry.begin(9600); 9} 10void loop() { 11 int sensorValue = analogRead(sensorPin); 12 toRaspberry.println(sensorValue); 13 delay(10000); 14}
attiny85 code
arduino
Program atTiny85 using Arduino Uno
1#include <SoftwareSerial.h> 2#define RX 1 // D1, Pin 6 3#define TX 2 // D2, Pin 7 4#define sensorPin 3 // D3, Pin 3 5SoftwareSerial toRaspberry(RX, TX); 6void setup() { 7 pinMode(sensorPin, INPUT); 8 toRaspberry.begin(9600); 9} 10void loop() { 11 int sensorValue = analogRead(sensorPin); 12 toRaspberry.println(sensorValue); 13 delay(10000); 14}
Raspberry Pi Zero
python
1#!/usr/bin/env python 2import time 3import serial 4import os 5import random 6import sqlite3 as sl 7def main(): 8 ser = serial.Serial( 9 port='/dev/serial0', 10 baudrate = 9600, 11 parity=serial.PARITY_NONE, 12 stopbits=serial.STOPBITS_ONE, 13 bytesize=serial.EIGHTBITS, 14 timeout=1 15 ) 16 x = ser.readline(); 17 while (x == ''): 18 x = ser.readline(); 19 print x 20 checkSituation(x.rstrip()); 21def checkSituation(x): 22 waterLevel = 1024 - int(x); 23 tweetText = '{} --water level:{}'; 24 if (waterLevel < 200): 25 tweetText = tweetText.format(getHelpTweet(), waterLevel); 26 else: 27 tweetText = tweetText.format(getFineTweet(), waterLevel); 28 tweet(tweetText); 29 log(waterLevel); 30def log(waterLevel): 31 con = sl.connect('plant.db'); 32 sql = 'INSERT INTO PLANT_DATA (water_level, timestamp) values(?, ?)'; 33 data = (waterLevel, int(time.time())); 34 con.execute(sql, data); 35 con.commit(); 36 con.close(); 37def tweet(text): 38 command = 'twidge update "{}"'.format(text); 39 os.system(command); 40 print(command); 41def getFineTweet(): 42 fines = ["I'm doing fine today :)", 43 "It's a beautiful day ;)", 44 "I love my pot :)"]; 45 return random.choice(fines); 46def getHelpTweet(): 47 helps = ["I need water!! :(", 48 "Somebody give me water, please", 49 "Anyone there to water me? :("] 50 return random.choice(helps); 51if __name__ == "__main__": 52 main()
Downloadable files
Sketch
Sketch
Sketch
Sketch
Comments
Only logged in users can leave comments