#include <LiquidCrystal.h>
#include <Wire.h>
int pir = 7;
int pirState = LOW;
int data = 0;
int moistureSoil = 0;
//const int Death = 590;
const int Dry = 550;
//const int Ok = 480;
const int Wet = 380;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte w[] = {
B01010,
B10101,
B10101,
B10001,
B10001,
B10001,
B10001,
B10001
};
byte a[] = {
B11110,
B10001,
B11110,
B10000,
B01110,
B00000,
B00000,
B00000
};
byte t[] = {
B01100,
B10010,
B00010,
B00010,
B00111,
B00010,
B00010,
B00000
};
byte e[] = {
B01110,
B00001,
B11111,
B10001,
B01110,
B00000,
B00000,
B00000
};
byte r[] = {
B00001,
B00001,
B00001,
B10011,
B01101,
B00000,
B00000,
B00000
};
byte dry[] = {
B00000,
B01110,
B11111,
B10001,
B10001,
B01010,
B00100,
B00000
};
byte ok[] = {
B00000,
B01110,
B11111,
B11111,
B10001,
B01010,
B00100,
B00000
};
byte wet[] = {
B00000,
B01110,
B11111,
B11111,
B11111,
B01110,
B00100,
B00000
};
void setup() {
// put your setup code here, to run once:
pinMode(pir, INPUT);
Serial.begin (9600);
lcd.begin(20, 4);
lcd.createChar(0, w);
lcd.createChar(1, a);
lcd.createChar(2, t);
lcd.createChar(3, e);
lcd.createChar(4, r);
lcd.createChar(5, dry);
lcd.createChar(6, ok);
lcd.createChar(7, wet);
lcd.home();
}
void loop() {
// put your main code here, to run repeatedly:
data = digitalRead(pir);
Serial.println(data);
if (data == HIGH)
{
lcd.setCursor(7,1);
lcd.print("IH");
delay(2000);
lcd.clear();
moistureSoil = analogRead (A0);
Serial.println (moistureSoil);
if ( moistureSoil < Wet ) { // If sensor is less than Wet
Serial.println("Greater than71% : Overwatering, enough water");
lcd.setCursor(12, 2);
lcd.write((byte)0);
lcd.setCursor(11, 2);
lcd.write((byte)1);
lcd.setCursor(10, 2);
lcd.write((byte)2);
lcd.setCursor(9, 2);
lcd.write((byte)3);
lcd.setCursor(8, 2);
lcd.write((byte)4);
lcd.setCursor(7, 2);
lcd.write((byte)7);
delay (3000);
lcd.clear();
} else if( Dry > moistureSoil){ /// If sensor is greater than Wet and less than Dry (semidry)
//moist
Serial.println("Between 31% to 70% : Just right");
lcd.setCursor(12, 2);
lcd.write((byte)0);
lcd.setCursor(11, 2);
lcd.write((byte)1);
lcd.setCursor(10, 2);
lcd.write((byte)2);
lcd.setCursor(9, 2);
lcd.write((byte)3);
lcd.setCursor(8, 2);
lcd.write((byte)4);
lcd.setCursor(7, 2);
lcd.write((byte)6);
delay (3000);
lcd.clear();
}
else if( moistureSoil > Dry){ /// If sensor is greater than Wet and greater than dry
//water
Serial.println("Between 0% to 30% : Thirsty, add water");
lcd.setCursor(12, 2);
lcd.write((byte)0);
lcd.setCursor(11, 2);
lcd.write((byte)1);
lcd.setCursor(10, 2);
lcd.write((byte)2);
lcd.setCursor(9, 2);
lcd.write((byte)3);
lcd.setCursor(8, 2);
lcd.write((byte)4);
lcd.setCursor(7, 2);
lcd.write((byte)5);
delay (3000);
lcd.clear();
}
else
{
delay(800);
lcd.clear();
}
}else
{
Serial.print("BYE");
lcd.clear();
//delay(1000);
}
/*
if ( moistureSoil >= Dry ) {
delay (2000);
Serial.println("Between 0% to 30% : Thirsty, add water");
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
}else if ( Wet>= moistureSoil >= Ok){
delay (2000);
Serial.println("Between 31% to 70% : Just right");
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
}else{
delay (2000);
Serial.println("Greater than71% : Overwatering, enough water");
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
}
*/
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.