top of page

Código del programa en Arduino

/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
int potenciometro = A1;    // select the input pin for the potentiometer
int SenHumedad = A0;
int electrovalvula = 13;      // select the pin for the LED
int PorcentajeC = 0;  // variable to store the value coming from the sensor
int Humedad;
float h; //humedad relativa
float t;  //temperatura del entorno
int pulsador1=7;

//variables para determinar el encendido y apagado del led del lcd
int LCD=8;
int contadorLCD=0;
//-------------------

int pulsadormenuUP=0;
int pulsadormenuDOWN=0;
int contadorpulso=0;
int contraste = 6;           // the PWM pin the LED is attached to
int contrasteLCD = 50;    // how bright the LED is
String electv="";
int decremento=0;


// Incluimos librería
#include <DHT.h>

// Definimos el pin digital donde se conecta el sensor
#define DHTPIN 10
// Dependiendo del tipo de sensor
#define DHTTYPE DHT22
 
// Inicializamos el sensor DHT22
DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() 
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  pinMode(electrovalvula, OUTPUT);
  pinMode(contraste, OUTPUT);
 
  pinMode(pulsador1, INPUT);
  pinMode(LCD, OUTPUT);
  digitalWrite(LCD,LOW);

    // set the brightness of pin 9:
  analogWrite(contraste, contrasteLCD);
   dht.begin();//inicie la lectura del sensor
}

void loop()
{
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  pulsadormenuUP = digitalRead(pulsador1);
  
if (pulsadormenuUP == LOW)
  {
    //Si el pulsador de menú fue oprimido
    contadorpulso++;
    contadorLCD=0;//como se oprimio reinicia la cuenta
   }
   contadorLCD++; //aquí continua la cuenta para saber hasta que momento queda encendido el LCD
 if (contadorpulso >1)
  {
    contadorpulso=0;
  }
  
/////////////////////////////////////////////////
  if (contadorLCD > 60)
  {
    // turn LED off:
    digitalWrite(LCD,LOW);
  }
  else
  {
    // turn LED on:
    digitalWrite(LCD,HIGH);
  }
  
/////////////////////////////////////////////////
  
  PorcentajeC = analogRead(potenciometro);
  Humedad = analogRead(SenHumedad);
  PorcentajeC = map(PorcentajeC, 0, 1023, 0, 100);
  Humedad = map(Humedad, 1023, 260, 0, 100);
  h = dht.readHumidity(); //Se lee la humedad relativa
  t = dht.readTemperature(); //Se lee la temperatura

  if(contadorpulso==0)//el primer menú que muestra la humedad del suelo
  {
    //imprimo la primera fila
    lcd.setCursor(0, 0);
    lcd.print("Hum Suelo:");
    lcd.setCursor(11, 0);
    lcd.print(Humedad);
    lcd.setCursor(13, 0);
    lcd.print("%");
    //imprimo la segunda fila
    lcd.setCursor(0, 1);
    lcd.print("Accion: ");
    lcd.setCursor(8, 1);
    lcd.print(PorcentajeC);
    lcd.setCursor(10, 1);
    lcd.print("%");
    lcd.setCursor(12, 1);
    lcd.print(electv);
   
   }
  if(contadorpulso==1)//el segundo menú que muestra la temperatura y la humedad del medio
  {
    lcd.setCursor(0, 0);
    lcd.print("Temp:");
    lcd.setCursor(6, 0);
    lcd.print(t);
    lcd.setCursor(12, 0);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("Humd:");
    lcd.setCursor(6, 1);
    lcd.print(h);
    lcd.setCursor(12, 1);
    lcd.print("%");
    }
  
   if(Humedad <PorcentajeC)//
   {
      digitalWrite(electrovalvula, LOW);
      electv="ON";
   }
   else
   {
      digitalWrite(electrovalvula, HIGH);
      electv="OFF";      
   }
   delay(200);
   lcd.clear();

}

  • YouTube Social  Icon
  • Facebook Social Icon
  • Twitter Social Icon

Semillero de Investigación conformado por docentes, directivos y estudiantes de la Institución Educativa Rural Ramón Messa Londoño, ubicada en la Vereda Pueblo Rico del municipio de Quimbaya departamento del Quindío, Colombia, que quieren integrar la tecnología al sector agropecuario para fortalecer la producción ecológica y automatizada.

bottom of page