Start a new topic

how to take Nextion text value in arduino float variable

In my project i have added on nextion t5.txt=45.5;

Please assist me how to take in arduino MCU float sv1;

Because with the help of this float sv1 i will compare with the current value of sensor and operate a relay.

Many many thanks in advance.

atof() ?


Arduino has Serial.parseFloat() which is very easy to use.

If you wrap your float in start and end markers for example <45.5> then watching for the start marker in loop, you just divert the rest of the read directly to the function. You can do multiple reads consecutively as long as there are delimiters (non-numerical characters) between them.

while (Serial.available()) {
 if ( == '<') {
   myFloat1 = Serial.parseFloat();
   //myFloat2 = Serial.parseFloat();//Optional consecutive read
   //Do something with myFloat1/2


my question is in my nextion i have used t5.txt=45.5 (text field i have used for entry because number takes only integer value.

In Arduino i have to used this value for comparision , please suggest how to take this text file from nextion to Arduino float variable, so that i can compare it with my current sensor  value and operate a relay

You do not say how you are programming your Arduino.

I also have no idea how competent you are at programming either Arduino or Nextion.

The atof() function suggested by Michael will work on an ascii string representation of the float.

You will need to capture that string on Arduino. You can push the string from Nextion using the print function. You can pull the string from Nextion using Itead library get function.

The Serial.parseFloat() method I describe, will parse out the float 'value' directly from the incoming ascii stream at the Serial port, so there is no need to collect a string first.

You have choices......


Is the value 45.5 constant or is it changed by the user?

Login or Signup to post a comment