Arduino - Temperatuur- en Vochtigheidssensor - LCD

We leren hoe u:

Hardware Benodigd

1×Arduino Uno R3
1×USB 2.0-kabel type A/B
1×LCD I2C
1×DHT11 Temperatuur- en Vochtigheidssensor Module
1×Jumper Draden

U kunt de DHT22 sensor gebruiken in plaats van de DHT11 sensor.

1×(Aanbevolen) Schroefklem Block Shield voor Arduino Uno
1×(Aanbevolen) Breadboard-Shield voor Arduino Uno
1×(Aanbevolen) Behuizing voor Arduino Uno
1×(Aanbevolen) Prototyping Basisplaat & Breadboard Kit voor Arduino Uno

Of u kunt de volgende kits kopen:

1×DIYables Sensorkit (30 sensoren/displays)
1×DIYables Sensorkit (18 sensoren/displays)
Openbaarmaking: Sommige van de links in deze sectie zijn Amazon-affiliate links. We kunnen een commissie ontvangen voor aankopen die via deze links worden gedaan, zonder extra kosten voor u. We waarderen uw steun.

Over DHT11, DHT22 en LCD

Als u nog niet bekend bent met de DHT11, DHT22 temperatuursensor en het LCD-display (pinout, hoe het werkt, hoe te programmeren ...), leer hierover in de volgende tutorials:

Bedradingsschema

Arduino - DHT11 Module LCD Bedrading

Arduino DHT11 temperatuur- en vochtigheid LCD bedrading schema

This image is created using Fritzing. Click to enlarge image

Arduino - DHT22 Module LCD Bedrading

Arduino DHT22 temperatuur- en vochtigheid LCD bedrading schema

This image is created using Fritzing. Click to enlarge image

Echte bedrading voor DHT11

Arduino DHT11 LCD bedrading

This image is created using Fritzing. Click to enlarge image

Arduino Code - DHT11 Sensor - LCD I2C

/* * Deze Arduino code is ontwikkeld door newbiely.nl * Deze Arduino code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/arduino/arduino-temperature-humidity-sensor-lcd */ #include <LiquidCrystal_I2C.h> #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows DHT dht(DHTPIN, DHTTYPE); void setup() { dht.begin(); // initialize the sensor lcd.init(); // initialize the lcd lcd.backlight(); // open the backlight } void loop() { delay(2000); // wait a few seconds between measurements float humi = dht.readHumidity(); // read humidity float tempC = dht.readTemperature(); // read temperature lcd.clear(); // check if any reads failed if (isnan(humi) || isnan(tempC)) { lcd.setCursor(0, 0); lcd.print("Failed"); } else { lcd.setCursor(0, 0); // start to print at the first row lcd.print("Temp: "); lcd.print(tempC); // print the temperature lcd.print((char)223); // print ° character lcd.print("C"); lcd.setCursor(0, 1); // start to print at the second row lcd.print("Humi: "); lcd.print(humi); // print the humidity lcd.print("%"); } }

※ Notiz:

Het I2C-adres van het LCD kan verschillen per fabrikant. In de code gebruiken we 0x27, dat wordt gespecificeerd door de fabrikant DIYables.

Snelle stappen

  • Verbind de Arduino met de PC via de USB-kabel
  • Open de Arduino IDE, selecteer het juiste board en de juiste poort
  • Navigeer naar het Bibliotheken icoon in de linkerzijbalk van de Arduino IDE
  • Zoek op “DHT”, en vind de DHT sensor bibliotheek van Adafruit
  • Klik op de knop Installeren om de bibliotheek te installeren
Arduino DHT sensor bibliotheek
  • U krijgt mogelijk de vraag om andere afhankelijkheden te installeren
  • Klik op de knop Alles Installeren om alle bibliotheek afhankelijkheden te installeren
Arduino Adafruit Unified sensor bibliotheek
  • Zoek op “LiquidCrystal I2C”, en vind de LiquidCrystal_I2C bibliotheek van Frank de Brabander
  • Klik op de knop Installeren om de LiquidCrystal_I2C bibliotheek te installeren
Arduino LiquidCrystal I2C bibliotheek
  • Kopieer bovenstaande code en open deze met Arduino IDE
  • Klik op de knop Uploaden in Arduino IDE om de code naar de Arduino te uploaden
  • Maak de omgeving rond de sensor warmer of kouder
  • Bekijk het resultaat op het LCD
Arduino DHT11 LCD Bedrading

This image is created using Fritzing. Click to enlarge image

De bovenstaande code werkt ook voor de Arduino Nano. Een grootvader die via deze tutorial zijn kleinkind begeleidt, heeft deze code getest met Arduino Nano en stuurde ons het onderstaande resultaat:

Arduino toont temperatuur en vochtigheid op LCD

Als het LCD niets weergeeft, zie dan Probleemoplossing bij LCD I2C

Arduino Code - DHT22 Sensor - LCD I2C

/* * Deze Arduino code is ontwikkeld door newbiely.nl * Deze Arduino code wordt zonder enige beperking aan het publiek beschikbaar gesteld. * Voor volledige instructies en schema's, bezoek: * https://newbiely.nl/tutorials/arduino/arduino-temperature-humidity-sensor-lcd */ #include <LiquidCrystal_I2C.h> #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT22 LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows DHT dht(DHTPIN, DHTTYPE); void setup() { dht.begin(); // initialize the sensor lcd.init(); // initialize the lcd lcd.backlight(); // open the backlight } void loop() { delay(2000); // wait a few seconds between measurements float humi = dht.readHumidity(); // read humidity float tempC = dht.readTemperature(); // read temperature lcd.clear(); // check if any reads failed if (isnan(humi) || isnan(tempC)) { lcd.setCursor(0, 0); lcd.print("Failed"); } else { lcd.setCursor(0, 0); // start to print at the first row lcd.print("Temp: "); lcd.print(tempC); // print the temperature lcd.print((char)223); // print ° character lcd.print("C"); lcd.setCursor(0, 1); // start to print at the second row lcd.print("Humi: "); lcd.print(humi); // print the humidity lcd.print("%"); } }

※ Notiz:

De code voor DHT11 en DHT22 is identiek behalve één regel. De bibliotheek voor DHT11 en DHT22 is dezelfde.

Video Tutorial

We overwegen het maken van videotutorials. Als u videotutorials belangrijk vindt, abonneer u dan op ons YouTube-kanaal om ons te motiveren de video's te maken.

※ ONZE BERICHTEN

  • U bent welkom om de link naar deze tutorial te delen. Gebruik onze inhoud echter niet op andere websites. We hebben veel moeite en tijd gestoken in het maken van de inhoud, respecteer alstublieft ons werk!