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.

Arduino All The Things! Contest

Participated in the
Arduino All The Things! Contest

Indoor Gardening Contest 2015

Participated in the
Indoor Gardening Contest 2015