Yash Sanghvi has Published 220 Answers

Defining new functions in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:26:57

Defining new functions in Arduino is equivalent to defining the functions in C.The syntax is −Syntaxreturn_type function_name(arg_type arg)The only difference is that in C, the function needs to be declared at the top, if it is invoked before its definition. No such constraint exists in Arduino. The following code demonstrates ... Read More

Convert string to lowercase or uppercase in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:24:09

In order to convert a string to lower/upper case, the in-built .toLowerCase() and .toUpperCase() functions can be used.Note: These functions change the original string itself, and don't return a new string with the changes.The implementation is shown below −Examplevoid setup() {    Serial.begin(9600);    Serial.println();    String s1 = "Hello World"; ... Read More

Replace characters in a string in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:23:39

The .replace() function in Arduino allows you to replace a character or a substring with another character/substring in Arduino.Note: This function replaces substrings in the original string itself, and does not return a new string containing the changes.Examples are given in the code below −Examplevoid setup() {    Serial.begin(9600);   ... Read More

Convert string to integer/ float in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:22:58

In order to convert a string to an integer or a float, the .toInt() and .toFloat() functions can be used. Of course, the string should actually correspond to the integer or floating-point value. For instance, "1.87" can be converted to float. But it doesn't make sense to convert "Hello" to float. ... Read More

Concatenate strings in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:20:34

String concatenation in Arduino is quite straightforward and also robust. You simply use the + operator to join strings. However, it doesn't end with joining two strings. You can concatenate characters, and even integers and floats to strings (Arduino converts the integers and floating-point numbers to string internally). Examples can ... Read More

Convert character array to string in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:20:05

In order to convert a character array to a string, the String() constructor can be used. An example is shown below −Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    char buf[10] = "Hello!";    Serial.print("Char array: ");    Serial.println(buf); ... Read More

Convert string to character array in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:17:46

There are several libraries built for Arduino whose functions take in character arrays as inputs instead of strings. Thankfully, Arduino has an inbuilt method (toCharArray()) to covert a String to a Character Array. A sample implementation is given below −Examplevoid setup() {    // put your setup code here, to ... Read More

Check if two strings are equal or not in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:17:17

In order to check if two strings are equal, the .equals() function can be used. This returns a Boolean. True if both the strings are equal, else false. An example code is given below −Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);   ... Read More

Find if a string begins with a specific set of characters in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 24-Mar-2021 05:16:42

The startsWith() function in Arduino helps you determine if a string starts with a specific set of characters. It returns true if the string starts with the substring you specified, else it returns false. An example implementation is given below −Examplevoid setup() {    // put your setup code here, ... Read More

Find if a substring exists within a string in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:53:17

In order to check if a specific substring exists within a string in Arduino, the indexOf() function can be used. This returns the index of the first occurrence of the character or a string that you are searching for within another string. In case the character or string does not ... Read More

Advertisements