Demo entry 6358806

Arduino

   

Submitted by Eduardo on Apr 26, 2017 at 19:13
Language: C++. Code size: 2.2 kB.

#include <Wire.h>

#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
#include <DHT11.h>

byte dir = 0x27;   // Ese 0x significa que es hexadecimal, no decimal
LiquidCrystal_I2C lcd(dir, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

int hTreshold, hum, valv;
float temp, ambHum;
unsigned long time;
int botonA, botonB;
int riegoTime;
int sensorT = 1;
DHT11 dht11(sensorT);
void setup() {
  
  //Config inicial de temp y humedad:
  hTreshold = 50;
  riegoTime = 1;
  
  //Configuramos botones y actuadores.
  botonA = 10;
  botonB = 11;
  valv = 3;
  pinMode(botonA, INPUT);
  pinMode(botonB, INPUT);
  pinMode(valv, OUTPUT);

  //Iinicio LCD:
  lcd.begin (16,2);    // Inicializar el display con 16 caraceres 2 lineas
  lcd.setBacklightPin(3,POSITIVE);
  lcd.setBacklight(HIGH);          
  //Mostramos el dialogo de configurar.
  showConfigure();
  time = millis();
  // put your setup code here, to run once:
  do{
    //┬┐El boton esta pulsado?
    if(digitalRead(botonA)){
      configure();
      break;
    }
  } while(millis()< (time + 2000));
}

void loop() {
  if(evaluate())
  {
    regar();
    delay(2000);
  }
}

void configure(){
    
}

bool evaluate(){
  int err;
  if((err = dht11.read(ambHum, temp)) != 0)    // Si devuelve 0 es que ha leido bien
  {
    return false;
  }
  hum = analogRead(A0)/10; //Aproximacion a porcentaje
  showStatus(temp, hum);
  if(hum < hTreshold){
    return true;    
  }
  else
    return false;
}

void regar(){
   digitalWrite(valv, HIGH);
   delay(riegoTime*1);
   digitalWrite(valv, LOW);
};

void showConfigure(){
  //Show config init
  lcd.clear();
  lcd.home ();                   // go home
  lcd.print("Pulse Boton A");
  lcd.setCursor ( 0, 1 );        // go to the 2nd line
  lcd.print("Para configurara");
}

void showStatus(float T, int H){
  char bufferT[16];
  char bufferH[16];
  sprintf(bufferT, "T=%f", T);
  sprintf(bufferH, "H=%d", H);
  //Show config init
  lcd.clear();
  lcd.home ();                   // go home
  lcd.print(bufferT);
  lcd.setCursor ( 0, 1 );        // go to the 2nd line
  lcd.print(bufferH);
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).