DHT11 temperature and humidity sensor with 1602 i2C LCD display - Arduino for beginners
Posted: 25 Jun 2021 19:43
Pentru incepatori, un senzor de temperatura DHT11 si un ecran LCD 1602 cu interfata i2C, conectat la arduino si testat intr-o zi foarte fierbinte de vara.
Schema legaturilor
Codul pe care l-am incarcat pe Arduino Uno
si un scurt video despre cum se construieste si functionarea intr-o zi foarte calduroasa, cu senzorul scos direct la soare.
Schema legaturilor
Codul pe care l-am incarcat pe Arduino Uno
Code: Select all
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
Serial.println(F("Senzor de temperatura si umiditate cu display 1602 cu interfata i2c"));
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Daradici Levente");
lcd.setCursor(2,1);
lcd.print("DHT11 Senzor");
delay(3000);
lcd.clear();
dht.begin();
}
void loop() {
delay(3000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.setCursor(9,0);
lcd.print(t);
lcd.setCursor(14,0);
lcd.print((char)223);
lcd.setCursor(15,0);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Umid:");
lcd.setCursor(9,1);
lcd.print(h);
lcd.setCursor(15,1);
lcd.print("%");
Serial.print(F("Umiditate: "));
Serial.print(h);
Serial.print(F("% Temperatura: "));
Serial.print(t);
Serial.println(F("°C "));
}
si un scurt video despre cum se construieste si functionarea intr-o zi foarte calduroasa, cu senzorul scos direct la soare.