Building IoT application using ESP32 and Micropython in 10 Steps

Objective : In this blog we will demonstrate how to build end to end IoT application using ESP32 board and Micropython as language.

What is required:

ESP32 development board

DHT22 sensor

SSD1306 OLED display

Raspberry Pi

Windows/Linux OS to connect to ESP32 board via serial port


Before explaining architecture, let us understand why we choose these components

Why ESP 32 board: Good specs at decent cost for hackers Dual core , Wifi, 3.3 V logic, Bluetooth

Why Micropython: High level language, Simple and clean, REPL, easy for experimentation and prototyping



This architecture has two components

Publish sensor data (temperature) from Edge on ESP32 using micropython

Subscribe sensor data (temperature) from Raspiberry Pi and display on SSD1306 using python3

Edge side setup (ESP32 setup):

Step 1: Refer earlier blog to setup and get into REPL prompt.

There are three ways to get into this prompt

  1. Using plain serial port communication (cp2102 drivers)
  2.  Using editors like esplorer
  3. Using Rshell
  4.  Using Adafruit Ampy

Step 2:

Connect to Wireless network

Step 3: Connect DHT22 with ESP 32

DHT 22 has 4 pins, Pin 1 Vcc on the DHT22 is connected to a 3.3V pin on the ESP32. Pin 2, the DHT-22 data line is connected to GPIO13  Pin 3 is left disconnected and pin 4 ground is connected to a ground on the ESP32.

Step 4: MQTT Publish code

If umqtt is not there , install using this command


Step 5: Verify edge side code

On the serial console, check temperature and humidity values are showing

Pi Side setup

Step 6: Setting up Pi

Install python3 and connect SSD1306

Step 7 : Subscribe code

Step 8 :Display data code via SSD OLED display

Verify the reading at SSD console connected with Pi

Step 9 : Also verify the readings from Cloudmqtt console to check the messages are published and subscribed

Step 10 : Take the ESP32 setup with Battery and put it in another place,where temperature and humidity is different. Check SSD console to verify.



One Comment

Add a Comment

Your email address will not be published. Required fields are marked *