Arduino LCD Soil Moisture Sensor

19,721

38

20

Posted

Introduction: 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

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

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

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

// 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
lcd.print("Humidity");
// title of sorts
Serial.begin(9600);
}
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
lcd.print(soil);
//print the percent symbol at the end
lcd.print("%");
//wait 0.1 seconds
delay(75);
//wipe the extra characters
lcd.print(" ");
delay(1);
}

Step 5: 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.

3 People Made This Project!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Gluten Free Challenge

    Gluten Free Challenge
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

14 Comments

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

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

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.setCursor(0,1);

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!

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

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

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?

Can u attach the picture of your lcd?

I also have this problem.

20170316_171409.jpg

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.