Smart Plant Sensor

by avivw08 in Outside > Backyard

593 Views, 4 Favorites, 0 Comments

Smart Plant Sensor

WhatsApp Image 2021-01-23 at 16.40.41.jpeg

Does your plants keep on dying? the mysteries of plant-watering schedules are a bit too much?

Well, look no further, because the 'Smart Plant Sensor' will give you just the right alerts in just the right time!

Supplies

- Circuit Playground Express Board (from now on will be called CPX)

- 2 Batteries and a battery cartridge
- Smartphone
- Computer with internet access

The Main Idea

WhatsApp Image 2021-01-21 at 18.22.43.jpeg

Main Concept of the project:

The goal of this project is to send informative messages, twice a day, to the user that will help him decide if his plants need watering today or not. One alert at the start of the day is based on today's forecast, and the other one at the end of the day is based on measurements taken from the plant's pot or ground.

Of course you can think of this project as a module that could be implemented into a bigger autonomous watering system, that beside pre-determined schedule for watering, can make an informed decision per day using weather forecasts and live-measurements

The project consists of 3 parts:

- a code that runs on our CPX,

- a Blynk App

- 2 Scenarios that run once a day in Integromat.


CPX main Idea:

Our CPX code will have a loop that runs every 30 minutes. in each loop we will measure the temperature from the 'Temperature sensor' of our Board. The day will be split into 3 intervals : morning, noon, night. each interval is 8 hours long. During the morning interval (09:00AM - 05:00PM) we will keep track of the temps we have measured and at the end of the interval, the CPX will reach a conclusion if we should water the plants or not.

During 'noon' and 'night' we don't take our measurements into account.

The CPX will also reflect current temperatures with a beautiful display of it's LED's - ranging from majestic blue (cold) to boiling hot red (hot!)

Blynk app main Idea:

Our App will give us current weather-related measurements from our CPX board that sits right between our plants in the garden! what we'll get is:

- current Temperature of our Plants

- current Light levels (as in 'are our plants getting enough sun?')

On top of this, our Blynk app will start a sequence that results the user getting:

- a push notification in the morning with today's forecast

- a push notification in the evening with our CPX conclusion on 'should you water your plants today?' based on the measurements it made during the day.

These 2 messages combined, should be enough for the user to make an informed decision on whether he should water his plants or not!

Integromat main Idea

This part is listening on 2 Webhooks to be sent from the CPX board to start 2 sequences:

1. Weather sequence: when this scenario receives a trigger, it asks for today's forecast from a weather API called : 'Open Weather Map'. it sends it in an appropriate text to the user (e.g sends: "Today will be sunny, light rain, heavy clouds" etc.) The text will differ based on what we got back from the forecast (we'll make a filter that sends different text based on the website's response! )

2. Sensor sequence: when the 'morning' interval is done (see CPX main idea part) this sequence will recieve the CPX measurements from today and conclusion (should we water or not? ) and send an appropriate text to the user based on that information.

Creating Our 'smart Water' Blynk App!

1.jpeg
2.jpeg
3.jpeg
4.jpeg
5.jpeg

While 'Smart Water' isn't such a informative name of what the app does- this description sure is!

1. Download the 'Blynk' app from playstore/appstore.

2. Create new project like the images shown above:

  • click 'new project' (image 1)
  • give it a name and choose your device (image 2)
  • a token will be sent to your email - save it for later (image 3 )
  • click on the empty app screen of your project to open the 'Widget Box'
  • add 'Value Display' and 'Gauge' (image 4)
  • add 2 'Webhook' (image 5)

Configuring Our App

6.jpeg
7.jpeg
webhook.jpeg
WhatsApp Image 2021-01-23 at 13.04.32.jpeg

Now lets configure our widgets:

Temperature:

this is our 'Gauge' widget. choose a virtual pin (we used 'V0', it doesn't matter which one you use) and set the range from '0' to '40' (Celsius) ( see image 1)

Light Level:

this is our 'Value Display' widget. choose a virtual pin (we used 'V1', it doesn't matter which one you use) and set the range from '0' to '1500' (this is the light value returned by the CPX light sensor) (see image 2)

Webhook:

choose a different virtual pin for each one (we used 'V2' and 'V3' it doesn't matter which one you use).

and leave the URL blank for now, we will fill it in later.

at the end it should look something like image 4 without any data

Integromat - Part 1

Forecast Webhook _ Integromat.png
http configure.png
filter.png
push notification forecast.png

Before we begin:
Our Integromat implementation isn't very complex but require a basic familiarity with the platform. please go over a basic 5 minute video on the platform if you are not familiar with it.

for this part you will need to make a free account with Open Weather Map. once you do you'll get an email titled 'OpenWeatherMap API Instruction' and with it an API key you will need later on.

First scenario: Weather Sequence

1. open a new scenario.

2. add the different modules as shown in image 1 (the 'HTTP' one is 'Make http request', the android ones are 'Push' notifications)

3. save the webhook URL and put it inside the URL line in your 'webhook' widget inside of your blynk app (see step 3 picture 3. this is the initiator of the sequence - once the app will make an http request to that address the sequence will begin.)

4. configure the HTTP module like shown in picture 2. replace the 'lat' , 'lon' values with the latitude and longitude values of the place you wish to get the forecast of (in this project, we want to put our city there) use latlong.net for that. replace the 'appid' value (marked in black) with the API key you saved from before.
Make sure 'parse response' is checked and run the scenario once. open the webhook address so the scenario is being played. now we have access to the forecast data and we can integrate it into our push notification!

5. add a filter on the 'Router' module by clicking the wrench between the router and the android modules. the filter can be like shown in picture 3 (this checks if the forecast for today is 'Rain'. the other filter would be set using the same parameter with the condition of 'not equal to' .

6. configure your device on the android module. make one node to send a text for when we should water the plants and one for when we shouldn't. an example template is shown in picture 4

Integromat - Part 2

Sensor Webhook.png
filterSensorWebhook.png
push notification sensor.png

Second Scenario: Sensor Sequence

1. open a new scenario.

2. arrange the modules like shown in the image 1

3. save the webhook URL and put it inside the URL line in your other 'webhook' widget inside of your blynk app (see step 3 picture 3). at the end of it add 2 parameters like so:

?param1=temp&param2=YN

4. set the router's filter like shown in image 2 for one android module, and use the same parameter for the second filter with the condition switched to 'not equal to'.

5. configure an appropriate text for each android module (image 3 is an example of the android module connected to the filter shown in image 2) .

CPX Code

WhatsApp Image 2021-01-21 at 18.22.51.jpeg

Follow these instructions:

1. Download 'blynk.h.ino' and 'SmartPlantSensor.ino' (scroll down to the Downloads section)

2. put these 2 files inside a folder named 'SmartPlantSensor'.

3. Copy the folder into your_sketchbook_folder of Arduino IDE.

To find the location of your_sketchbook_folder, go to top menu in Arduino IDE:

Windows: File → Preferences

Mac OS: Arduino → Preferences

4. go to the 'blynk.h.ino' file and enter your wifi name, wifi password and blynk token in the appropriate spots (the blynk token you saved in step 2 image 3 )

5. upload the code to your CPX

Putting It All Together

WhatsApp Image 2021-01-23 at 16.27.20 (1).jpeg
blynk.jpeg
push notifications.jpeg

if you want to check that everything is configured properly you can change the 'interval' value in 'SmartPlantSensor.ino' to be 1000 (=1sec) and run your integromat scenarios without scheduling. you should receive 2 push notifications with appropriate texts as we configured along the way, and also see live-temperatures and light values in the blynk app (try and cover with your hand the CPX board to see a different message regarding the 'Light Level' in the blynk app.)

once you're satisfied that everything is up and running, set the 'interval' variable back to 1,800,000 (= 30 minutes). Next, set scheduling to our 2 integromat scenarios at the time of your choosing. We recommend setting the forecast scenario to run daily at 09:00 AM and the Sensor Scenario to run daily at 05:00 PM .

Finally, plug those batteries into the battery cartridge, plug in your CPX (don't forget to upload the code first!) , place it near your most precious tulips and never forget watering them ever again!