#include<LiquidCrystal.h>//initializevariablesforsensorpinsintmoistPin=0;inttempPin=1;intlightPin=2;//initializevariablestostorereadingsfromsensorsintmoistVal=0;inttempVal=0;intlightVal=0;//initializevariablesforLEDpinsintredPin=11;intgreenPin=10;intbluePin=9;intwaterPump=13;//initializethelibrarywiththenumbersoftheinterfacepinsLiquidCrystallcd(7,6,5,4,3,2);voidsetup(){//initializetheserialportSerial.begin(9600);//setLEDpinstooutputmodepinMode(redPin,OUTPUT);pinMode(greenPin,OUTPUT);pinMode(bluePin,OUTPUT);pinMode(waterPump,OUTPUT);//setLEDpinstooffdigitalWrite(redPin,LOW);digitalWrite(greenPin,LOW);digitalWrite(bluePin,LOW);//setuptheLCD'snumberofcolumnsandrows:lcd.begin(16,2);}voidloop(){inthumidityRaw=analogRead(A0);//1023to0===>0to100%inthumidityReal=map(humidityRaw,1023,0,0,100);//displaymoisturereadingonlcdlcd.clear();lcd.print("moisture % ");
lcd.print(humidityReal);
Serial.println(humidityReal);
delay(100);
if (humidityReal < 60)
{
digitalWrite(waterPump, HIGH);
}else{
digitalWrite(waterPump, LOW);
}
//turn on LED to blue, others off if moisture pins are touching together
if (humidityReal > 60)
{
blue();
}
else
{
off();
}
//wait 4 seconds
delay(4000);
//display moisture reading on lcd
tempVal = analogRead(tempPin);
float mv = ( tempVal/1024.0)*5000;
float cel = mv/10;
float farh = (cel*9)/5 + 32;
lcd.clear();
lcd.print("temperature ");
lcd.print(cel);
if (cel >29)
{
red();
}
else
{
off();
}
delay(4000);
lightVal = analogRead(lightPin);
//display moisture reading on lcd
lcd.clear();
lcd.print("light ");
lcd.print(lightVal);
//turn on green if light sensor reads 600 or brighter
if (lightVal > 20)
{
green();
}
else
{
off();
}
delay(4000);
}
void blue()
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin,HIGH);
}
void red()
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
void green()
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
}
void off()
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
void on()
{
digitalWrite(redPin,HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
}