Introduction: Arduino LCD Soil Moisture Sensor

Picture of Arduino LCD Soil Moisture Sensor

What we are going to make is a Arduino moisture sensor with YL-69 sensor which work based on a resistance between the two "blades". It will give us values between 450-1023 so we need to map it to get the percentage value, but we well get to this later. So lets begin.

Step 1: Gathering Parts

Picture of Gathering Parts

You neet to gather:

1. LCD 16x2 (White in my case)

2. Potentiometer 47k Ohm (or smaller, I only had that one, but you can also use 10-20k and it should be just fine)

3. Cables, a lot of cables

4. Prototype board

5. Arduino Uno / Arduino Pro mini (with programmer)

6. Power supply (9V battery for example)

7. Moisture sensor (for ex. YL-69)

Step 2: Connect LCD

Picture of Connect LCD

Connect the LCD with the cables to arduino as it's shown on a shematic. Do not forget the potentiometer.

Step 3: Connect Moisture Sensor

Picture of Connect Moisture Sensor

Connect the moisture sensor board VCC pin to + rail of the prototype board and GND pin to ground. (I connected to the second ground on the arduino board)

Moisture sensor data pin need to be connected to A0 (in case of YL-69 its the last of 4 pins) on arduino board.

Step 4: Code

Picture of Code

// Author: W. Marczak
#include <LiquidCrystal.h>
// include the LCD library
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
// Set pins as 12,11,7,6,5,4. It might be different for your LCD, check the producer catalog
int potPin = A0; //input pin
int soil=0;
void setup() {
lcd.begin(16, 2);
// lcd rows and columns
// title of sorts
void loop() {
// map the values
int soil = analogRead(potPin) ;
soil = constrain(soil, 485, 1023);
soil = map(soil, 485, 1023, 100, 0);
lcd.setCursor(0, 1);
//display final numbers
//print the percent symbol at the end
//wait 0.1 seconds
//wipe the extra characters
lcd.print(" ");

Step 5: Add the Power Supply

Picture of Add the Power Supply

Add the proper power supply (5-9V should be fine) and set the contrast of your LCD with the potentiometer. Also set the potentiometer on the YL-69 moisture sensor if the red light on the small board is not on. What you should get is as its shown on the picture, but instead of Wilgotnosc you ll get "Humidity", as Humidity is wilgnotność in my language. Check if the sensor is working properly with a cup of water.


hassanbinzia98 (author)2017-11-11

Amazing project, but the only problem arsing is that my lcd is not giving any results. connections are checked many times but lcd is giving no output. any suggestions?? just the lcd light is brighten but no result

You might have a different screen, with different pinout. Check the datasheet for your LCD and compare it to the one i had :)

TheDirkKnight (author)2017-09-03

Fantastic Instructable with absolutely straight forward coding! By the way if anyone has an issue with characters of the % sign or in my case I added extra text to define the level of moisture, dry, wet, humid, etc, then you can add this code to "clear" the lcd's bottom line so there are no overlapping characters:


lcd.print(" ");

This will help the lcd to not appear "laggy". I only add this because I noticed that if the % goes from 1% to 90% or 100% back to 1% then the lcd tends to read "1%%".

Again great Instructable!

brandonmufc06 (author)2017-06-10

great project! i have made for my grandmas birthday present.

BrandonR123 (author)2017-04-06

I have made this project and it works brilliantly! Thank you for this

tuner666 (author)2017-03-01

I made this one, but my LCD is shining super bright. Adjusting the pot meter (10K) has the only effect that small white blocks appear, nothing like your pictures.

Connections are checked 5 times, and 3 other times by another person.

Do you have any advice?

WojciechM3 (author)tuner6662017-03-01

Can u attach the picture of your lcd?

thunderjew (author)WojciechM32017-03-16

I also have this problem.

thunderjew (author)thunderjew2017-03-16

Ah, now I got it to work. I moved pin D5 (on the display) to another pin on the breadboard, in the same row, though.

ChristianP109 made it! (author)2016-11-15

Great instructions, really enjoyed this build.

AdamS37 (author)2015-12-30


arduinomaster made it! (author)2015-12-29

WojciechM3 (author)arduinomaster2015-12-29

Great work there! My idea was based on taking short measurments and taking the probe out of the soil and off from the power, since i made it just to standarize the soil moisture for my plants in different conditions of growth (im currently doing a studies of germination of pulsatilla in different "mediums"(soil, sand, both in dark and exposed to fitotrone lamps light). To obtain my goal i need to have more or less the same moisture level of different "mediums". Thanks for improving my idea, you just gave me an idea how to even make it better since a short measurments with plugged moisture sensing device to power might be the trick which i needed to also add a simple water pump which will add some water to the "mediums" if the sensor will give a low values. Also the next idea you gave me is to get a SD card shield and dump the measurments on the SD and make a monthly graphs. So again thanks for the improvments and next ideas:)

arduinomaster (author)2015-12-26

Wait a long time to refresh your display, otherwise you "de galvanise" your probes.

putting constant current through probes is like a chemical or electrochemical delamination process.

If probes are immersed in an aqueous solution (the soil). The metal on the probes dissolve in the electrolytic process.

To make your probes last, keep this process to a minimum.

A longer delay is suggested as the circuit does not need to test every second.

I use galvanised 6 mm thick bolts A2-70 or A4-70 as probes together with the cheap chinese sensor.

If the probes are magnetic, they contain iron and are not of good quality.

5 minutes x60x1000 = 5*60*1000

delay(5*60*1000);// =5 minutes

DIY Hacks and How Tos (author)2015-12-20

I need to make one of these for my indoor plants. A lot of them are pretty sensitive to moisture levels.

For example VH400 from Vegetronix. It main adventage is that it does not corrode over time. However it costs like 20 low cost YL-69's. For most of the plants YL-69 should be good enough, but remember it will corode over time. If your plants arent very sensitive and only pretty sensitive YL-69 should work, but keep it in mind that you might want to change the probe sometime since it will corrode a bit.

Then i also suggest to buy a more expensive moisture sensore, since those cheap chinese ones might not be good enough. Also take a look on the sensors which work is not based on a resistance, since the resistance depends from various of conditions (temp. for ex.) and might not work well enough.

About This Instructable




More by WojciechM3:Soil Moisture Sensor (LCD, RTC, SD Logger, Temperature)Arduino LCD Soil Moisture Sensor
Add instructable to: