#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 4, 5, 18, 19);
const int DHT_PIN = 15;
DHTesp dhtSensor;
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
int Temperaturevalue = 0;
int Humidity = 0;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// Print a message to the LCD.
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("SMART IRRIGATION");
lcd.setCursor(0,1);
lcd.print("SYSTEM");
Serial.begin(9600);
delay(2000);
lcd.clear();
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
float Temperaturevalue = data.temperature;
float Humidity = data.humidity;
Serial.println(Temperaturevalue);
Serial.println(Humidity);
if (Temperaturevalue <= 30 || Humidity >= 200 ) {
lcd.setCursor(0,0);
lcd.print("Tem=");
lcd.print(Temperaturevalue);
lcd.print("Mos=");
lcd.print(Humidity);
lcd.setCursor(0,1);
lcd.print("PUMP STATUS:OFF ");
}
else if (Temperaturevalue > 30 || Humidity < 200) {
lcd.setCursor(0,0);
lcd.print("Temp=");
lcd.print(Temperaturevalue);
lcd.print("Mos=");
lcd.print(Humidity);
lcd.setCursor(0,1);
lcd.print("PUMP Status:ON ");
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
delay(750); // Delay a little bit to improve simulation performance
int16_t i = analogRead(34);
String msg = i < 2165 ? "WET" : i > 3135 ? "DRY" : "OK";
lcd.clear();
lcd.print("Soil: ");
lcd.print(msg);
delay(750);
}