Περιγραφή
Με τον αισθητήρα DHT11 μετράμε την υγρασία και την θερμοκρασία της ατμόσφαιρας και τυπώνουμε τις τιμές σε οθόνη LCD I2C.
Εξαρτήματα και συνδέσεις
- Arduino Uno
- αισθητήρας DHT11
- οθόνη LCD I2C
Κώδικας
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  
#define DHTPIN 2    
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));
  dht.begin();
  lcd.init();
  lcd.clear();         
  lcd.backlight();
}
void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  // 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;
  }
  Serial.print(F("HUMI: "));
  Serial.print(h);
  Serial.println(F("%"));
  Serial.print(F("TEMP: "));
  Serial.print(t);
  Serial.println(F("°C "));
  lcd.setCursor(0,0); 
  lcd.print(F("TEMP: "));
  lcd.print(t);
  lcd.print(F(" oC"));
  lcd.setCursor(0,1);
  lcd.print(F("HUMI: "));
  lcd.print(h);
  lcd.print(F(" %"));
}


 
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου