user-img

FUSION AUTOMATE

  • 3 Projects
  • 3 Followers
  • Oct 28,2025
+ Follow

GPIO Control in ESP32 using Nextion Discovery Series Display

ESP32 controls an LED via Nextion touch display. Buttons trigger glow, fast blink, slow blink, or turn off using serial events and non-blocking logic for smooth, real-time control.

GPIO Control in ESP32 using Nextion Discovery Series Display
 
  • thumbnail-img
 

Hardware Components

  • Nextion 3.5" Discovery Series Resistive Touch Display

    Nextion
    X 1 fenxiang

Tools, APP Software Used etc.

  • Nextion Display

    Nextion
  • Arduino IDE

    Arduino IDE

    Arduino

Story

⚡ ESP32 × Nextion Display — GPIO Control Demo

This project demonstrates how to control an ESP32’s GPIO pin using a Nextion HMI Display. It’s a clean example of two-way serial communication between the ESP32 and a Nextion Discovery series touchscreen, where user touch events directly drive an LED’s behavior.


???? Project Overview

The setup allows you to:

  • Glow the LED continuously
  • Blink the LED fast
  • Blink the LED slow
  • Turn the LED off (automatically when buttons are released)

The project showcases how to handle Nextion touch events on the ESP32 through the Serial2 port, parse the raw data packets, and execute non-blocking LED operations.


???? Hardware Used

Component Description
ESP32 Main microcontroller handling logic
Nextion Discovery Display Touchscreen interface for user input
LED Connected to GPIO 2
Wires / Breadboard For basic prototyping and connections

⚙️ Circuit Connections

ESP32 Pin Nextion Pin Description
16 TX Data from Nextion → ESP32
17 RX Data from ESP32 → Nextion
5V 5V Power
GND GND Common Ground
2 LED Anode LED Output Pin

(Add a 220 Ω resistor in series with the LED if using a standard one.)


???? Nextion Display Setup

On the Nextion Editor, create three buttons with the following IDs:

Button ID Purpose
bt0 2 LED Glow
bt1 3 Blink Fast
bt2 4 Blink Slow

Make sure the buttons send a “Touch Event” (Send Component ID) when pressed and released. The ESP32 interprets these packets automatically.


???? Working Principle

  1. Nextion Touch Event → ESP32: When a button is pressed, Nextion sends a 7-byte serial packet starting with 0x65.

  2. ESP32 Decodes Event: The ESP32 checks the header, validates terminators (0xFF 0xFF 0xFF), and extracts:

    • Page ID
    • Component ID
    • Press/Release event
  3. LED Behavior Changes Dynamically: Depending on which button is pressed:

    • bt0 → LED ON
    • bt1 → LED Blink Fast
    • bt2 → LED Blink Slow
    • On button release → LED OFF
  4. Non-Blocking Blink: The LED blinks using a millis()-based timer, ensuring smooth and responsive UI behavior without delays.


???? Code Highlights

switch (currentState) {
  case LED_GLOW:
    digitalWrite(ledPin, HIGH);
    break;
  case LED_BLINK_SLOW:
    blinkLed(500);
    break;
  case LED_BLINK_FAST:
    blinkLed(200);
    break;
  case LED_OFF:
  default:
    digitalWrite(ledPin, LOW);
    break;
}

✅ Non-blocking logic — LED behavior doesn’t freeze other operations. ✅ Clean event handling — Each button event is decoded and mapped clearly. ✅ Scalable structure — Easy to extend for more GPIOs or multiple pages.


???? Serial Packet Example

A button press from Nextion typically sends this 7-byte packet:

Byte Example Meaning
0 0x65 Touch event header
1 0x00 Page ID
2 0x02 Component ID (e.g., bt0)
3 0x01 Event (1 = press, 0 = release)
4–6 0xFF 0xFF 0xFF Packet terminator

???? Demo Behavior

Button Action LED Behavior
bt0 (Glow) Press LED stays ON
bt1 (Blink Fast) Press LED blinks rapidly
bt2 (Blink Slow) Press LED blinks slowly
Any button Release LED turns OFF

???? Tools Used

  • Arduino IDE (with ESP32 board support)
  • Nextion Editor for GUI design
  • Serial Monitor for debugging events
Code
  • Arduino code in GPIO_Control_ESP32.ino

    GPIO_Control_ESP32_155657352568ffb25899ac2.zip
    Download(2)

GPIO Control in ESP32 using Nextion Discovery Series Display

ESP32 controls an LED via Nextion touch display. Buttons trigger glow, fast blink, slow blink, or turn off using serial events and non-blocking logic for smooth, real-time control.

49
 
7
0
0
These revenues will go back into supporting creators, contests, and the open source ecosystem, and more.

Share your project on social media to expand its influence! Get more people to support it.

  • Comments( 0 )
  • Like( 7 )
/1000
Upload a photo:
You can only upload 1 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP

You May Also Like

View All
Add to cart
Board Type : GerberFile :
Layer : Dimensions :
PCB Qty :
Different PCB Design
PCB Thickness : PCB Color :
Surface Finish : Castellated Hole :
Copper Weight : 1 oz Production Time :
Total: US $
As a sharing platform, our community will not bear responsibility for any issues with this design and parameters.

PCB Assembly

PCBA Qty: BomFile:
NO. OF UNIQUE PARTS: NO. of Components:
Country: Shipping Way:
Assembly Cost: US $
As a sharing platform, our community will not bear responsibility for any issues with this design and parameters.
Add to cart
3dPrintingFile : Size :
Unit : Volumn :
3D Printing Qty : Material :
Total: US $12.99
As a sharing platform, our community will not bear responsibility for any issues with this design and parameters.
Add to cart
Acrylic Type : AcrylicFile :
Dimensions: Engrave:
Acrylic Qty :
Acrylic Thickness:
Acrylic Color:
Total: US $12.99
As a sharing platform, our community will not bear responsibility for any issues with this design and parameters.
Add to cart
CNC Milling File : Size:
Unit: Volumn:
CNC Milling Qty : Material:
Type of Aluminum: Surface Finish:
Tolerance:
Surface Roughness:
Total: US $12.99
As a sharing platform, our community will not bear responsibility for any issues with this design and parameters.
Add to cart
Item Price Qty Subtotal Delete
Total: US $0.00
Certified Product | Supported Purchase: Full After-sales Protection