
Nextion Display with Arduino: Complete Guide Without Using the Nextion Library
Learn how to connect and control a Nextion display with Arduino using serial communication—no library required. Simple, fast, and memory efficient.
If you've ever worked with a Nextion HMI display, you probably know it usually requires the Nextion Editor software and official library. But what if you could control it directly through Arduino serial communication, with no external libraries?
In this tutorial, we'll walk you through how to interface a Nextion display with Arduino without the Nextion library. You'll learn how to send commands manually, update text or numeric values, and build interactive projects that run faster and use less memory. This approach gives you more control, flexibility, and deeper understanding of how Nextion displays really work.
About Project
The Nextion display comes with an official Arduino library, but it can be memory-heavy and sometimes difficult to use, especially for simple projects. To make things faster and more efficient, we'll control the Nextion display directly using USART (RX/TX) serial communication — without relying on any external libraries.
In this tutorial, we'll build the project in two main parts:
- Nextion Display Setup and Programming – designing the user interface and uploading it to the display.
- Arduino Programming – writing the code to send and receive serial commands for display control.
This approach gives you better performance, lower memory usage, and a clearer understanding of how the Nextion and Arduino communicate at the serial level.
Components Requirements
- 1 × Arduino
- 1 × Nextion Display
- 1 × TTL Serial to USB Adapter
- 1 × 220 Ω Resistor
- 1 × LED
- 1 × BreadBoard
- 8 × Jumper Wires
🧩 Part I – Creating and Programming the Nextion Display Screen
If you're new to the Nextion display, don't worry! You can check out our Beginner's Guide to Nextion Editor here to learn the basics of creating interfaces, adding buttons, and programming events. That guide covers everything you need to get started with the Nextion HMI Editor software.
For this project, I've designed a custom Nextion screen as shown below. The interface includes essential UI elements such as text fields, buttons, and data display areas, which we'll later control directly from the Arduino using serial communication (USART) — all without using the official Nextion library.
As shown in Figure 1, the main screen layout of our Nextion project includes the following components:
- Main Screen ID: page0
- Slider ID: h0
- Text Box IDs: t0, t1
- Button IDs: b0, b1
Before we move to Arduino coding, we need to write the user code (event code) for these components inside the Nextion Editor. You can refer to the Nextion User Code Guide here for detailed syntax and command references.
In this section, we'll create event codes for the slider (h0) and the buttons (b0, b1) to enable communication with the Arduino. The data will be sent in string format through the serial interface (USART).
The first step is to set the correct baud rate for your Nextion display to ensure smooth communication with the Arduino.
Page0 : postinitialize Event
bauds=9600
h0 : TouchRelease Event
// here we use va0 as string variable to convert number to string
covx h0.val,va0.txt,0,0
prints va0.txt,3
b0 : TouchRelease Event
prints b0.txt,2
b1 : TouchRelease Event
prints b1.txt,2
Interface: Upload Project HMI file using TTL Serial to USB Adapter
Interface Nextion Display with Arduino
🎥 Watch Nextion Display Video Tutorial
For a complete step-by-step guide, check out our Nextion Display Tutorial video, where we demonstrate the full setup, programming, and Arduino communication process.
🔧 Part II – Arduino Programming (Nextion Display Communication Without Library)
Now it's time to write the Arduino code for the second part of this project. In this section, we'll establish serial communication between the Arduino and the Nextion display, process incoming commands, and control components like the built-in LED.
⚙️ Step 1: Set Up Serial Communication
First, initialize the serial communication with the proper baud rate. This allows the Arduino to exchange data with the Nextion display via the USART (RX/TX) pins.
Serial.begin(9600);
💡 Step 2: Configure the Output Pin
We'll use the built-in LED (Pin 13) to test communication. Set Pin 13 as an output in the setup section:
pinMode(13, OUTPUT);
🧠 Step 3: Read Data from Nextion Display
To receive messages from the Nextion display, we first check if data is available on the serial port:
if (Serial.available())
{
while (Serial.available())
{
Data_From_Display += char(Serial.read());
}
}
Here, Data_From_Display stores the incoming string from the display.
🔍 Step 4: Compare and Process Incoming Commands
Next, we compare the received string with the commands sent from the Nextion display — either ON, OFF, or a slider value.
if (Data_From_Display == "ON") {
digitalWrite(13, HIGH); // Turn LED ON
}
else if (Data_From_Display == "OFF") {
digitalWrite(13, LOW); // Turn LED OFF
}
else {
// Slider value received
String command = "page0.t0.txt=\"" + Data_From_Display + "\"";
Serial.print(command);
// Send termination bytes to Nextion
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
In this code: else coming data is slider value so we need to send it back to page0 textbox t0, for that we have to send string as given below:
- page0.t0.txt = "Data_From_Display"
- page0 → Main screen ID
- t0 → Textbox ID
Data_From_Display → Value received from the slider
These commands update the text box (t0) on the Nextion screen with the slider's current value.
💾 Source Code & Project Files
You can download the complete Arduino source code and Nextion project file from the link below:
📥 Download Project🏁 Conclusion
In this project, we successfully learned how to interface a Nextion display with Arduino without using the official Nextion library. By using simple serial communication (USART), we achieved full control of the display — including buttons, sliders, and text updates — while saving memory and improving performance.
This approach helps beginners understand how Nextion and Arduino communicate directly, making it easier to build efficient HMI-based embedded projects.
Thank you so much. I really liked how you explained the project step by step. It was really helpful.
ReplyDeleteAlways Welcome. Its Our pleasure
Deletethank you
ReplyDelete