Start a new topic

Arduino physical button to change page

Greetings everyone!


Is there a way for me to use a physical button on my arduino, to change the page on the nextion display? Using it as a display in my car, but im want to use a button on my steering wheel and not touch the display.


Should be really simple yet i cant figure it out lol




Hi Nicholas,

I think this is quite possible.

Step one is to receive the button data inside the arduino, after that it can send the information to the Nextion screen.

Step two is to make sure the Nextion knows the information that the arduino is sending through serial communication. Unfortunately the Nextion doesn't has something like an interrupt to know when data is received from the arduino (As far as I know, I haven't played with it for a few months). So my solution is something like running a timer that is checking a variable that the arduino will change by sending the information. When the variable has changed you can use different of if statements to jump to a next page depending on the received information.

Hope this makes some sense.


Hi there,


Thank you very much for your reply! I ended up just sending new texts to every text box so long, so far its working great. I was worried about using to much processing time but so far for my application its working perfectly. Doesnt seem as slow as i thought it would be. Again thank you very much! I'll do some deeper research into your idea!




There is a function in the Arduino library to change page.

It's in the examples CompPage.

It uses; to change to page 3


do I need to install nexpage for this to work?

//*************** Sketch

/*********name:Flame Alarm*************************/

#include <SoftwareSerial.h>
#include <Nextion.h>

NexPage page6  = NexPage(6, 0, "page6");

//Nextion Code
SoftwareSerial nextion(10, 11);// Nextion TX to pin 10 and RX to pin 11 of Arduino
Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

const int analogInPin = 9;// D0
const int digitalInPin = A3; //A0
const int ledPin = 13; //pin13 built-in led
const int buzzerPin=25; //buzzer

void setup()
  //set the pins state
  Serial.begin(9600);//initialize serial


void loop()
  int analogVal = analogRead(analogInPin); //read the value of A0
  Serial.print("A0: ");
  Serial.println(analogVal);//print to serial monitor
  boolean stat = digitalRead(digitalInPin);
  Serial.print("D0: ");
  Serial.println(stat); // print to serial monitor
  Serial.println(" ");
  if(stat == HIGH)
  //noTone(25);//if you want to play different pitches on multiple pins, you need to  call noTone() on one pin before calling tone() on the next pin.
  if(stat == LOW)
  myNextion.setComponentText("t10","TEST"); //Flame Sensor;
  delay(500); // used to slow down readings while calibrating


// ***************This is the Error I get*************************

exit status 1
'NexPage' does not name a type

Not sure if this thread is still read by anyone but i need help with the following. 

I have an Arduino uno with an IR sensor on it, I want the sensor to send a command to my nextion display to change a page on the display using a button i have created on the nextion editor. The file is already uploaded on the nextion and the buttons work if i press them with my finger.  I am new to this software and most of the video tutorials show what i want but the other way around (i.e a button on the display to turn on a feature on the arduino board) , what code do i need to press the button when triggered by the IR sensor? 

Thankyou in advance!

 Forum closed since Nov. 15 2017 !!!!