Machine control panel with Nextion
Build it step by step
0 of 7 doneDesign page 0
Add Start, Stop, Speed, a number and a text.
Set the touch events
Send the component ID on press.
Upload the .tft
Copy to the card, power the display.
Test the link
Print events on the serial monitor.
Act on the events
Switch the relay with Start and Stop.
Show the reading
Update the number twice a second.
Add the alarm
Beep and show a message above the limit.
How do you build a machine control panel with Nextion?
A Nextion touchscreen gives a small machine a proper control panel with start, stop, speed and alarms. You need Arduino Nano, Nextion 3.5 inch HMI display, Relay Module 5V, 5 V 2 A USB adapter, Potentiometer 10 kΩ and Active buzzer 5 V. It takes 7 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- DisplaysBuy
- InterfacesBuyRelay Module 5V × 1
- PowerBuy
- PassivesBuy
- Motors & ActuatorsBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Nextion 5V and GND | Separate 5 V adapter (at least 1 A) and GND | Display power (do not use the Nano's 5 V pin) |
| Nextion TX | Nano D10 | Touch events to the Nano |
| Nextion RX | Nano D11 | Commands from the Nano |
| Nano GND | Nextion GND | Common ground |
| Relay IN | Nano D4 | Switches a low-voltage load (a 12 V pump or fan) |
| Relay VCC and GND | Nano 5V and GND | Power |
| Pot wiper | Nano A0 (ends to 5 V and GND) | Simulated sensor for the gauge |
| Buzzer | Nano D5 and GND | Alarm |
Code
A Nextion display holds its own pages, buttons and gauges, designed in the free Nextion Editor, and talks to the Arduino with short serial messages ending in three 0xFF bytes. Touch events arrive as 0x65, the page number, the component ID and the event; the sketch reads these and acts. Build the .tft file in the editor, copy it to a FAT32 microSD card and let the display upload it at power-up. Power the display from its own 5 V adapter: its backlight can pull more than the Nano's regulator can give. The relay here switches only a low-voltage load such as a 12 V pump or fan. A real machine with mains or dangerous moving parts needs a hardware emergency stop that cuts power without any software, and any mains wiring must be done by a qualified electrician. A password page for settings is a good addition for a shared machine; remember it only keeps casual users out. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Nextion HMI over software serial. Board: Arduino Nano. Library: SoftwareSerial (built in).
// In the Nextion Editor make page 0 with:
// button b0 (id 1) "START" button b1 (id 2) "STOP" slider h0 (id 3) "Speed"
// number n0 (name n0) "Reading" text t0 (name t0) "Status"
// Set the touch Press event of each button and slider to "Send Component ID". The panel then sends: 65 page id event FF FF FF.
// Build the .tft file in the editor, copy it to a FAT32 microSD card, put the card in the display and power it on to upload.
#include <SoftwareSerial.h>
SoftwareSerial nex(10, 11); // RX, TX
const int RELAY = 4, BUZZ = 5;
bool runningMachine = false;
int speedSet = 50;
void nxCmd(const String& s) { nex.print(s); nex.write(0xFF); nex.write(0xFF); nex.write(0xFF); } // every command ends with three 0xFF
void setup() {
pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH); // most relay boards are active LOW, HIGH = off
pinMode(BUZZ, OUTPUT);
nex.begin(9600);
nxCmd("page 0");
nxCmd("t0.txt=\"Stopped\"");
}
void handleEvent(byte page, byte id, byte ev) {
if (ev != 1) return; // act on press only
if (id == 1) { runningMachine = true; digitalWrite(RELAY, LOW); nxCmd("t0.txt=\"Running\""); }
if (id == 2) { runningMachine = false; digitalWrite(RELAY, HIGH); nxCmd("t0.txt=\"Stopped\""); }
}
void loop() {
static byte buf[8]; static byte n = 0; static byte ff = 0;
while (nex.available()) {
byte b = nex.read();
if (b == 0xFF) { ff++; if (ff >= 3) { if (n >= 4 && buf[0] == 0x65) handleEvent(buf[1], buf[2], buf[3]); n = 0; ff = 0; } }
else { ff = 0; if (n < sizeof(buf)) buf[n++] = b; }
}
static unsigned long last = 0;
if (millis() - last > 500) { // update the number on the screen twice a second
last = millis();
int reading = analogRead(A0) / 4; // 0 to 255, stands in for a real sensor
nxCmd("n0.val=" + String(reading));
if (reading > 230) { tone(BUZZ, 2000, 200); nxCmd("t0.txt=\"ALARM high reading\""); } // simple alarm rule
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Touch Start | Relay clicks on, status says Running |
| Touch Stop | Relay clicks off, status says Stopped |
| Turn the pot | Number on the screen follows |
| Pot above 90 percent | Beep and alarm text |
If it does not work
Display does nothing
Check TX and RX are crossed and the baud rate is 9600.
Touch events missing
Set Send Component ID on each component.
Garbled text
Make sure each command ends with three 0xFF bytes.
Display reboots
Use its own 5 V supply.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the machine control panel with Nextion?
Arduino Nano, Nextion 3.5 inch HMI display, Relay Module 5V, 5 V 2 A USB adapter, Potentiometer 10 kΩ and Active buzzer 5 V.
How long does the machine control panel with Nextion take to build?
About 180 minutes for a intermediate maker, in 7 steps.
How do I know the machine control panel with Nextion works?
Touch Start: Relay clicks on, status says Running. Touch Stop: Relay clicks off, status says Stopped. Turn the pot: Number on the screen follows.
Display does nothing: what should I check?
Check TX and RX are crossed and the baud rate is 9600.
Touch events missing: what should I check?
Set Send Component ID on each component.
Garbled text: what should I check?
Make sure each command ends with three 0xFF bytes.
Display reboots: what should I check?
Use its own 5 V supply.
