DHT11 on pin 3, readings on an LCD, on an Arduino Uno
A DHT11 module on pin 3 measures temperature and humidity; the DHT library reads it every two seconds and a 16x2 LCD on pins 4, 6 and 10 to 13 shows both. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Temperature and humidity: a DHT11 on pin 3, read out on the LCD.
//
// DHT11 DATA -> pin 3 VCC -> 5V GND -> GND
// LCD RS -> pin 4 LCD E -> pin 6
// LCD D4 -> pin 10 D5 -> pin 11 D6 -> pin 12 D7 -> pin 13
// LCD RW, VSS, K -> GND VDD, A -> 5V
// LCD V0 (contrast) -> GND here; on the bench, the middle leg of a pot
//
// The DHT11 sends its readings down one wire as a string of short and long
// pulses. The DHT library times them. The sensor needs about two seconds
// between readings, so the sketch waits that long.
//
// Click the sensor and change its temperature or humidity.
#include <LiquidCrystal.h>
#include <DHT.h>
DHT dht(3, DHT11);
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
void setup() {
dht.begin();
lcd.begin(16, 2);
Serial.begin(9600);
Serial.println("Mokxi Uno: DHT11 on pin 3, LCD on pins 4, 6 and 10 to 13");
}
void loop() {
delay(2000);
float humidity = dht.readHumidity();
float celsius = dht.readTemperature();
if (isnan(humidity) || isnan(celsius)) {
lcd.clear();
lcd.print("Sensor error");
Serial.println("no reading: check the DATA wire");
return;
}
lcd.setCursor(0, 0);
lcd.print("Temp: C ");
lcd.setCursor(6, 0);
lcd.print(celsius, 0);
lcd.setCursor(0, 1);
lcd.print("Humidity: % ");
lcd.setCursor(10, 1);
lcd.print(humidity, 0);
Serial.print(celsius, 0);
Serial.print(" C, ");
Serial.print(humidity, 0);
Serial.println(" %");
}
Parts list
4 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
9 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 13; Character LCD, 16x2 pin D7
- Arduino Uno R3 pin 12; Character LCD, 16x2 pin D6
- Arduino Uno R3 pin 11; Character LCD, 16x2 pin D5
- Arduino Uno R3 pin 10; Character LCD, 16x2 pin D4
- Arduino Uno R3 pin 6; Character LCD, 16x2 pin E
- Arduino Uno R3 pin 4; Character LCD, 16x2 pin RS
- Arduino Uno R3 pin 3; Temperature and humidity, DHT22 pin DATA
- Arduino Uno R3 pin 5V; Character LCD, 16x2 pin VDD; Character LCD, 16x2 pin A; Temperature and humidity, DHT22 pin VCC
- Ground: Arduino Uno R3 pin GND; Character LCD, 16x2 pin VSS; Character LCD, 16x2 pin V0; Character LCD, 16x2 pin RW; Character LCD, 16x2 pin K; Temperature and humidity, DHT22 pin GND
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.