|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  AutoIt (Programación) Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  Teleco - Emisora de A.M. Visual Basic Cosas de Windows Webs interesantes
T Búsqueda en este sitio:


.

Arduino en español
Circuitos con Arduino - Juan Antonio Villalpando

-- Tutorial de iniciación a Arduino --

Volver al índice del tutorial

____________________________

49BF.- Teclado 4x4, bus I2C. Pantalla LCD. Sensor de humedad y temperatura. Infrarojo. RadioFrecuencia. Reloj.

- A nuestro proyecto le añadimos un Reloj RTC para visualizarlo en la pantalla LCD cuando pulsemos la tecla "*".

- Nos guiaremos por el tutorial: 48.- Reloj de fecha y hora. RTC DS1307. Bus I2C.

- Funcionamiento:

- Al pulsar la tecla '*' se observará el Reloj en la pantalla LCD.

_______________________
- Teclados y LED.

'A' Modifica la temperatura máxima para encender el LED13 LED13
'B' Visualiza la Humedad en LCD. LED13
'C' Visualiza la Temperatura en LCD. LED13
'#' Fin de entrada de datos para la opción 'A'  
Mando de infrarojo Teclas '1' y '2' del mando de infrarojo. LED7
'D' Distancia ultrasonido por Radio Frecuencia en LCD.  
PulsadorA
PulsadorB
  LED5
LED6
'*' Visualizar la hora en LCD.  

______________________________________________________
- Conexionado.

- He agregado el módulo de Reloj RTC. Este módulo admite conexión por bus I2C.

- Podemos conectarlo a cualquier conexión marcada como SCL y SDA.

______________________________________________________
- Código para el Arduino.

- Además de las librerías vistas anteriormente, debemos cargar esta librería: RTClib

jTeclado_LCD_humedad_ir_rfr_reloj.ino

// Juan A. Villalpando.
// Abril 2018. KIO4.COM
#include <Wire.h>
// Teclado.
#include <Keypad_I2C.h>
#include <Keypad.h>
// Pantalla LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define LED13 13
#define LED7 7
// Sensor humedad-temperatura.
#include <DHT.h> 
#define DHTPIN 2 
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);
// Infrarojo.
#include <IRremote.h>
// Radio Frecuencia.
#include <VirtualWire.h>
const int pin_de_recepcion = 8; // RF
  #define LED5 5
  #define LED6 6
  int distancia;
  int distancia_old;
  boolean radiofrecuen = false;
  // Reloj RTC
#include <RTClib.h>
RTC_DS1307 RTC;
boolean reloj = false;
// Teclado
const byte ROWS = 4; 
const byte COLS = 4;
String maximo = "40";
char key = ' ';
// Humedad Temperatura.
float humedad = 0.0;
float temperatura = 0.0;
float temperatura_old = 0.1;
boolean temperatu = false;
// Infrarojo.
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int tecla;
 
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
 
byte rowPins[ROWS] = {0,1,2,3}; 
byte colPins[COLS] = {4,5,6,7};
 
int i2caddress = 0x38; // Direccion I2C teclado.
 
Keypad_I2C kpd = Keypad_I2C( makeKeymap(keys), rowPins, colPins, ROWS, COLS, i2caddress );
 
void setup(){
  Serial.begin(9600);
  kpd.begin();
  lcd.begin(16,2);// Columnas y filas de LCD
  pinMode(LED13, OUTPUT);
  // Humedad Temperatura.
  dht.begin();
  // Infrarojo.
  pinMode(LED7, OUTPUT);
  irrecv.enableIRIn();
  // Radio Frecuencia.
  // Inicializa IO y ISR
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  ////pinMode(LED3, OUTPUT);
  Serial.println("Recepcion");
   vw_set_rx_pin(pin_de_recepcion);
   vw_setup(2000); // Bits por segundo
   vw_rx_start(); // Comienzo de recepción
   // Reloj RTC
   Wire.begin();
   RTC.begin();
   RTC.adjust(DateTime(__DATE__, __TIME__));
}
 
void loop(){
  infrarojo();
  radiofrecuencia();

  key = kpd.getKey();
  if (key){
      if (key == 'A'){ // Cambiar maximo.
       introduce_maximo();
      }      
      if (key == 'B'){ // Ver humedad.
       ver_humedad();
      }
      if (key == 'C'){ // Ver temperatura.
       temperatu = !temperatu;
       temperatura_old = 99;
       reloj = false;
       radiofrecuen = false;
      }
      if (key == 'D'){ // Ver RadioFrecuencia-Ultrasonido.
       radiofrecuen = !radiofrecuen;
       distancia_old = 123456;
       reloj = false;
       temperatu = false;
      }
      if (key == '*'){ // Ver Reloj RTC.
       reloj = !reloj;
       temperatu = false;
       radiofrecuen = false;
      }
  }
     if (temperatu){ver_temperatura();}
     if (reloj){ver_reloj();} 
     if (radiofrecuen){ver_radiofrecuencia();} 
     if (String(temperatura) >= maximo) {
          digitalWrite(LED13, HIGH);
       } else {
          digitalWrite(LED13, LOW);
      }
      
} // FIN loop.
///////////////////////////////////////////////////
  // Introduccion de datos de maximo.
void introduce_maximo() {
      lcd.clear(); // Borra pantalla
      lcd.setCursor(0,0); // Inicio del cursor
      lcd.print("Valor maximo");
      lcd.setCursor(0,1); // Siguiente renglón.
      lcd.print(maximo);
      maximo = "";
     while (key != '#' )
        {
           key = kpd.getKey(); 
           if (key){
            maximo = maximo + key;
            lcd.clear(); // Borra pantalla
            lcd.setCursor(0,0); // Inicio del cursor
            lcd.print("Valor maximo");
            lcd.setCursor(0,1); // Siguiente renglón.
            lcd.print(maximo);
            delay(100);
            }
        }
  }
///////////////////////////////////////////////////
/////  Ver informacion humedad ///////////////////
void ver_humedad() {
  lcd.clear(); // Borra pantalla
  humedad = dht.readHumidity();
  lcd.setCursor(0,0); // Inicio del cursor
  lcd.print("Humedad");
  lcd.setCursor(0,1); // Siguiente renglón.
  lcd.print(humedad);
  delay(50);
  }
///////////////////////////////////////////////////
/////  Ver informacion temperatura ////////////////
void ver_temperatura() { 
  temperatura = dht.readTemperature();
  if (temperatura != temperatura_old) { // Para que no parpadee.
  temperatura_old = temperatura;
  lcd.clear(); // Borra pantalla
  lcd.setCursor(0,0); // Inicio del cursor
  lcd.print("Temperatura");
  lcd.setCursor(0,1); // Siguiente renglón.
  lcd.print(temperatura);
  delay(50);
  }
}
///////////////////////////////////////////////////
/////  Leer infrarojo ////////////////////////////
void infrarojo() {
  if (irrecv.decode(&results)) {
  Serial.println(results.value, DEC);
  tecla=results.value; // Obtenemos el valor decimal de la tecla pulsada
  //Serial.println(tecla);
  if (tecla==12495){ // Código de la tecla 1 
  digitalWrite(LED7, HIGH);
  }
  if (tecla==6375){ // Código de la tecla 2 
  digitalWrite(LED7, LOW);
  }
  irrecv.resume(); // Receive the next value
  }
  delay(100);
}
///////////////////////////////////////////////////
/////  Leer Radio Frecuencia //////////////////////
  void radiofrecuencia() {
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  if (vw_get_message(buf, &buflen))
  {
  int i;
  // Mensaje en el Monitor Serial
  for (i = 0; i < buflen; i++)
  {
  Serial.print((char) buf[i]); // Salen los 6 caracteres
  Serial.print(' ');
  }
  Serial.println();

//////////////// Los LED
// LED5
  if(buf[0] == '0'){
   digitalWrite(LED5,HIGH);   
  } else {
   digitalWrite(LED5,LOW); 
  }
  // LED6
  if(buf[1] == '0'){
   digitalWrite(LED6,HIGH);   
  } else {
   digitalWrite(LED6,LOW); 
  }

// Obtiene el valor del potenciómetro
   int a, b, c, d;

   a = 1000 * (buf[2] - 48);
   b = 100 * (buf[3] - 48);
   c = 10 * (buf[4] - 48);
   d = 1 * (buf[5] - 48);

   distancia =  a + b + c + d;
   Serial.print("Distancia ultrasonido = "); 
   Serial.println(distancia);
}
} 
///////////////////////////////////////////////////
/////  Ver radiofrecuencia en LCD ////////////////
void ver_radiofrecuencia() {
  if (distancia != distancia_old) { // Para que no parpadee.
    distancia_old = distancia;
  lcd.clear(); // Borra pantalla
  lcd.setCursor(0,0); // Inicio del cursor
  lcd.print("Distancia (RF)");
  lcd.setCursor(0,1); // Siguiente renglón.
  lcd.print(distancia);
  delay(50);
  }
}
///////////////////////////////////////////////////
/////  Ver Reloj RTC en LCD ///////////////////////
void ver_reloj() {
  DateTime now = RTC.now();
  lcd.clear(); // Borra pantalla
  lcd.setCursor(0,0); // Inicio del cursor
  lcd.print(now.day(), DEC);
  lcd.print("/");
  lcd.print(now.month(), DEC);
  lcd.print("/");
  lcd.print(now.year(), DEC);
  lcd.setCursor(0,1); // Siguiente renglón.;
  lcd.print(now.hour(), DEC);
  lcd.print("/");
  lcd.print(now.minute(), DEC);
  lcd.print("/");
  lcd.print(now.second(), DEC);
  delay(200);
}

______________________________________________________
- Comentarios.

- Fíjate en la manera de elegir las opciones.

	   if (key){
      if (key == 'A'){ // Cambiar maximo.
       introduce_maximo();
      }      
      if (key == 'B'){ // Ver humedad.
       ver_humedad();
      }
      if (key == 'C'){ // Ver temperatura.
       temperatu = !temperatu;
       temperatura_old = 99;
       reloj = false;
       radiofrecuen = false;
      }
      if (key == 'D'){ // Ver RadioFrecuencia-Ultrasonido.
       radiofrecuen = !radiofrecuen;
       distancia_old = 123456;
       reloj = false;
       temperatu = false;
      }
      if (key == '*'){ // Ver Reloj RTC.
       reloj = !reloj;
       temperatu = false;
       radiofrecuen = false;
      }
  }
     if (temperatu){ver_temperatura();}
     if (reloj){ver_reloj();} 
     if (radiofrecuen){ver_radiofrecuencia();} 
	  

 

______________________________________________________
______________________________________________________

________________________________

 

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información