Introduction: Soil Moister With Node

In this manual I will show you how to make a homade soil sensor for the gardenhealth system. I will show you what you need, give some code examples and how to implement the code.

At the end of the instructions you wil know how to change a led strip's color when the soil is wet, a bit wet or dry.

In this manual I will use:

  • Arduino version 1.8.9
  • The Adafruit_NeoPixel.h library


You wil need:

  • NodeMCU 1.0 (ESP-12E module)
  • 1 female to female cable
  • A LED strip
  • (Optional) Homade soil sensor (Watch the video above until 00:36)

Step 1: Setup

  • Take your node and your soil sensor.
  • Connect the soil sensor to A0 .(Photo 1) (alternatively take a stript female cable and connect it to A0 (Photo 3)
  • Take your LED strip and put GND in G, 5V on 3V and the middle cable in D5.(Photo 2)

Now it will look something like the last photo.

Step 2: Adding Code for Soil Sensor

  • Make a new project in arduino IDE
  • Past in the following code:

Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255 and uses the result to set the pulse width modulation (PWM) of an output pin. Also prints the results to the Serial Monitor.

The circuit: - potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground - LED connected from digital pin 9 to ground

created 29 Dec. 2008 modified 9 Apr 2012 by Tom Igoe

This example code is in the public domain. *

/ These constants won't change. They're used to give names to the pins used: const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = D5; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot

void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); }

void loop() { // read the analog in value: sensorValue = analogRead(analogInPin);

// print the results to the Serial Monitor: Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\n"); // Serial.println(outputValue);

// wait 1 milliseconds before the next loop for the analog-to-digital // converter to settle after the last reading: delay(1000); }

Now you can check if your sensor is gives a value.

Touch the end of the screw or the cable and you will see something like photo 1

If it doesn't work check your cables. Are they correctly connected?

Step 3: Neopixel Library

  • Download the adafruit_neopixel library (If you haven't already).
    • Go to tools>manage liberaries
    • search for adafruit neopixel photo 1
    • Install version 1.2.5

Step 4: Neopixel Code Setup

  • Add the following in the top of your project
    • #include
    • #include
    • #include "Adafruit_NeoPixel.h"
  • Below that:

char ssid[] = "SSID"; // your network SSID (name)

char password[] = "password"; // your network password

  • And below that

#define PIXEL_PIN D5
#define PIXEL_COUNT 30 //change to how maney led's are on your strip


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

Step 5: Void Setup

  • Put the following code in the voide setup ()

pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED); // Turn OFF all pixels ASAP

pixels.setBrightness(50); //must be between 0 and 255 if you would like the led strip to be brighter you can increase the number

Step 6: Void Loop

  • In the void loop() and below the delay(1000); enter the following code.

if (sensorValue == 0 || sensorValue <= 200) {

for(int i=0; i

pixels.setPixelColor(i, 255, 0, 0);;


}else if (sensorValue > 200 || sensorValue <= 500) {

for (int i=0; i

pixels.setPixelColor(i, 0, 255, 0);;


} else if (sensorValue > 500) {

for(int i=0; i

pixels.setPixelColor(i, 0, 0, 255);;




Step 7: Check

Congratulations! You just made a system that can indicate if soil is wet or dry.

Now when you put the sensor in wet soil the LED will turn green and when it is in dry soil it will turn red.Like the pictures above.