I used Intel Edison and Python to acquire and visualize sensor data for growing plants. Even a beginner like me who doesn't understand the circuit can easily get the value just by writing the code if there is a Base Shield and a sensor, which is fun. There are few things written using Python in Edison, so I decided to write it. It doesn't look like IoT because it doesn't work with the server.
edison setup Get sensor value by python ・ Save csv file Visualization with nvd3.js
This was set with reference to the following. Arduino board http://nonnoise.github.io/Edison/
I used the following sensors.
Grove - Temperature Sensor Grove - Light Sensor Grove - Moisture Sensor http://www.seeedstudio.com/wiki/Grove_-Temperature_Sensor http://www.seeedstudio.com/wiki/Grove-Light_Sensor http://www.seeedstudio.com/wiki/Grove-_Moisture_Sensor
I bought a kit because I'm a beginner and I don't understand the circuit too much. http://www.sengoku.co.jp/mod/sgk_cart/detail.php?code=EEHD-4KNG
Also, I thought it would be interesting to talk, so I attached an LCD monitor. http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight
The completed system looks like this. Grow peppermint.
It is interesting that you can easily get data just by inserting it in the pin.
This time, the date, temperature, light intensity, and water content in the soil are saved in csv format every 10 minutes. Import the mraa module and read the value of the pinned sensor. It seems that lcd can be controlled by mraa, but pyupm_i2lcd was easier, so I used this.
sensor.py
#!/usr/bin/python
import datetime
import mraa
import csv
import time
import math
import pyupm_i2clcd as lcd
# definition of Pin
light = mraa.Aio(0)
temperature = mraa.Aio(1)
moisture = mraa.Aio(2)
lcdDis = lcd.Jhd1313m1(0, 0x3E, 0x62)
B = 3975
t = 0
OUT_FILE = "20150426_30.csv"
HOUR = 3600 * 30
with open(OUT_FILE,"wb")as f:
writer = csv.writer(f)
writer.writerow(["datetime","temperature","light","moisture"])
while t < HOUR:
if t % 600 == 0:
#read the value
light_val = light.read()
tem_val = temperature.read()
moi = moisture.read()
#calc temperature
resistance = (1023.0 - tem_val) * 10000 /tem_val
tem_last = round(1/(math.log(resistance /10000) / B+1 / 298.15) - 273.15,2)
#calc light
rsensor = round((1023.0 - light_val)*10 / light_val,2)
#calc today
d = datetime.datetime.today()
#calc moisture
moi_per = round(moi / 10.0,2)
strtime = d.strftime("%Y-%m-%d %H:%M:%S")
with open(OUT_FILE,"ab")as f:
writer = csv.writer(f)
writer.writerow([strtime,tem_last,rsensor,moi_per])
print "Now:",strtime,"," , "Temperature:",tem_last,"," , "Light:",rsensor,",","Moisture:",moi_per
#Check Moisture and Change LCD Display
if moi_per < 10.0:
lcdDis.write(" ")
lcdDis.setColor(128,0,128)
lcdDis.setCursor(0,0)
lcdDis.write("I am thirsty :(")
else:
lcdDis.write(" ")
lcdDis.setColor(255,255,0)
lcdDis.setCursor(0,0)
lcdDis.write("Iam fine :)")
time.sleep(1)
t += 1
The value obtained by this is saved in csv format.
The acquired sensor data was visualized using nvd3.js. http://nvd3.org/
It looks like this. Since it was placed indoors, the temperature did not fluctuate significantly. Is it within the margin of error that the water in the soil is rising? Or is it because it sucked up the water in the saucer? When the light is bright, the value is low, and when it is dark, the value is high. You can see that it is a night-time human being.
・ The training environment is bad (laughs) I tried it in the room this time, but the growth rate is much better if I grow it on the balcony (laugh) When I moved the pot to the balcony, it was growing steadily. I think you can get more interesting data if you put it outdoors.
・ Not IoT This time I didn't go to the point of sending the value to the server, so Next time I would like to send it to the server and make a prediction based on the sent data
· Send values directly to the server ・ Predict when watering is needed from there ・ I want to make an automatic watering device ・ I want to grow vegetables
Recommended Posts