Arduino LCD Soil Moisture Sensor

23,665

38

24

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

  • Optics Contest

    Optics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Plastics Contest

    Plastics Contest

24 Discussions

0
None
MarinS11

7 months ago

Me again, sorry. I made the I2C work now but my main issue is that the YL-69 sensor shows 100% all the time and every second the numbers go from 100 to around 60. But when I take the sensor into my hand and cover it, the sensor reads 0% and when I let it it goes to 100% again. What is wrong here?

4 replies
0
None
WojciechM3MarinS11

Reply 7 months ago

The error is in the coding part in the values calculating section (values mapping). As you see when the moisture is 0 it reads the full resistance of 1023 (or something like that) and calculates it to percentage value of 100% instead of 0%.
the values should be like this :
when moisture is 0% the resistance is 1023. when it i 100% resistance should be at minimal number (around 200 as i remember, you need to check that). In your case it is the oppsite way, when its 100% its 1023 and when it calculates some value it drops from 100% instead increasing from 0%. I dont know if this answer is clear enough if its not please copy me the part of your code in the section of calculating and presenting values.

0
None
MarinS11WojciechM3

Reply 7 months ago

I'm not really the best in arduino coding so this is the code:

void loop() {

int soil = analogRead(potPin) ;

soil = constrain(soil, 485, 1023);

soil = map(soil, 485, 1023, 100, 0);

lcd.setCursor(0, 1);

lcd.print(soil);

lcd.print("%");

delay(999); //I wrote 999 because the numbers were too fast to catch

lcd.print(" ");

delay(0);

}

Thanks in advance!

0
None
MarinS11

7 months ago

Hello again. Because I blindly got a 16x2 display, same like yours, but mine came with a I2C module soldered to the LCD, how am I able to connect it with the arduino uno because the LCD has only 4 pins now instead of 16. Thanks in advance

1 reply
0
None
WojciechM3MarinS11

Reply 7 months ago

Check out the datasheet of your module, also take a look on

0
None
MarinS11

7 months ago

Hello, am I able to use a 50K ohm pot? It's the currently only one I have, thanks in advance

2 replies
0
None
WojciechM3MarinS11

Reply 7 months ago

Absoltly YES, but remember to go down from 50k resistance to desired value not the oposite way. Set the value of potentiometer to 50k with a screwdriver, check the resistance to see if its 50k and go down to the point of interest. This should prevent pushing too much current thru the potentiometer. I belive arduino current value are save for the screen, but you newer know until you check it (and possibly burn the lcd in the process).

0
None
hassanbinzia98

11 months ago

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

1 reply
0
None
WojciechM3hassanbinzia98

Reply 11 months ago

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

0
None
TheDirkKnight

1 year ago

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!

0
None
brandonmufc06

1 year ago

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

0
None
BrandonR123

1 year ago

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

0
None
tuner666

1 year ago

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?

3 replies
0
None
thunderjewthunderjew

Reply 1 year ago

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.

0
None
AdamS37

2 years ago

Polak!!!!!