Ir al contenido principal

Estación Meteorologica con integrado Amtel ATmega 328P-PU (4-4)

Sketch de programación AMTEL328P-PU

 

/* Circuito de valores de  temperatura y Humedad DHT-11 y segunda medida temperatura por termistor en display LCD 16,2, refresco pantalla cada segundo (Blink).  

 * El esquema eléctrico es el usado por ELEGOO tanto de termistor, DHT-11 y Display 16,2

 * El resto de modificaciones y adaptación del código han sido realizadas

 *     by Walter L.Campoamor Stursberg (2021).

  */

 

#include <LiquidCrystal.h> // incluimos la librería LCD

#include <dht_nonblocking.h> // incluimos la librería sensor de humedad y temperatura

#define DHT_SENSOR_TYPE DHT_TYPE_11 // define el sensor DHT-11

static const int DHT_SENSOR_PIN = 2; // declara el PIN 2 Digital como entero constante estática

int tempPin = 0; //  PIN A0 analogico para lectura termistor

 

//                BS  E  D4 D5  D6 D7

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //

DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

void setup()

{

  pinMode(LED_BUILTIN, OUTPUT); // declaro Pin 13 como salida

  lcd.begin(16, 2); // declaro filas y columnas del display instalado

}

/*

 * Poll for a measurement, keeping the state machine alive.  Returns

 * true if a measurement is available.

 */

static bool measure_environment( float *temperature, float *humidity ) 

  {

  static unsigned long measurement_timestamp = millis( );

  /* Measure once every four seconds. */

  if( millis( ) - measurement_timestamp > 3000ul )

  {

    if( dht_sensor.measure( temperature, humidity ) == true )

    {

      measurement_timestamp = millis( );

      return( true );

    }

  }

  return( false );

}

 

void loop()

{

 

   float temperature;

int tempReading = analogRead(tempPin);

  // This is OK

  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));

  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK );       //  Temp Kelvin

  float tempC = tempK - 273.15;            // Convert Kelvin to Celcius

  float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit

 

 

  /* Measure temperature and humidity.  If the functions returns

     true, then a measurement is available. */

    

  if( measure_environment( &temperature, &humidity ) == true )

  {

 

  /* Seccion DHT-11 */

       lcd.setCursor(0, 0);

        lcd.print( temperature, 1 );

    lcd.print(" C");

    lcd.setCursor(8, 0);

        lcd.print( humidity, 1 );

    lcd.println( "%   " );

  

   /* Sección termistor */

        lcd.setCursor(0, 1);

    lcd.print("Temp         C  ");

    lcd.setCursor(6, 1);

    lcd.print(tempC);

 

    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

delay(500);

    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

    delay(500);

  }

 

}

/* Fin del codigo fuente*/

Comentarios