Facebook icon

How To Create Your Very Own Soil Moisture Sensor

July 30, 2021
Dying houseplants are a thing of the past with this soil moisture sensor hack. In this guide, we’ll show you how to create a very simple moisture sensor for measuring soil moisture content. This can be used to monitor real-time volumetric water content in your houseplant soil so you know when to water it to keep it at the optimum moisture level. This soil moisture sensor uses the Ynvisble Display Kit and Arduino Nano. Read on to learn how to do it yourself.

REQUIRED HARDWARE

To make the soil moisture sensor, you’ll need the following:

  1. Ynvisible 1x7 bar display (buy here)
  1. Ynvisible Display Driver (buy here)
  1. Arduino Nano or similar (buy here)
  1. DFROBOT Capacitive Soil Moisture Sensor V1.0 (buy here)
  1. 2x CR2032 Batteries
  1. CR2032 2x Battery holder
  1. 4 pin IDC 90° Adapter
  1. 3 pin IDC 90° Adapter
  1. Jumper Wires

REQUIRED SOFTWARE

CONNECTING THE COMPONENTS

Follow these simple steps to build your own soil moisture sensor:

  1. Connect the Arduino to the breadboard  
  1. Connect the Ynvisible driver to the breadboard by using the 4 pin 90° IDC adapter
  1. Connect the bar display to the driver (The leftmost display electrode must be connected to the leftmost electrode in the connector).
  1. Connect the DFROBOT Capacitive Soil Moisture Sensor V1.0 to the breadboard by using the 3 pin 90° IDC adapter
  1. Connections that need to be made using jumper wires:
  1. 5V from Arduino to VCC on the driver and to + on the moisture sensor
  1. GND from Arduino to GND on the driver and to – on the moisture sensor
  1. SDA from the driver to pin A4 on the Arduino
  1. SCL from the driver to pin A5 to the Arduino
  1. Pin A from the sensor to pin A2 on the Arduino
  1. Connect the Power supply + to the Arduino VI pin and the – to the GND

PROGRAMMING THE ARDUINO

Follow these steps to program the Arduino for your soil moisture sensor:

ADD THE LIBRARY TO THE ARDUINO IDE

  1. Install and open Arduino IDE
  1. Click "Sketch"/"Include Library"/"Add .ZIP Library..." in the main menu
  1. Go to your downloads folder and choose Ynvisible_Driver_4.2-1.0.0.zip

UPLOAD THE CODE TO ARDUINO

  1. Connect the Arduino to your computer with a USB cable
  1. Create a new file in the Arduino IDE
  1. Replace the code in the editor with the code below:


#include <Ynvisible_Driver_4.2-1.0.0.h>



int i2c_address = 43;         //The i2c address of driver board 4.1
int number_of_segments = 7;  //Number of segments on display (1-15)

 

const int analogInPin = A2;   // Analog input pin 
int sensorValue = 0;          // Value read from the moisture sensor
int barValue = 0;             // Output value for the bar display sensor

 

YNV_ECD ECD(i2c_address, number_of_segments); //Initialize ECD Object

 

void setup() {
}

 

void loop() {
  sensorValue = analogRead(analogInPin); // Read the value from the moisture sensor
  barValue = map(sensorValue, 350, 850, 7, 0); // Mapping the value from the moisture sensor on a range from 0 to 7

 

  ECD.setBar(barValue); //Set the display with the output value mapped from 0 to 7  
  delay(3000); //3 seconds delay between each update

}       

	

  1. Click "upload" (the right arrow on the upper left in the Arduino IDE)
  1. Congratulations you now have a functional moisture sensor. You can now add your soil sensor to your plant to begin monitoring the water content of the soil - and how happy it is!

FEEL FREE TO CHANGE THINGS UP

Now you have your own soil moisture sensor, you have everything at your fingertips to start exploring the code and making changes to the hardware to turn your ideas into prototypes. You could try switching up the display from the Ynvisible Display kit and change the moisture sensor to a light sensor, for example. The sky is your limit.

Check out Ynvisible University for more inspiration and how-tos.  

Check out the latest news

Press releases, success stories, and educational content from Ynvisible University.

Learn more