arduino int to string code example

Example 1: arduino string to int

void loop() {
  Serial.readBytes(mystr,5); //Read the serial data and store in var

  //delay(1000);
  
  String val = mystr; 
  int i = val.toInt();
  int num = i + i;
  Serial.println(num);
  
}

Example 2: arduino ip to string

//IP addresses are stored as an array, you can just say

IPAddress my_IPAddress(162.198.2.3);
Serial.println(my_IPAddress[1]);

//Output
--------------------------------------------------------
 > 198

Example 3: int to string arduino

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
String stringOne = String(5.698, 3);                  // using a float and the decimal places

Tags:

C Example