#include <LiquidCrystal_I2C.h> // includes the LiquidCrystal Library
#include <dht.h>
#include <Stepper.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
dht DHT;
void setup()
{
lcd.begin(20,4); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
lcd.backlight();
}
void loop()
{
HumTemp();
soilMoisture();
stepperMotor();
}
void soilMoisture()
{
int sensor_pin = A0;
int moisture;
moisture= analogRead(sensor_pin);
moisture = constrain (moisture, 400,1023);
moisture = map(moisture,400,1023,100,0);
lcd.setCursor(0,3);
lcd.print("Soil Moisture: ");
lcd.print(moisture);
lcd.print("% ");
delay(2000);
if ( moisture < 50)
{
stepperMotor();
}
else if (moisture > 80)
{
}
}
void HumTemp()
{
#define dataPin 2
int readData = DHT.read11(dataPin);
int t = DHT.temperature;
int h = DHT.humidity;
lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Temp: "); // Prints string "Temp." on the LCD
lcd.print(t); // Prints the temperature value from the sensor
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(12,1);
lcd.print("Hum: ");
lcd.print(h);
lcd.print("% ");
if (h<50){
stepperMotor();
}
void stepperMotor()
{
// Stepper motor initialization
const int stepsPerRevolution = 48;
Stepper stepper(stepsPerRevolution, 8,9,10,11);
int stepCount = 0;
stepper.setSpeed(60);
stepper.step(stepsPerRevolution);
stepCount++;
}