members
Basics: Project 070n ESP32 development board MQTT
of Acoptex.com in ESP8266 ESP-32
Basics: Project 070n
Project name: ESP32 development board MQTT
Tags: EESP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, Installing the ESP32 Board in Arduino IDE, Uploading sketch, MQTT, BME 280, temperature, humidity, Raspberry, Raspberry PI 3 model B board
Attachments: I2Cscannersketch, library1, library2, library3, sketch1
In this project, you need these parts :
1.Raspberry PI 3 model B 1 pc
2. Micro SD card and SD card adapter 1 pc
3. Micro USB power supply (2.1 A, max 2.5 A) 1 pc
4. USB keyboard 1 pc
5. USB mouse 1 pc
6. TV or PC monitor 1 pc
7. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc
8.Arduino IDE ( you can download it from here )
9.Jumper cables F-M, M-M
10. Resistor 1 pc (220 Ohm)
11. BME280 sensor module 1 pc
12. Breadboard 1 pc
13. LED 1 pc (any color)

General
We will learn how to control ESP32 development board outputs and display sensor data from the ESP32 development board on Node-RED. The Node-RED software is running on a Raspberry PI 3 model B, and the communication between the ESP32 development board and the Node-RED software is achieved with the MQTT communication protocol.
There are a lot of different development boards made. You can find more information about them here.
MQTT Protocol
In this project we are going to establish a communication between a Raspberry PI 3 model B running the Node-RED software and an ESP32 development board using MQTT.
MQTT stands for MQ Telemetry Transport and it is a nice lightweight publish and subscribe system where you can publish and receive messages as a client. It is a simple messaging protocol, designed for constrained devices and with low-bandwidth.
Mosquitto Broker
The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in it and then publishing the message to all subscribed clients in MQTT.
There are several brokers you can use. In this project we’re going to use the Mosquitto Broker which needs to be installed on Raspberry PI 3 model B.
Understanding the Raspberry PI 3 model B
The Raspberry Pi 3 is the third-generation Raspberry Pi. It replaced the Raspberry Pi 2 Model B in February 2016.
Specification:
- Quad Core 1.2GHz Broadcom BCM2837 64bit CPU
- 1GB RAM
- BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board
- 40-pin extended GPIO
- 4 USB 2 ports
- 4 Pole stereo output and composite video port
- Full size HDMI
- CSI camera port for connecting a Raspberry Pi camera
- DSI display port for connecting a Raspberry Pi touchscreen display
- Micro SD port for loading your operating system and storing data
- Upgraded switched Micro USB power source up to 2.5A
Understanding the ESP32 Development board with WiFi and Bluetooth
You can read more about it here.
Understanding the BME280 module
You can read more about it here.
Signals and connections of LED
The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.
Signals and connections of the BME280 sensor module
To use SPI communication protocol, you must have the following pins:
VIN - power supply 3.3V DC
GND - ground
CLK (or SCK or SCL) (Serial Clock) - The clock pulses which synchronize data transmission generated by the master
MISO (or DO or SO or SDO) (Master In Slave Out) - The Slave line for sending data to the master
MOSI (or DI or SI or CMD or SDI or SDA) (Master Out Slave In) - The Master line for sending data to the peripherals
CS (or SS or D3 or CSB) (Chip Select or Slave Select) - the pin on each device that the master can use to enable and disable specific devices
If your BME280 sensor module has 4 pins it can use I2C communication protocol only:
VIN - power supply 3.3V DC
GND - ground
SDA - Serial Data Line
SCL - Serial Clock Line
Signals and connections of the Raspberry PI 3 model B
Signals and connections of the ESP32 Development board with WiFi and Bluetooth
You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.
Let's check our development board - ESP32 DEVKITV1with ESP-WROOM-32 module from Espressif Systems:
Pinout diagram for the ESP Wroom 32 breakout:
ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.
USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.
BOOT button - Download button: holding down the Boot button and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.
EN button - Reset button: pressing this button resets the system.
Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.
TX0, TX2 - transmit pin. GPIO pin
RX0, RX2 - receive pin. GPIO pin
3V3 (or 3V or 3.3V) - power supply pin (3-3.6V).
GND - ground pin.
EN - Chip enable. Keep it on high (3.3V) for normal operation.
Vin - External power supply 5VDC.
Wiring
ESP32 development board BME 280 sensor
G GND
3V3 VCC
D21 SDA
D22 SCL
Step by Step instruction
1. Preparations
- Insert your micro SD card with Raspbian OS to Raspberry Pi 3 board.
- Connect the TV or PC monitor Display port (HDMI Port) to your Raspberry PI 3 board HDMI Port (HDMI cable required).
- Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1, etc).
- Plug in your USB mouse and USB keyboard to Raspberry PI 3 board USB ports.
- Get connected. Connect an Ethernet cable to 10/100 LAN port of Raspberry Pi 3 or plug in WiFi adapter (see the list of supported here) to USB port of Raspberry Pi 3.
- Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
- The Raspberry PI desktop will start up.
- Install Node-RED on you Raspberry PI.
- Install Node-RED Dashboard on you Raspberry PI.
- Install Mosquitto Broker on your Raspberry PI.
2. Establishing a MQTT communication with Node-RED
- We will create the dashboard layout. In this project, we’ll have a button to control an ESP8266 ESP-12E module output; a chart and a gauge to display temperature and humidity readings from the DHT11 sensor.
- Go to Terminal.
- You need to know your Raspberry Pi 3 IP address in order to access your video streaming web server. Use this command: hostname -I
- You will see Raspberry Pi 3 IP address. In our case it is 192.168.0.121.
- Run the commands: sudo apt-get update and sudo apt-get upgrade to make sure that you have all packages up to date.
- Go to Raspberry icon-> Programming -> Node-RED
- You should see a window displaying information about Node-RED starting up.
- On your PC go to web browser (Google chrome or Microsoft Edge). We are using PC with Windows 10.
- Locate the address bar at the top and type: http://your_Raspberry_Pi_IP_address:1880 (in our case that is http://192.168.0.121:1880) then press Enter button. You will see the Node-RED.
- On right top corner of the Node-RED window you need to go to menu to select the dashboard.
- To add a tab to the user interface click on the +tab button.
- Once created, you can edit the tab by clicking on the edit button.
- You can edit the tab’s name and change its icon. Name: you can use any (we used Room); Icon: you should use a name accordingly to the icon’s names here. Press Update button.
- To add a group to the tab, you need to click on the +group button. You can edit the created group by clicking on the edit button. You can edit its name, select its corresponding tab and change its width. Press Update button. Create two groups: Lamp and Sensor inside the Room tab.
- Drag the following nodes to the flow, from Input - MQTT two times, from Output - MQTT one time, from Dashboard - Switch, Chart, Gauge:
switch to control the ESP8266 ESP-12E module output; mqtt output node – to publish a message to the ESP8266 ESP-12E module accordingly to the switch state;2x mqtt input nodes – these nodes will be subscribed to the temperature and humidity topics to receive sensor data from the ESP8266 ESP-12E module; chart – to display the temperature sensor readings; gauge – to display the humidity sensor readings.
- Node-RED and the MQTT broker should be connected. To connect the MQTT broker to Node-REd, double-click the MQTT output node. A new window pops up.
- Click the Add new mqtt-broker option (pencil sign). Type localhost in the server field. All the other settings are configured properly by default.
- Press Add button.
- Edit all the node's properties as shown in the following figure and press Done button - the MQTT output node automatically connects to your broker.
- switch – the switch sends an on string message when it’s ON; and sends an off string message when it’s OFF. This node will publish on the room/lamp topic. Your ESP8266 ESP-12E module will then be subscribed to this topic, to receive its messages. Double-click the switch output node.
- Edit all the node's properties as shown in the following figure and press Done button.
- Double-click on mqtt input node. This node is subscribed to the room/temperature topic to receive temperature sensor data from the ESP8266 ESP-12E module. The ESP8266 ESP-12E module will be pusblishing the temperature readings on this topic. Edit all the node's properties as shown in the following figure and press Done button.
- Double-click on chart node. The chart will display the readings received on the room/temperature topic. Edit all the node's properties as shown in the following figure and press Done button.
- Double-click on mqtt input node. This node is subscribed to the room/humidity topic to receive humidity sensor data from the ESP8266 ESP-12E module. The ESP8266 ESP-12E module will be pusblishing the humidity readings on this same topic. Edit all the node's properties as shown in the following figure and press Done button.
- Double-click on gauge node. The gauge will display the readings received on the room/humidity topic. Edit all the node's properties as shown in the following figure and press Done button.
- Wire your nodes:
- Your Node-RED application is ready. Click Deploy button on the top right corner.
- Go to Web browser.
- Locate the address bar at the top and type: http://your_Raspberry_Pi_IP_address:1880/ui (in our case that is http://192.168.0.121:1880/ui) then press Enter button. This will display the Node-RED dashboard.
3. Adding ESP32 platform to Arduino IDE
The ESP32 is currently being integrated with the Arduino IDE like it was done for the ESP8266. There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language.
1. Installing ESP32 add-on in the Arduino IDE (Windows 10 OS)
- Download and install the latest Arduino IDE Windows Installer from arduino.cc
- Download and install Git and Git GUI from git-scm.com
- Search for Git GUI, right-click the icon and select “Run as administrator“
- Select the Clone Existing Repository option.
- Select source and destination. Source Location: https://github.com/espressif/arduino-esp32.git
- Target Directory:C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32
- Do not create the espressif/esp32 folders, because they will be created automatically.
- Click Clone to start cloning the repository.Wait a few seconds while the repository is being cloned.
- Open the folder: C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32/tools
- Right-click the get.exe file and select “Run as administrator“.
- You will see that necessary files will be downloaded and upzipped. It will take some time.
- When get.exe finishes, you should see the following files in the directory.
2. Uploading sketch to the ESP32 development board
- Do wiring.
- Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
- Open Arduino IDE.
- Open Boards manager. Go to Tools -> Board -> Boards Manager… (in our case it’s the DOIT ESP32 DEVKIT V1)
- Select COM port that the board is attached to (if you don’t see the COM Port in your Arduino IDE, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers)
- Find your BME280 I2C address. Each device has an I2C address that it uses to accept commands or send messages. Open, compile and upload the I2Cscannersketch to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
- Press the ESP32 on-board EN button to reboot it.
- Open the Serial Monitor at a baud rate of 115200. Arduino will scan the address range looking for a reply. Even though the documentation said it was 0x77, this scanner can detect different (in our case 0x76). Adafruit_BME280 library has default I2C address 0x77 and if you are getting 0x76 you need to modify line of code in ESP32devshieldsketch: status = bme.begin();to status = bme.begin(0x76);
- Open and edit the sketch1 with your own SSID, password and Raspberry IP address.
- Compile and upload it to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
- Press the ESP32 on-board EN button to reboot it.
- This code publishes messages of the temperature and humidity from the BME280 sensor on the room/temperature and room/humidity topics trough MQTT protocol. The ESP32 development board is subscribed to the room/lamp topic to receive the messages published on that topic by the Node-RED application, to turn the lamp ON/OFF.
- Open the Serial Monitor at a baud rate of 115200. When your Raspberry Pi is running your Node-RED application and the Mosquitto broker, you can see what’s happening in real time. This is helpful to check if the ESP32 development board has established a successful connection to your router and to the Mosquitto broker. You can also see the messages the ESP32 development board is receiving and publishing.
4. Running your application
- Go to Web browser.
- Locate the address bar at the top and type: http://your_Raspberry_Pi_IP_address:1880/ui (in our case that is http://192.168.0.121:1880/ui) then press Enter button. This will display the Node-RED dashboard.
- Congrats!!! You project is now completed.
Summary
We have learnt how to control ESP32 development board outputs and display sensor data from the ESP32 development board on Node-RED.
Libraries
- All libraries attached on the begining of this project description.
- Wire library included in your Arduino IDE.
- PubSubClient library included. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here. Provides a client for doing simple publish/subscribe messaging with a server that supports MQTT (basically allows your ESP8266 ESP-12E module to talk with Node-RED).
- Adafruit_Sensor library included. Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here.
- Adafruit_BME280 library included.Download, unzip and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here.
Sketch
- See attachments on the begining of this project
Other projects of Acoptex.com










Viewed: 3212 times