IoT system to monitor soil moisture with Arduino and cloud platform

This IoT system monitors the soil moisture using Arduino and sensors. Data coming from sensors is sent to a cloud platform. Moreover, this Arduino IoT system implements a notification system so that when the soil gets too dry it sends a notification.

As you know already, Internet of things is one of the most important topics nowadays, that promises to shape our future and the way we live. One interesting aspect about IoT is the fact we can experiment an IoT system building it by ourselves. There are several prototyping boards available in the market and we can build amazing IoT projects without spending too much.

IoT system project overview

To build this project we need:

  1. Arduino MKR1000 (or a compatible board)
  2. Moisture sensor
  3. Carriots free account (use this link to create a free account)
  4. IFFT account (to know more click here)

The idea that stands behind this project is building an IoT system that monitors the soil moisture detecting when it gets too dry. The Arduino MKR1000 controls the sensor sending the data to the Carriots IoT platform. This platform, in turn, stores the data coming from the sensor and detects when the values stored are under a threshold level. We will see later how to analyze the data. By now, we can assume that the Carriots IoT platform is able somehow to invoke an IFFT service that will send a short message to the user alerting him. Building this IoT system we can explore how to use several components of the IoT ecosystem. Moreover, this project displays the humidity soil status using a LEDs matrix. Let us see how to build it.

IoT system sensors: Retrieving data

In this first step, we have to read the sensor data. This IoT project uses YL-38 + YL-69 sensor. This is an analog sensor that can be inserted into the soil we want to check. The picture below shows how to connect the sensor to Arduino:

iot system to monitor the soil moisture

The code is very simple, we read data from the A1 pin and then we calculate the humidity:

float moistureHum = analogRead(A1);
moistureHum = (1023 - moistureHum) * 100 /1023;

This is very simple, not much to explain about it.  The value stored in moistureHum is the one we will send to IoT cloud platform. Moreover, to do it, Arduino MKR1000 has to connect to internet so that it can sends data. The code below describes how to connect Arduino to the WiFi:

#include "WiFi101.h"
WiFiClient client;
void setup() {

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);

where the connectToWifi() is:

void connectToWifi() {
  while ( status != WL_CONNECTED) {
   Serial.print("Attempting to connect to WPA SSID: ");
   // Connect to WPA/WPA2 network:
   status = WiFi.begin(ssid, pass);
   // wait 10 seconds for connection:

In this code, you have to provide the ssid and the pass (WiFi password).

That’s all. We can manage in this sketch the LEDs matrix showing the humidity level as described in the code attached to this article. Now we can focus our attention on the IoT cloud platform.

Learn how to build an IoT Arduino system to monitor the soil moisture. Step by step guide #IoT Click To Tweet


Connecting to the IoT cloud platform

Before sending data to the cloud, we have to configure our Carriots platform in order to manage the data. Carriots uses a hierarchical structure to group and manage devices. Therefore, we have to create this structure before using our device. At the top of this structure, there is the Project. Once you are logged in, you have to click on Hierarchy and then Project filling the data required:

building an IoT system

The next step is creating the service filling the data required:

IoT system DIY

Finally, you have to create the group:

how to use carriots

The steps are very fast and you do it only once. The last step is configuring our device. It represents the physical device we are using to send data. This device belongs to the group created in the last step, that in turn belongs to the service. The service belongs to the project. The configuration step is very easy as shown in the picture below:

connect arduino to the clud

That’s all. The configuration steps are completed. We have to connect the Arduino device to Carriots and start sending data. In this step, it is important the developer id shown in the picture above, it represents the unique device identifier we will use to bind the data coming from our Arduino device to the Carriots device. Another important parameter is your API Key. You can find it in Settings -> Api key menu. In order to send data, let us add this function to the sketch shown above:

Notice that the function sends a JSON payload containing the data read from the sensor. This function must be invoked in the loop() method. Running the sketch, we can notice that the device sends data to the Carriots as shown below:

iot sensor data

Monitoring the IoT sensor data

The next step is monitoring the data. Usually, in an IoT system, we are not only interested in acquiring data from the sensor but we want to monitor such information to take corrective actions when the values are out of a specific interval. There are several actions we can take, in this example we want to inform the user alerting him/her. Even if Carriots has a built-in email system, we prefer to integrate with Carriots another useful and interesting platforms called IFFT. This platform provides several integration services we can use and integrate into our IoT projects.

In order to alert the user we need two components:

  1. a monitoring data system
  2. alerting system

As monitoring data system, this IoT system uses Carriots listener. A listener is a process that analyzes the incoming values and applies a specific rule. When the rule is verified then it invokes a script. The interesting aspect about Carriots is that we can use Groovy as a scripting language to invoke external services.

The alerting system is built on IFFT. Before completing the work on Carriots, it is useful to configure the IFFT. As stated before, we want to send a short message when the humidity hits a threshold level. In order to achieve it, we configure a short message service in IFFT. It is required you have a free account in order to complete this task. As a first step, let us create a new Applet:

ifft configure IoT applet



Now click on plus sign to add the service and search for Maker service:

ifft maker service

Select Maker webhooks to enable IoT maker. Now we have to configure the maker service adding the event name that triggers the sending message process:

configure IFFT maker service

Finally, let us enable the sending message service configuring all the required parameters like the destination number and the message body:

ifft sending message

That’s all. Now we can focus our attention on the listener in Carriots platform. Let us create a new listener that invoke the URL related to the applet we have just created. When the listener invokes the URL, IFFT sends a short message. The picture below shows how to configure the listener:

how to configure carriots listener

The last step is configuring the expression. We can write it using Groovy as described in this example.

That’s all, now you can test the project verifying that when the soil moisture is lower than the threshold level, we will get a short message on our mobile.


At the end of this article, you have learned how to build an IoT system using sensors, Arduino and IoT cloud platforms. As you have noticed during this tutorial, we can integrate existing platforms and services to build an IoT system.

More posts...