Book Image

Internet of Things Projects with ESP32

By : Agus Kurniawan
Book Image

Internet of Things Projects with ESP32

By: Agus Kurniawan

Overview of this book

ESP32 is a low-cost MCU with integrated Wi-Fi and BLE. Various modules and development boards-based on ESP32 are available for building IoT applications easily. Wi-Fi and BLE are a common network stack in the Internet of Things application. These network modules can leverage your business and projects needs for cost-effective benefits. This book will serve as a fundamental guide for developing an ESP32 program. We will start with GPIO programming involving some sensor devices. Then we will study ESP32 development by building a number of IoT projects, such as weather stations, sensor loggers, smart homes, Wi-Fi cams and Wi-Fi wardriving. Lastly, we will enable ESP32 boards to execute interactions with mobile applications and cloud servers such as AWS. By the end of this book, you will be up and running with various IoT project-based ESP32 chip.
Table of Contents (12 chapters)

Working with DHT sensors

To build a weather station, we need environmental sensors. In Chapter 2, Making Visual Data and Animation on an LCD, we learned how to retrieve temperature and humidity from a DHT22 module, and displayed this in the LCD.

To work with DHT22, we declare a DHT module type and its GPIO pin on ESP32:

#include <dht.h>
static const dht_sensor_type_t sensor_type = DHT_TYPE_DHT22;
static const gpio_num_t dht_gpio = 26;

We can obtain the temperature and humidity from DHT22, and we can call the dht_read_data() function by passing temperature and humidity variables, as follows:

int16_t temperature = 0;
int16_t humidity = 0;

dht_read_data(sensor_type, dht_gpio, &humidity, &temperature);

Next, we will implement a weather station with ESP32.