(Arduino) Mostrar Temperatura Y Humedad En OPEN SMART Rich Shield

Hola estimado lector, en el tutorial de hoy voy a hablar de un tema interesante si te has comprado un Rich Shield, y es que comprar una de estas placas, en las diferentes plataformas como Ali Express o Wish, puede darte mucho juego, ya que generalmente son placas con funciones muy bien definidas, y que nos permiten hacer mini proyectos, con pocos conocimientos técnicos.

En el día de hoy les traigo el siguiente ejercicio, que muestre en la pantalla de nuestra OPEN SMART, la temperatura, para ello también encendemos el LED rojo, y sino encendemos el LED azul con humedad. Es un código bastante sencillo, teniendo en cuenta que prácticamente el 90% del código nos lo ofrece el fabricante en sus librerías.

Tabla de contenidos

Materiales:

Rich Shield de OPEN SMART AliExpress.com Product – Starter kit Rich Shield with Infrared Receiver LED Buzzer Button DHT11 Light Sensor Temperature Sensor Module for Arduino UNO R3
Arduino UNO AliExpress.com Product – high quality One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 (NO USB CABLE)

Código:

En un principio sólo necesitamos el Arduino IDE configurado con las librerías del fabricante, y poco más, necesitamos saber que la librería «RichShieldLED.h» hay que declararla, y que los diferentes LED de la placa también, sin más aquí dejo el resultado.

Por aquí dejo el código resultante de este esperimento, espero que os haya gustado, que lo estudiéis y nada sin más nos vemos, hasta la próxima, chao.

#include <Wire.h>

#include «RichShieldDHT.h»
#include «RichShieldTM1637.h»
#define CLK 10//CLK of the TM1637 IC connect to D10 of OPEN-SMART UNO R3
#define DIO 11//DIO of the TM1637 IC connect to D11 of OPEN-SMART UNO R3
TM1637 disp(CLK,DIO);
#include «RichShieldLED.h»

#define LED1 7
#define LED2 6
#define LED3 5
#define LED4 4
LED led(LED1,LED2,LED3,LED4);

DHT dht;

void setup() {
disp.init();  
dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    displayError();
  } 
  else{
    led.off(2);
    displayTemperature((int8_t)t);//
    led.on(4);
    delay(3000);
    led.off(4);
    led.on(2);
    displayHumidity((int8_t)h);//
    
    delay(2000);
  }
}
/************************************************* *********************/
/* Function: Display temperature on 4-digit digital tube */
/* Parameter: -int8_t temperature, temperature range is -40 ~ 125 degrees celsius */
/* Return Value: void */

void displayTemperature(int8_t temperature)
{
  int8_t temp[4];
  if(temperature < 0)
{
temp[0] = INDEX_NEGATIVE_SIGN;
temperature = abs(temperature);
}
else if(temperature < 100)temp[0] = INDEX_BLANK;
else temp[0] = temperature/100;
temperature %= 100;
temp[1] = temperature / 10;
temp[2] = temperature % 10;
temp[3] = 12;           //index of ‘C’ for celsius degree symbol.
disp.display(temp);
}

void displayHumidity(int8_t humi)
{
  int8_t temp[4];
  if(humi < 100)temp[0] = INDEX_BLANK;
  else temp[0] = humi/100;
  humi %= 100;
  temp[1] = humi / 10;
  temp[2] = humi % 10;
  temp[3] = 18;           //index of ‘H’ for celsius degree symbol.
  disp.display(temp);
}

void displayError()
{
  disp.display(3,14);//display «E»
}

2 comentarios en «(Arduino) Mostrar Temperatura Y Humedad En OPEN SMART Rich Shield»

Deja un comentario

Información básica sobre protección de datos Ver más

  • Responsable: Tomas Gonzalez.
  • Finalidad:  Moderar los comentarios.
  • Legitimación:  Por consentimiento del interesado.
  • Destinatarios y encargados de tratamiento:  No se ceden o comunican datos a terceros para prestar este servicio.
  • Derechos: Acceder, rectificar y suprimir los datos.
  • Información Adicional: Puede consultar la información detallada en la Política de Privacidad.

error: Content is protected !!

Descubre más desde InfoGonzalez - Blog de formador e informático

Suscríbete ahora para seguir leyendo y obtener acceso al archivo completo.

Seguir leyendo

Este sitio web utiliza cookies, si necesitas más información puedes visitar nuestra política de privacidad    Ver
Privacidad
Creative Commons License
Except where otherwise noted, the content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.