#include <Wire.h> //Library for using I2C
#include <LiquidCrystal_I2C.h> //Library for using I2C type LCD display
#include <DHT.h> //Library for using DHT sensor
#define DHTPIN PA1
#define DHTTYPE DHT22
LiquidCrystal_I2C lcd(0x3F,16,2); //initilize object lcd for class LiquidCrystal_I2C with I2C address of 0x27 and 16x2 type LCD display
DHT dht(DHTPIN, DHTTYPE); //initilize object dht for class DHT with DHT pin with STM32 and DHT type as DHT11
void setup()
{ Wire.begin();
// initialize the LCD
lcd.init();
dht.begin(); //Begins to receive Temperature and humidity values.
lcd.backlight(); // Turn on the blacklight and print a welcome message.
lcd.setCursor(0,0);
lcd.print("CIRCUIT DIGEST");
lcd.setCursor(0,1);
lcd.print("DHT11 with STM32");
delay(3000);
lcd.clear();
}
void loop()
{
float h = dht.readHumidity(); //Gets Humidity value
float t = dht.readTemperature(); //Gets Temperature value
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" C");
Serial.print("Humidity: ");
Serial.print(h);
Serial.println(" %");
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Humid: ");
lcd.print(h);
lcd.print(" %");
}