The story
In our day-to-day life, we often forget to water and take care of our plants. Therefore I thought to make a project which will give us notifications on our phones about our plant's status on it's moisture content and intensity of sunlight falling on the plant at regular time intervals along with it's Intensity graphs to determine the best timings for our plant to receive sunlight.
Here is a video of the project in action:
Gathering all the required componentsAll the components required for the project are included in the Bolt Iot kit Except the Soil sensor which is easily available in the market at a cheap price.
1. Soil Sensor
2. Bolt Iot Wifi Module
3.LDR
4.Jumper Wires(Female/Male)
5.Resistor (10k ohm)
Integromat is an easy to use, powerful tool with unique features for automating manual processes to connect your favorite apps, services and devices with each other without having any programming skills
All you have to do is create a scenario that will watch for new data in one app/service, set-up the proceeding modules for the desired end result and Integromat will execute the task for you.
Twilio SMSTwilio is a cloud communications platform which allows software developers to programmatically send and receive text messages using its web service APIs.
Mailgun E-MailMailgun is an email automation service provided by Rackspace. It offers a complete cloud-based email service for sending, receiving and tracking email sent through your websites and applications. Mailgun features area vailable through an intuitive RESTful API.
Assembling the hardware1. Get all the required components.
2. Connect one end of the LDR to pin A0 and other with 3.3V supply of the Bolt.
3. Connect a 10k Ohm resistor between A0 and GND pins of the Bolt.
4. Now connect the soil sensor probe to it's amplifier circuit using female/male jumper wires and connect the Vcc, GND and DO (Digital Output) pins of the amplifier circuit to 3.3V, GND and pin 0 of the Bolt unit respectively using the female header connectors. Ignore the analog output of amplifier circuit.
5. Place the soil sensor probe into the plant and power up the Bolt.
NOTE: Check all the connections before powering up Bolt and for any help look into the schematic.
1. First make an account on Integromat using the link.
2. After setting up the account, create a new scenario using the 'Create a new scenario' button located on the top right corner in dashboard.
3. In the services choose BoltIIoT, Twilio and Mailgun.
4. Now using the services build the required logic flow as shown in figure below.
a) Create and connect 2 bolt modules which takes data from the A0 and 0 pin of bolt module.
b)Then Using a router connect one of them to a router(Good Moisture) and further connect it to 2 Twilio modules. This route will be taken in the logic when the moisture level is good.
c)Connect the other link to a increment function and then to another router. Extend this router to 3 twilio modules (2 for low moisture levels and the 3rd one when the moisture level has been low for a long time.)
d)Further more connect each Twilio module to an 'Send an email' Mailgun module as shown
5. After building the logic now we need to enter the credentials for the services being used. i.e Bolt device ID and the API key for the BoltIoT service, SSID, Authentication token number, sender's number for the Twilio service and API key, Sandbox URL, Sender URL for Mailgun service. You can find all these at cloud.boltiot.com, twilio.com, mailgun.com respectively.
Also fill the required command along with the pin no. for the BoltIoT service, the required SMS along with recipient's number to be send for Twilio service and the required E-Mail subject and content along with recipient's E-mail Id to be sent for Mailgun service.
7. Attach resume error handler to both BoltIoT services in order to prevent Integromat from stopping the scenario automatically in case of any error. In the handler use any number that is to be assigned to the Bolt in case of error.
8. Apply error filter and conditions to the router's input branch and moisture content and light intensity filter to each of the router's output branch as shown below.
a)For good moisture level
b)For low moisture level
Also set the 'Reset a value' of the increment tool to 'Never'. It will help us to keep track of how many hours the plant has gone without water.
9. i)For Twilio service use your SSID, authentication key and sender's number provided on the Twilio dashboard.
ii)For MailGun service use your API Key, Sandbox URL and Sender URL (which is test@your SANDBOX_URL) which is provided on your Mailgun's sandbox dashboard.
10. After successfully creating the logic, run to check for any errors.
11. Finally schedule your scenario according to your requirements and save it. In this case the scenario will run after every 60 minutes.
IMP:The Whole scenario blueprint of this logic has been linked below(in case of confusions or errors)
NOTE: Don't forget to save your work before closing it.
Step 2: Writing the Code on Virtual servers using PythonI did this project in python(3.5.2) in Virtual box. You can run Python files on either Digital Ocean or on Ubuntu server virtual machine.
1.Once you start your virtual server you have to create configurations file for this project, using the following command.
sudo nano conf.py
After the editor is open, type in the following configuration parameters
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
Save the file by pressing Ctrl+x.
2.Now create one more file named anomaly_detection.py, using the following command
sudo nano anomaly_detection.py
The code to put in this file is a bit long so I will put in the code section of this project.
Save the file by pressing Ctrl+x.
3.After creating and saving both files, We need to run the program. You can do this by running the anomaly detection code using the following command
python3 anomaly_detection.py
Step 3: Visualizing the Data (Plotting Graph) on the Bolt CloudFollow these steps to visualize the collected Sunlight Intensity data:
1. Login into cloud.boltiot.com and click on the 'Product' tab.
2.Create a new Product on the Bolt Cloud and check option of Input devices and GPIO.
3. Next, we need to 'Configure your product'. For this click on the Configure Product icon.
4.Now choose the hardware pin 'A0' for this project.
5.Now give a variable name 'sunlight' to the pin value.
6.Save your configuration and move to the code tab.
7. Here you have 2 options
a) Make a single graph plotting (Simple way):
Click on the 'Code' tab, and then click on the 'Import code' button to generate and import a new code.
Here you have multiple types of graph to choose from. Eg- Bar graph, Line Graph, Scatter graph.
b)Multiple graph plotting (Advanced way):
Here you can write your own code to plot multiple graphs. I have done this method with Area, Bar and scatter graph. The code for the same is given below.
The code tells the Bolt Cloud, how to plot the sensor data for visual representation.
5. Give a name to your code and save the configurations.
6. Link Bolt with the 'Sunlight' product that you created.
7. Deploy the code to your Bolt.
8. See the output on a plot by clicking on 'View this device'.
Output PlotSingle-Graph plot:
Multiple-Graph plot:
1.The soil sensor measures the moisture content present in the soil and LDR measures the light intensity falling on the plant. Both the data are read by the Bolt unit and send to Integromat logic whenever a read request is arrived.
A router is send different SMS & E-mail to the user based on the data received. For determining which message has to be delivered, each branch connecting Twilio, Mailgun and router is set with a filter having certain conditions.
To handle any kind of error a resume error handler is attached to both of the BoltIoT services.
2.The python code runs and collects atleast 10 data points to start its detection i.e. Z-Analysis.Once 10 data points has been collected it starts to detect for anomaly in the sunlight intensity. Once any anomaly occurs it proceeds to send a SMS to the number which has been specified in the code and it's corresponding E-mail to the recipient e-mail specified.
3.Whenever the light falling on the sensor changes, the resistance of sensor changes which is then converted into a change in voltage. The ADC pin on Bolt WiFi Module converts this analog voltage level into digital values which are shown on the graphs.
This digital data is then sent to the cloud where it is plotted for visual representation.
We are done!Now just turn the scenario on, run the python code and sit back.
Comments