When I put my soil moisture sensor on the soil it states 900% + or around 130% in the LCD. How do I make it to 100%. When I take out of the soil it states -10% and how do I make it to 0%.
Or maybe I have to change the sensorvalue?
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//int ACWATERPUMP = 13;
//int relay1 = 8;
//int DigitalSensor; .
int sensorpin = A0;
int sensorvalue = 0;
int percent = 0;
void setup() {
pinMode(13,OUTPUT);
pinMode(8,INPUT);
//pinMode(A0,INPUT);
lcd.begin(20, 4);
lcd.clear();
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print("Smart Pot");
delay(1000);
lcd.setCursor(0,1);
lcd.print("Soil Moisture Sensor");
delay(1000);
lcd.setCursor(0,2);
lcd.print("Motor");
}
void loop() {
float sensor_percentage;
int sensor_analog;
sensorvalue = analogRead(sensorpin);
//percent = analogRead(sensorvalue);
// lcd.print = ValuesToSerial();
lcd.setCursor(0,3);
delay(1000);
//percent = map(sensorvalue, 0, 4095, 0, 100);
percent = map(sensorvalue, 200, 680, 100, 0);
lcd.print(percent);
lcd.setCursor(3,3);
lcd.print("%");
lcd.setCursor(5,3);
lcd.print("Moisture");
if(percent < 50)
{
digitalWrite(13,LOW); //if soil moisture sensor provides LOW value send LOW value to relay
}
else
{
digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to relay
}
delay(400); //Wait for few second and then continue the loop.
}