Siddhant Poojary
Published © MIT

All In One Plant Monitoring System

A Bolt IoT project which gives you timely updates of your plant moisture and sunlight levels, along with alerts if any.

IntermediateFull instructions provided4 hours4,305
All In One Plant Monitoring System

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Soil Moisture Sensor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
LDR
×1

Software apps and online services

Integromat
Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API

Story

Read more

Custom parts and enclosures

Integromat Logic Blueprint

This is the blueprint for the Integromat logic. You can use by importing this blueprint into your scenario.

Schematics

AIO Plant Monitoring Circuit

Code

conf.py

Python
The code contains your APIs and keys of your Bolt module, Twilio and Mailgun Dashboard.Put this code into conf.py file in your virtual server
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
SSID = 'You can find SSID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device'
FRAME_SIZE = 10
MUL_FACTOR = 6

anomaly_detection.py

Python
Code for the sunlight anomaly detection.Paste this in your anomaly_detection.py file in your virtual server.
import conf, json, time, math, statistics
from boltiot import Sms, Bolt, Email
def compute_bounds(history_data,frame_size,factor):
    if len(history_data)<frame_size :
        return None

    if len(history_data)>frame_size :
        del history_data[0:len(history_data)-frame_size]
    Mn=statistics.mean(history_data)
    Variance=0
    for data in history_data :
        Variance += math.pow((data-Mn),2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size-1]+Zn
    Low_Bound = history_data[frame_size-1]-Zn
    return [High_bound,Low_Bound]

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
history_data=[]

while True:
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    if data['success'] != '1':
        print("There was an error while retriving the data.")
        print("This is the error:"+data['value'])
        time.sleep(10)
        continue

    print ("This is the value "+data['value'])
    sensor_value=0
    try:
        sensor_value = int(data['value'])
    except Exception as e:
        print("There was an error while parsing the response: ",e)
        continue

    bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
    if not bound:
        required_data_count=conf.FRAME_SIZE-len(history_data)
        print("Not enough data to compute Z-score. Need ",required_data_count," more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue

    try:
        if sensor_value > bound[0] :
            print ("Anomaly Detected. Light Intensity has suddenly increased. Sending an SMS & Email.")
            response1 = sms.send_sms("Light Intensity has suddenly increased")
            response2 = mailer.send_email("Anomaly Alert", "Light Intensity has suddenly increased")
            response2_text = json.loads(response2.text)
            print("This is the response of SMS ",response1)
            print("Response received from Mailgun is: " + str(response2_text['message']))

            
        elif sensor_value < bound[1]:
            print ("Anomaly Detected. Light Intensity has suddenly decreased. Sending an SMS & Email.")
            response1 = sms.send_sms("Light Intensity has suddenly decreased")
            response2 = mailer.send_email("Anomaly Alert", "Light Intensity has suddenly decreased")
            response2_text = json.loads(response2.text)
            print("This is the response of SMS ",response1)
            print("Response received from Mailgun is: " + str(response2_text['message']))
        history_data.append(sensor_value)
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

Multiple Graph code for Sunlight Intensity Plotting

JavaScript
Paste this code in the product's code tab.This is for multiple graph plotting.
setChartTitle('Sunlight Intensity graph');
var Graph1 = new boltGraph();
Graph1.setChartType("areaGraph");
Graph1.setAxisName('Time_stamp','Sunlight');
Graph1.plotChart('time_stamp','sunlight');
var Graph2 = new boltGraph();
Graph2.setChartType("barGraph");
Graph2.setAxisName('Time_stamp','Sunlight');
Graph2.plotChart('time_stamp','sunlight');
var Graph3 = new boltGraph();
Graph3.setChartType("scatterGraph");
Graph3.setAxisName('Time_stamp','Sunlight');
Graph3.plotChart('time_stamp','sunlight');

Credits

Siddhant Poojary

Siddhant Poojary

1 project • 3 followers
Computer Engineer , Trader , Athlete

Comments