#include <Stepper.h>
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int stepsPerRevolution = 2052;
Stepper myStepper(stepsPerRevolution, 6, 8, 7, 9);
int relaywaterpump = 13;
int humiditysensor=0;
int humidityreal=0;
int photo=0;
int luce=0;
int mem1=0;
void setup() {
pinMode( relaywaterpump,OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
dht.begin();
myStepper.setSpeed(10);
}
void loop() {
humiditysensor=analogRead(A1);
humidityreal= map(humiditysensor, 1023,0,0,100); // map the value to have they in %
float T = dht.readTemperature();
photo=analogRead(A0);
luce= map(photo, 1023,0,0,200);// map the value to have they in %
delay(200);
lcd.setCursor(8, 1);// write the valor in lcd
lcd.print("Luce:");
lcd.print(luce);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Um:");
lcd.print(humidityreal);
lcd.print("%");
lcd.setCursor(2, 0);
lcd.print("Temp:");
lcd.print(T);
lcd.print(" C");
delay(300);
if(humidityreal <= 50){ // if the humidity is low turn on the pump
digitalWrite(relaywaterpump, HIGH);
delay(500);
}
else { // if the humidity is high turn off the pump
digitalWrite(relaywaterpump, LOW);
delay(500);
}
if (luce>=40 && mem1==0){// if the light is high and the memory=0 turn on the stepper motor
myStepper.step(stepsPerRevolution);
mem1=1;
delay(500);
}
if(luce<40 && mem1==1){// if the light is low and the memory=1 turn the stepper motor upside down
myStepper.step(-stepsPerRevolution);
mem1=0;
delay(500);
}
}
Comments