ESP32 Starter Kit
(continued from previous page)
#include <xht11.h>
LiquidCrystal_I2C lcd(0x27, 16,2); // set the LCD address to 0x27 for a 16 chars and 2␣
˓→line display
xht11 xht(26); //The DHT11 sensor connects to IO26
unsigned char dat[] = { 0, 0, 0, 0 }; //Define an array to store temperature and␣
˓→humidity data
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop() {
if (xht.receive(dat)) { //Check correct return to true
lcd.setCursor(0, 0);
lcd.print("humidity:");
lcd.setCursor(9, 0);
lcd.print(dat[0]);
lcd.setCursor(0, 1);
lcd.print("temperature:");
lcd.setCursor(12, 1);
lcd.print(dat[2]);
}
delay(1500); //Delay 1500ms
}
4. Test Result
After connecting the wiring and uploading code, the LCD display will directly discover the ambient humidity and
temperature value.
8.5.26 Project 25: Ultrasonic Rangefinder
1. Description
This ultrasonic rangefinder measures distance of obstacles by emitting sound waves and then receiving the echo. That
is to say, the distance is not an immediate value, but an observed one by a theoretical calculation of time difference
between emitter and receiver.
Ultrasonic is able to detect the shape of objects, set up automatic doors and estimate flow velocity and pressure.
134 Chapter 8. Arduino Tutorial