Do You Know How Your Plants Are Feeling?

DZone 's Guide to

Do You Know How Your Plants Are Feeling?

If you garden, your inner botanist probably wants to know how much moisture is in your plants' soil. This guide will help set your sensor up so you can see for yourself.

· IoT Zone ·
Free Resource

Nothing will replace walking out and handling soil for yourself, but today's technology has made it possible to remotely monitor soil and track parameters that are immeasurable to the human senses. Soil probes like the SHT10 have advanced technologically to be extremely accurate and offer an unparalleled look into what is happening underground. Giving instantaneous information on soil moisture content, saturation, salinity, temperature, and more, soil sensors have become important tools for anyone working with soil. From the small-town farmer trying to increase crop yields to researchers looking to understand CO2, soil sensors are a must-have for any advancing agricultural operation.

Temperature and moisture sensors are amongst the most commonly used environmental sensors. And, more importantly, similar to the metrics of computer advancements increasing power but dropping prices, so too have soil measurement systems. These systems have and will continue to become more affordable for anyone.

What is soil moisture? Soil moisture is difficult to define because it means different things in different disciplines. For example, a farmer's concept of soil moisture is different from that of a water resource manager or a weather forecaster. Generally, however, soil moisture is the water present between soil particles — and for the purpose of this article, we will be using soil moisture as simply the amount of water present in a measurement of soil.

Why is measuring soil moisture important? Compared to other components of the water cycle, the volume of soil moisture is small; nonetheless, it is fundamentally important to any hydrological, biological, or biogeochemical process. Soil moisture information is valuable for a wide range of government agencies and private entities concerned with weather and climate, runoff potential and flood control, soil erosion and slope failure, reservoir management, geotechnical engineering, and water quality.

In this guide, you will learn how to build your own home-made soil moisture and temperature sensor. Also included are instructions for your newly collected data to be utilized via Ubidots, an application enablement platform designed to help tinkerers and businesses develop and deploy innovative solutions to environmental obstacles. 

Materials Required 

  • Particle Electron
  • Soil Temperature/Moisture Sensor - SHT10
  • 10K Resistor
  • LED
  • Wires
  • Plastic Protection Case
  • Micro USB cable

To program your device and display the data you must first be registered on the following pages:

Wiring and Casing 

The sensor we will build today is a SHT10 with four data/power wires brought out. With this, any SHT-1X code for a microcontroller will work. The sensor works with 3 or 5V logic. The 1 meter-long cable has four wires: Red = VCC (3-5VDC), Black or Green = Ground, Yellow = Clock, Blue = Data. Don’t forget to connect a 10K resistor from the blue Data line to the VCC in order to receive the sensor's readings.

Follow the table and diagram below to make the correct connections:

Image title

Image title

Image title

Once you have the right connections, assemble in your protection case. Please use your imagination for this step. Below is how our full kit came together.

Image title

Image title

Connect to Particle's IDE

With your case and Particle Electron assembled in the protection case, we need to connect your device to Particle's IDE. Please reference the article below to connect your device if you are not already familiar with Particle's IDE.

Do not miss this step: While working with your Particle IDE, you need to add two libraries


  • SHT1X (1.0.1 or newer). 

Once you have included both libraries you will see something like this...

Image title

Now it is time to start coding.

Copy the code below and paste it into the Particle IDE. Before you paste your code into the Particle IDE, be sure to erase the previous library inclusions (initial codes) so you are working with a blank IDE.

Once you have copied the code, you will need to assign the unique Ubidots TOKEN. If you don't know how to locate your Ubidots TOKEN, please reference this article: How to get your Ubidots TOKEN


Please, reference to this link to get the code if it is not visible in your browser:

// This example is to get the last value of variable from the Ubidots API

// This example is to save multiple variables to the Ubidots API with TCP method

 * Include Libraries

#include "Ubidots.h"
#include <SHT1x.h>
#include <application.h>

 * Define Constants

#ifndef TOKEN
#define TOKEN "Put_your_Ubidots"  // Put here your Ubidots TOKEN

#ifndef DATAPIN
#define DATAPIN D0

#ifndef CLCKPIN
#define CLCKPIN D1

#ifndef LED
#define LED D7

Ubidots ubidots(TOKEN);

 * Auxiliar Functions


 * Main Functions

void setup() {
    pinMode(LED, OUTPUT);
    //ubidots.setDebug(true);  //Uncomment this line for printing debug messages

void loop() {
    float humidity = sht10.readHumidity();
    float temperature = sht10.readTemperatureC();
    ubidots.add("soil-moisture", humidity); 
    ubidots.add("temperature", temperature);
    ubidots.setMethod(TYPE_TCP);  //Set to TCP the way to send data
        // Do something if values were sent properly
        Serial.println("Values sent by the device");
        digitalWrite(LED, HIGH);
    digitalWrite(LED, LOW);

Once you have pasted the code and updated the Ubidots TOKEN line, you must verify this code within the Particle IDE. In the top left corner of our Particle IDE, you will see the following icons. Click the checkmark icon to verify any code.

Image title

Once the code is verified, you will receive a "Code verified! Great work" message in the Particle IDE.

Next, your have to upload the code into your Particle Electron. To do this, choose the flash icon above the checkmark icon. (Be sure that your Electron is plugged into your computer's USB port.)

Image title

Select the "FLASH OTA ANYWAY" to start the upload.

Once the code is uploaded, you will receive a "Flash successful! Your device is being updated - Ready" message in the Particle IDE.

Now your sensor is sending the data to the Ubidots Cloud!

Status LED

The LED will turn ON every time the sensor sends the data to Ubidots.

Data Management in Ubidots 

If your device is correctly connected, you will see a new device created within the device section of your Ubidots application. The name of the device will be "particle". If you open the devices tab, you will see two variables corresponding to your Paricle device: "soil-moisture" and "temperature", each taking readings every 10-12 seconds.

If you want to change your device and variable names to friendlier ones, please reference this article below.


Soil moisture is a key variable in controlling the exchange of water and heat energy between the land surfaces and our atmosphere. As a result, soil moisture plays an important role in the development of weather patterns, agriculture production, or gardening beauty. With this soil moisture and temperature tutorial, you now are in control of your plants environments and can respond when your plants tell you they are thirsty or cold.

Now it is time to create a dashboard for controlling and managing your very own soil moisture and temperature sensor. To learn more about Ubidots widgets and events for optimizing your application, check out these video tutorials.

iot ,sensors ,particle electron ,ubidots cloud

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}