How do I convert an int, n
, to a string so that when I send it over the serial, it is sent as a string?
This is what I have so far:
int ledP
You just need to wrap it around a String object like this:
String numberString = String(n);
You can also do:
String stringOne = "Hello String"; // using a constant String
String stringOne = String('a'); // converting a constant char into a String
String stringTwo = String("This is a string"); // converting a constant string into a String object
String stringOne = String(stringTwo + " with more"); // concatenating two strings
String stringOne = String(13); // using a constant integer
String stringOne = String(analogRead(0), DEC); // using an int and a base
String stringOne = String(45, HEX); // using an int and a base (hexadecimal)
String stringOne = String(255, BIN); // using an int and a base (binary)
String stringOne = String(millis(), DEC); // using a long and a base
This simply work for me:
int bpm = 60;
char text[256];
sprintf(text, "Pulso: %d ", bpm);
//now use text as string
Serial.println(val)
Serial.println(val, format)
for more you can visit to the site of arduino https://www.arduino.cc/en/Serial/Println
wish this will help you. thanks!