0

water pump with LCD
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

water pump with LCD

by Pashgen on Thu Nov 16, 2017 11:10 pm

Hi Everyone,

I am building watering system. Trying to show sensor readings on LCD. But no luck so far

Could you please check my code. how can I show soil moisture value on LCD?
I also wonder if I can show in %, for instance - very wet - show 100% on LCD, dry 0%, yeah, something like that


Code: Select all | TOGGLE FULL SIZE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);



int PUMP = 13;
int sensor = 8;
int val;

const int DigitalInPin = 8;
int sensorValue = digitalRead(8);

void setup() {
  pinMode(13,OUTPUT);
  pinMode(8,INPUT);

lcd.init();                      // initialize the lcd
lcd.init();

delay(100);

}

void loop() {
   val = digitalRead(8);
 
  if(val ==LOW)
  {
  digitalWrite(13,LOW);
  }
  else
  {
  digitalWrite(13,HIGH);
  }
  delay(400);


lcd.backlight();
lcd.setCursor(0,0);

lcd.print("Soil Moisture:");
sensorValue = digitalRead(8);
lcd.setCursor(0, 1);
lcd.print(sensorValue);
}

[img][/img]
Attachments
PUMP_ON_1.jpg
PUMP_ON_1.jpg (265.55 KiB) Viewed 169 times

Pashgen
 
Posts: 1
Joined: Thu Nov 16, 2017 10:50 pm

Re: water pump with LCD

by kcl1s on Fri Nov 17, 2017 1:00 am

On this line you have lcd.print(sensorValue); but you only assign a value to sensorValue once in setup so it will never change. You do realize your sensor is digital and only gives 0 or 1 value so displaying % is not possible. You can put lcd.print("Wet"); or lcd.print("Dry"); inside your if/else statement if you want words. Don't forget to add the lcd.setCursor(0, 1); in each.

Otherwise I think you have the basic idea. Keep trying.

Keith

kcl1s
 
Posts: 466
Joined: Tue Aug 30, 2016 12:06 pm

Re: water pump with LCD

by adafruit_support_bill on Fri Nov 17, 2017 6:39 am

Are you sure that you have the sensor connected properly? That looks like an analog sensor, but you are reading like a digital switch, so you will only get values of 0 or 1. Check with the sensor manufacturer for the correct way to connect and read the moisture sensor.

adafruit_support_bill
 
Posts: 63479
Joined: Sat Feb 07, 2009 10:11 am

Re: water pump with LCD

by kcl1s on Fri Nov 17, 2017 7:56 am

Bill,
I thought that too at first then saw the small blue board and Googled for something similar and found this https://www.ebay.com/itm/Soil-Humidity-Moisture-Detection-Digital-Sensor-Module-DC-3-3-5V-E9T7-/122778876038?_trksid=p2385738.m2548.l4275
The description only lists digital out DO but a second look shows an extra pin that the poster is not using. That might be for the raw analog reading.

Pashgen,
What does the documentation for your part say about the 4th unused pin?

Keith

kcl1s
 
Posts: 466
Joined: Tue Aug 30, 2016 12:06 pm

Re: water pump with LCD

by adafruit_support_bill on Fri Nov 17, 2017 10:02 am

OK. Similar in appearance to the Grove analog moisture sensor - but with just a digital output.
https://www.seeedstudio.com/Grove-Moist ... p-955.html

adafruit_support_bill
 
Posts: 63479
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.