Buenas tardes,
Me gustaria recibir ayuda con el siguiente problema, estoy haciendo un programa para un invernadero, el cual debe encender una bomba cuando la humedad este por debajo del 50% y apagarla cuando sea mayor al 50 % o hayan transcurrido 2 minutos, la ayuda que necesito es con el tiempo ya que no se como hacerlo
#include <TimerOne.h>
#include <LiquidCrystal.h>
#include <DHT.h>
unsigned long time;
unsigned long t=0;
int Dt;
volatile long int Time=0;
LiquidCrystal lcd (7, 6, 5, 4, 3, 2);
#define Bomba 1
#define DHTPIN A0
#define DHTTYPE DHT11 //DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
lcd.setCursor(1, 0);
lcd.print("RIEGO INVERNADERO");
pinMode(Bomba, OUTPUT);
dht.begin();
//Timer1.initialize(1000000); //Configura el TIMER en 1 Segundo
//Timer1.attachInterrupt(loop); //Configura la interrupción del Timer 1
}
void loop() {
int temp= dht.readTemperature();
int humedad = dht.readHumidity();
lcd.setCursor(0, 1);
lcd.print(">");
delay(100);
time = millis();
t=0;
if(humedad<50 && time - t< 10000 ){
digitalWrite(Bomba, HIGH);
delay(100);
}
else {
digitalWrite(Bomba, LOW);
}
//Time++;
if (humedad>50 || time - t> 10000){
//if (humedad>50 ||Time > 10) {
digitalWrite(Bomba, LOW);
delay (100);
// t = 0;
}
loop;
// if(humedad>50){
// digitalWrite(Bomba, LOW);
//delay (100);
//}
//apagar();
//if(humedad<=50){
// delay (10000);
// digitalWrite(Bomba, LOW);
// delay (10000);
//if(time - t> 10000){
//delay (10000);
//digitalWrite(Bomba, LOW);
//delay (100);
// time = millis();
//loop;
//if(time - t > Dt){
//Muestra en el LCD el valor actual de la humedad
lcd.setCursor(1, 1);
lcd.print("HUMEDAD: "+String(humedad)+" %");
lcd.setCursor(0, 1);
lcd.print(" ");
delay(80);
}
//void Temporizador(void)
//{
//Incrementa el timer
// Time++;
//Resetea el contador cuando llega a 1000 segundos
//if(Time>10){
// digitalWrite(Bomba, LOW);
//}
// Time = ;
//}
//void apagar()
Muchas gracias por la ayuda que me puedan brindar