Watering Pump with LCD, Arduino. Need some help with code
Hi,
Building watering unit with LCD, based on Arduino mega.
I couldn't get correct value on LCD.
I want to show current sensor readings.
Could you please help
#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);
}
Comments
3 years ago
If the sensor is the same that Ive used, (it looks the same) there is a pin on the end that you haven't got a wire plugged into which is labeled AO (analog out) thats the pin you need to use.
The DO pin (digital out) will give ether and high or low signal.
Saying all that, my sensor behaved quite strangely, and i lost interest in it, you might have better luck with it.
Try this, you should be able to read the value on the serial monitor. You will have ad code to get it to work on your LCD
int sensor_pin = A0;
int output_value ;
void setup() {
Serial.begin(9600);
Serial.println("Reading From the Sensor ...");
delay(2000);
}
void loop() {
output_value= analogRead(sensor_pin);
output_value = map(output_value,550,0,0,100);
Serial.print("Mositure : ");
Serial.print(output_value);
Serial.println("%");
delay(1000);
}