// https://wokwi.com/projects/397870120127088641
#include <LiquidCrystal.h>
LiquidCrystal lcd( 12, 13, 15, 16, 17, 18);
// RS, E, DB4, DB5, DB6, DB7
void Lcd( float temp, float rh, byte pos );
void Seriell( float temp, float rh, byte pos );
#include "DHT.h"
#define nr_of_DHTs 2
DHT dht[] = {
{4, DHT22}, // DHT dht1(4, DHT22);
{7, DHT22} }; // DHT dht2(7, DHT22); // DHT 22 (AM2302), AM2321 3P
void setup() { // initialize serial interface, LCD + ports:
Serial.begin( 9600 ) ;
lcd.begin( 16,2 ) ;
for( byte i = 0; i < nr_of_DHTs ; i++ ) dht[i].begin(); // 5P
}
void Lcd( float temp, float rh, byte pos )
{ // Temp RH pos = 0 / 1 / 2 / 3
if( pos > 4 ) pos %= 4;
lcd.setCursor( 0,pos );
lcd.print( String(pos)+":" );
lcd.print( temp,1 ) ;
lcd.write( 223 ); lcd.print( "C " );
if( rh < 100 ) lcd.print(" ");
if( rh < 10) lcd.print(" ");
lcd.print( rh,1 ); lcd.print( "% " ); // 10P
}
void Seriell( float temp, float rh, byte pos )
{
Serial.print("DHT"+String(pos)+":" );
Serial.print( temp,1 ) ; Serial.print( "°C \t");
Serial.print( rh,1 ) ; Serial.println( "% "); // 5P
}
void loop() { // ADW + ser.interface + LCD-output of Voltage
static float temp[nr_of_DHTs], old_temp[nr_of_DHTs] = {88,88};
static float humi[nr_of_DHTs], old_humi[nr_of_DHTs] = {-1,-1};
static unsigned long lastTime = 0 ;
if( millis() - lastTime > 1000 )
{
for( byte i = 0; i < nr_of_DHTs; i++ )
{
temp[i] = dht[i].readTemperature();
humi[i] = dht[i].readHumidity();
Lcd( temp[i], humi[i], i);
if( abs( old_temp[i] - temp[i] ) > 2.0 ||
abs( old_humi[i] - humi[i] ) > 2.0)
{ Seriell( temp[i], humi[i], i );
old_temp[i] = temp[i] ;
old_humi[i] = humi[i] ;
}
}
lastTime = millis(); // 17P
}
}