HTE - Moisture Sensor

Overview

For Fullscreen: https://www.youtube.com/watch?v=Z16mRQxJfVI

This HTE episode will show how to use a soil moisture sensor with the Quantum System.


How does a soil moisture sensor work?

Soil moisture sensors are used to measure the volumetric water content in the soil. There are numerous ways to measure the moisture content of soil. We will measure the moisture by determining the soils electrical resistance. It measures measures the flow of electricity between two electrodes placed in the soil and takes that data to determine the soil moisture content. When there is no water in the soil electricity cant flow really well so the sensor will measure a high potential between the electrodes.

When you water the soil know the electric resistance of the soil will lower and electricity between the electrodes will flow easier. The sensor will measure a lower potential between the electrodes.

Those type of sensors have only one downside. They are known to corrode over time and give less accurate readings of the moisture content. The sensor hat 3 pins that can be used. VCC pin is to power the sensor and GND pin is used to ground it. The Sig pin is used to get the readings of the sensor.

 


Assemble the Circuit

Picture

Name

Quantity

Link

Picture

Name

Quantity

Link

Soil Moisture Sensor

1

Can be purchased here

5V Power Supply DIY Kit

1

Can be purchased here

 

Jumper Cables (MM)

5

Included in Starter Kit

Or you can purchase it here

Q-Client Builder Base

1

Q-Client

If you have all the parts listed above, we can go ahead and build the circuit. It should look like this:

You don’t have to use the 5V Power Supply DIY Kit but if you use it you can place the soil moisture sensor anywhere you want. Connect the 3.3 V port of the Builder Base with the VCC pin of the soil moisture sensor (NOT THE 5 V pin!). Connect the GND pin of the sensor with the GND port of the Builder Base. For the signal pin of the sensor you can choose and GP pin of the Builder Base to connect to.


Pair the Builder Base

Now we want to pair the Builder Base with our Q-Server. In order to do so, go to the Homescreen of your Q-Server.

Next click on the lift side symbol labeled “Clients”. Switch to the “Unpaired” tab at the top middle of the screen.

You should see your unpaired Builder Base. If not, check if you have plugged in the power supply for the Builder Base. Now move to the three dots below “Actions” and click “Pair”.

Once your Client is paired, click the “Setup” button.

Now you can edit your Client. Give him a Name you want and also a location where you are going to use it. Hit “Save” when you finished.


Build the Firmware

Next we will build the firmware for our project. Move to the firmware tab of your Q-Server.

Click on “+ Create New” to start building a new firmware. Give it a name so you can identify it. We named ours “Moisture Sensor”.

You will see that there is no added hardware yet. So click “+ Add Hardware”.

Since there is yet no soil moisture sensor available as a hardware we going to search for a “Analog In”. The sensor is a analog device and we will transfer that data into a digital data. Always give your added hardware a name to differentiate them later on. We named it “Moisture Sensor”.

If you now click on your added hardware a tab should open up. As you see we have to select a Driver. Since we are using one of the GP pins we are going with the GPIO Driver.

After selecting the Driver you can select a pin. Select the pin you connected the sensor to the Builder Base. In our case it is the GP6 / RX.

Make sure save your changes to the hardware. When you are finished click on the Actions dots of the Moisture Sensor and select “Upload”.

After that you will be prompted to select a client you want to upload your firmware file to.

Click “Upload”.


Build the App

Now we are going to build the application for the moisture sensor. Move to the apps tab.

Click “+ Create New” and give your app a name. We named it “Moisture Sensor Demo”. Hit “Create”.

You will find yourself on the canvas. The first object we gonna search for is the analog in. You can either use the search bar or search by yourself by clicking in the different object groups.

Name every object you drag onto the canvas to help visibility and clarity. We named the analog in object “Plant 1”. The next object we will drag onto the canvas is a manual ranging object. It belongs to the code objects.

By clicking on the “Value” port of the analog in object you can connect the analog in with the manual ranging object by clicking again on the “Value” port of the manual ranging object. When you are finished we want to set the “In Max” value for the manual ranging object. Set the value to 4095. We need this number because the analog signal will get switched to a digital signal and there are only 4095 possible states for the digital signal because of the use of a 12 bit system.

For the “Out Max” we will set 100 because we always want to see what the maximum signal of the moisture sensor is.

“Rounded” we will set to true since we want the outgoing numbers and incoming number to be rounded up.

Now we going to add a string merge object. This object will merge up to 4 strings together and give out one final string.

Connect the “Value” port of the manual ranging object with the “String A” port of the string merge object

Since we are getting a value from 0 to 100 into “String A” we want to display it in percent. So we gonna give the “String B” the value “%”. Now the incoming value will be merged with the percent symbol.

Next we bring in a text interface object. This object will display the outcoming string of the string merge object.

Connect the string merge object with the text object. Also we gave the text object a name, a dashboard label and a dashboard group.

If you want to add a new dashboard tab or add a new dashboard group to a dashboard tab you can use the dashbuilder in the top right corner next to properties.

We gonna edit the “Tab 1” by clicking on the pencil. We named it “Plant Saturation Levels”.

Next click into the group circle and select the “Plant Saturation Levels” tab.

Click on the pencil to edit the group. We named the group also “Plant Saturation Levels”.

Go back to the properties of your text objects and select the new dashboard group.

Add another text object and connect it to the analog in object. We will need this text object for the calibration of the manual ranging object.

Name the text object and assign a label and group.

After you finished click on “Save App”. Go to “Return To My Apps”.


Map the Hardware

In the next step we are going to map the hardware to the software objects of the app. Click on the play button to start the “Moisture Sensor Demo” app.

As you can see we have our analog in. We now need to select the client we want to map it to. Click on “Done” and click “Save + Run”.

You can see that the play symbol will change to a green circle. Your app is running and ready for use!


Run the App!

To see the data of your moisture sensor click on the dashboard icon in the top right corner.

Select the “Moisture Sensor Demo” app.

Now you can see the saturation of the Plant 1 in percent. You will also see the analog value we will need to adjust it in the app itself.

Now put the sensor inside a glass filled with water to get a measurement for a fully saturated medium.

4095 was the maximum value we set before. As you can see the maximum value we can get is 3301. Note that down.


Adjust the Analog value

We will now adjust the maximum input of our app. Go back to your apps tab and click on the three dots of your “Moisture Sensor Demo” app.

Click on the “In Max” port of the manual ranging object to adjust the value. Type in your value we measured before and safe the app again.

When you put the sensor back in the water. The readings should be way more accurate than before. A deviation of 1-2% is totally fine.


Notification System with LCD

In the next step we will set up a notification system which will inform us when the plants needs to be watered and also the saturation level. First we will move to the library tab in our Q-Server and go to services. Here we want to download the twilio service. It will be used to send messages to a dedicated telephone number.

Once the download is finished go to your service tab. You will see the twilio service and the status of it.

Click on the three dots of the twilio service and click on start.

Now we will have to configure the twilio service. First you need an account sid and authentication token. The links are provided to you in the description.

Once you filled this out you will be prompted to input a telephone number. We use a phone number of our phone since we are getting sms messages later on.

After that you are ready to go. Click on “Activate” to start the twilio service.

Next we will modify the app. So go back to your apps tab and click on the three dots to edit the app again like before. First we going to add the twilio object to the canvas.

Add a number compare object.

Connect the “Value” port of the manual ranging object with the “Number 1” port of the number compare object. Set the “Number 2” value to 50. So when the the saturation drops below 50 % we want to be notified by the system to water our plant.

Set the trigger on for the “Number 1”.

Next connect the “Less” port of the number compare object to the “Trigger” port of the twilio object.

Type in your telephone number in the “Telephone Number” port of the twilio object.

Since we want the message also be displayed we need to add a lcd object.

Also add two static string objects.

One of the static string object will send the string when the plant is saturated.

The other one will tell you to water your plant. Name these objects accordingly to their purpose.

Connect both static string objects with the “String” port of the lcd object as well with the “SMS message” port of the twilio object.

Add a data sequence object to the canvas.

Connect the “Greater” and the “Less” port of the number compare object with the “Trigger” port of the data sequence object.

Connect the “Trigger 1” port of the data sequence with the “Clear” port of the lcd object. So everytime a new number comparison will accure the data sequence will send out a trigger to clear the lcd/

Connect the “Trigger 2” port of the data sequence object with the “Send to Display” port of the lcd object. When a new number comparison occurs the string will be send to the lcd.

Connect the lower static string object which notifies you to water you plant with the “Less” port of the number compare object.

Connect the “Greater” port of the number compare object with the upper static string object which tells you that your plants are saturated.

So one of the static strings will be send to the lcd depending on the number comparison before. Next we have to map the hardware again. Make sure to choose the right clients your hardware are connected to.

With the sensor out of the glass of water you will get the message “Water Plant 1!”.

When you put the sensor inside the water the message will change to “Plants Saturated”.

When you pull the sensor out the lcd message will immediately change. You will also get a message to the telephone number you typed in.

That’s it! You are now done and ready to use your system with a real plant!

This is how you connect and use a moisture sensor with the Quantum System. We also showed you how to set up a lcd and get notified via a telephone number to water your plants.

Happy Making!