Why Nextion + ESP32?
Combining Nextion HMI displays with ESP32 creates powerful IoT interfaces. Nextion handles the graphics while ESP32 provides WiFi, Bluetooth, and processing power.
Perfect Combination
- Nextion: Professional HMI graphics, touch input
- ESP32: WiFi, Bluetooth, GPIO, sensors
- Simple: Just TX/RX serial connection
- Fast: Offloaded display processing
Wiring ESP32 to Nextion
| Nextion | ESP32 | Color |
|---|---|---|
| TX | RX2 (GPIO16) | Yellow |
| RX | TX2 (GPIO17) | Blue |
| 5V | 5V (VIN) | Red |
| GND | GND | Black |
Power Note
Nextion displays can draw 500mA+. Use external 5V supply for larger displays, not just USB power.
Basic Communication Code
#include <HardwareSerial.h>
HardwareSerial nexSerial(2); // UART2
void setup() {
Serial.begin(115200);
nexSerial.begin(9600, SERIAL_8N1, 16, 17);
// Send command to Nextion
sendCommand("page 0");
}
void sendCommand(const char* cmd) {
nexSerial.print(cmd);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
}
void updateText(const char* obj, const char* text) {
char cmd[64];
sprintf(cmd, "%s.txt=\"%s\"", obj, text);
sendCommand(cmd);
}
void updateNumber(const char* obj, int value) {
char cmd[32];
sprintf(cmd, "%s.val=%d", obj, value);
sendCommand(cmd);
}
Project Ideas
Smart Thermostat
Temperature control with scheduling, WiFi for remote access
Home Dashboard
Control lights, view sensors, weather display
Audio Controller
Spotify/media controls with album art display
Plant Monitor
Soil moisture, light levels, watering alerts
Energy Monitor
Real-time power consumption display
Car Dashboard
OBD-II data display with gauges
Using EasyNextionLibrary
For easier development, use the EasyNextionLibrary:
#include "EasyNextionLibrary.h"
EasyNex myNex(Serial2);
void setup() {
myNex.begin(9600);
}
void loop() {
myNex.NextionListen(); // Listen for touch events
// Update display elements
myNex.writeStr("t0.txt", "Hello!");
myNex.writeNum("n0.val", 42);
myNex.writeNum("j0.val", 75); // Progress bar
}
Get Started
Browse our Nextion HMI displays and ESP32 boards.
New to Nextion? Start with our Nextion Editor Tutorial.
Frequently Asked Questions
Can I use these projects with ESP8266 instead of ESP32?
Yes, most projects work with ESP8266, but you'll need to use software serial for Nextion communication since ESP8266 has only one hardware serial port. Projects requiring dual-core processing or Bluetooth should stick with ESP32. For simple sensor displays and WiFi-only projects, ESP8266 is perfectly adequate and more affordable.
How do I send data from ESP32 to Nextion display?
Use simple serial commands. For example, to update a text component named txtTemp with temperature value: Serial2.print('txtTemp.txt="25.5°C"'); followed by three 0xFF bytes as terminators. The Nextion immediately updates the display. All commands follow this pattern: component.attribute=value plus terminators.
Can Nextion displays work without an external microcontroller?
Nextion displays can run standalone interfaces with timers, buttons, and page navigation, but they cannot connect to WiFi or read external sensors directly. For IoT projects, internet connectivity, or sensor integration, you need an external microcontroller like ESP32 to act as the communication bridge.
What is the maximum distance between ESP32 and Nextion display?
Serial UART communication typically works reliably up to 10-15 meters with standard wires at 9600 baud. For longer distances, use shielded cable, lower baud rates, or consider RS485 converters. For most projects where the display and microcontroller are in the same enclosure, standard jumper wires work perfectly.
How do I handle Nextion button presses in ESP32 code?
Configure the Nextion button component to send a unique string in its Touch Release Event (for example, 'BTN1'). In ESP32 code, continuously read Serial2, parse incoming strings, and execute corresponding actions when specific button codes are received. Use if/else or switch statements to route different button events to different functions.
