The character functions in Arduino programming are used to perform operation of the character data types that are used in Arduino. These functions are used to determine what type of character is used either as a number or alphabet.

Character functions in Arduino

As there are different types of characters used in Arduino so for each type there is a character function to recognize that type of character.The following are the eleven types of character functions that are briefly explained in this discourse:

  1. isuppercase() and islowercase() character functions
  2. isdigit() character function
  3. isspace() character function
  4. ispunct() character function
  5. isxdigit() character function
  6. isalpha() character function
  7. isascii() character function
  8. iscntrl() character function
  9. isprint() character function
  10. Isalnum() character function
  11. isGraph() character function

The explanation of each function is supported by its respective example.The examples of the Arduino program given are using the ternary operator. This operator is further divided into three parts. The first part is the condition which is to be checked and then comes the operator and if the result is correct then the value given first is displayed and if not the second value will be displayed. This can be further cleared by the syntax of the ternary operator:

((function applied ) ? (value to be displayed if true):( value to be displayed if False ));

isupperCase() and islowerCase() character functions

The upper-case function is used to check if the character used in Arduino programming is in capital letters or not. Similarly, to determine if the character is written in small letters, then the function lower case is used. The example code for both the functions is given:

void setup () {


   Serial.begin (9600);


   Serial.print (” Function islower says:r) ;


   Serial.print (islower( ‘F’ ) ? “f is “ : “F is not “ );


   Serial.println ( ” lowercase letterr );


   Serial.print (“Function islower says :r) ;


   Serial.print (islower( ‘f’ ) ? “f is a” : “F is not a” );


   Serial.println ( ” lowercase letterr );


   Serial.print (“Function isupper says:r) ;


   Serial.print (isupper( ‘F’ ) ? “F is “ : “f is not “ );


   Serial.println ( ” uppercase letterr );


   Serial.print (“Function isupper says :r) ;


   Serial.print (isupper( ‘f’ ) ? “F is a” : “f is not a” );


   Serial.println ( ” uppercase letterr );

}


void loop () {

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-1.png" data-lazy- height="592" src="data:image/svg xml,” width=”1030″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-2.png" data-lazy- height="234" src="data:image/svg xml,” width=”958″>

isdigit() character function

To check whether the character is a number or a letter the isdigit() function is used in Arduino programming. The example code gives further clear understanding of the function.

void setup () {


   Serial.begin (9600);


   Serial.print (” Function isdigit says:r) ;


   Serial.print (isdigit( ‘1’ ) ? “1 is “ : “1 is not “ );


   Serial.println ( ” Digit r );


   Serial.print (“Function isdigit says :r) ;


   Serial.print (isdigit( ‘a’ ) ? “a is a” : “a is not a” );


   Serial.println ( ”  Digitr );

}


void loop () {

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-3.png" data-lazy- height="500" src="data:image/svg xml,” width=”1082″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-4.png" data-lazy- height="148" src="data:image/svg xml,” width=”1058″>

isspace() character function

To determine if there is a space used in the Arduino program the character function isspace() is used. The spaces include tab space both horizontal or vertical, space for new line, form feed space , return space. Here in the example code all types of spaces are used and determined by using the isspace() function. The output of the Arduino program is in binary form. If the output is one then it means true and if the result is zero then it means false.

char character1 = ‘ ‘;


char character2 = ‘t’;


char character3 = ‘C’;


char character4 = ‘n’;


char character5 = ‘f’;


char character6= ‘a’;


char character7=‘v’;


char character8= ‘r’;

void setup() {// put your setup code here, to run once:


  Serial.begin(9600);


  Serial.println(isSpace(character1));


  Serial.println(isSpace(character2));


  Serial.println(isSpace(character3));


  Serial.println(isSpace(character4));


  Serial.println(isSpace(character5));


  Serial.println(isSpace(character6));


  Serial.println(isSpace(character7));


  Serial.println(isSpace(character8));

}


void loop() {


 

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-5.png" data-lazy- height="813" src="data:image/svg xml,” width=”998″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-6.png" data-lazy- height="371" src="data:image/svg xml,” width=”926″>

ispunct() character function

To identify any punctuation marks in the code the function ispunct() is used. In the example four punctuation marks are used and one character and one number is also used to give a clear picture of the working of the function.

void setup () {


   Serial.begin (9600);


   Serial.print (“function ispunct says:r);


   Serial.print (ispunct( ‘!’ ) ? “! is a”: “! is not a”);


   Serial.println(” punctuation mark r );


   Serial.print (“function ispunct says:r);


   Serial.print (ispunct( ‘:’ ) ? “: is a”: “: is not a”);


   Serial.println(” punctuation mark r );


   Serial.print (“function ispunct says:r);


   Serial.print (ispunct( ‘0’ ) ? “0 is a”: “0 is not a”);


   Serial.println(” punctuation mark r );


   Serial.print (“function ispunct says:r);


   Serial.print (ispunct( ‘a’ ) ? “a is a”: “a is not a”);


   Serial.println(” punctuation mark r );


   Serial.print (“function ispunct says:r);


   Serial.print (ispunct( ‘;’ ) ? “; is a”: “; is not a”);


   Serial.println(” punctuation mark r );


   Serial.print (“function ispunct says:r);


   Serial.print (ispunct( ‘.’ ) ? “. is a”: “. is not a”);


   Serial.println(” punctuation mark r );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-7.png" data-lazy- height="767" src="data:image/svg xml,” width=”935″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-8.png" data-lazy- height="321" src="data:image/svg xml,” width=”1344″>

isxdigit() character function

In Arduino programming to pick out the hexadecimal numbers the isxdigit() character function is used. The hexadecimal contains symbols from 0 to 9 and some other alphabetic symbols from A to F. Further it can be cleared from the example code:

void setup () {


   Serial.begin (9600);


   Serial.print (“function isxdigit says:r);


   Serial.print (isxdigit( ‘a’ ) ? “a is a”: “a is not a”);


   Serial.println(” hexadecimal digit r );


   Serial.print (“function isxdigit says:r);


   Serial.print (isxdigit( ’10’ ) ? “10 is a”: “10 is not a”);


   Serial.println(” hexadecimal digit r );


   Serial.print (“function isxdigit says:r);


   Serial.print (isxdigit( ‘e’ ) ? “e is a”: “e is not a”);


   Serial.println(” hexadecimal digit r );


   Serial.print (“function isxdigit says:r);


   Serial.print (isxdigit( ‘y’ ) ? “y is a”: “y is not a”);


   Serial.println(” hexadecimal digit r );


   Serial.print (“function isxdigit says:r);


   Serial.print (isxdigit( ‘2’ ) ? “2 is a”: “2 is not a”);


   Serial.println(” hexadecimal digit r );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-9.png" data-lazy- height="682" src="data:image/svg xml,” width=”950″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-10.png" data-lazy- height="309" src="data:image/svg xml,” width=”1186″>

isalpha() character function

The isalpha() function is used to identify the letters in Arduino programming. It checks whether a character has a letter or number.

void setup () {


   Serial.begin (9600);


   Serial.print (“function isalpha says:r);


   Serial.print (isalpha( ‘a’ ) ? “a is a”: “a is not a”);


   Serial.println(” letter r );


   Serial.print (“function isalpha says:r);


   Serial.print (isalpha( ’10’ ) ? “10 is a”: “10 is not a”);


   Serial.println(” letter r );


   Serial.print (“function isalpha says:r);


   Serial.print (isalpha( ‘e’ ) ? “e is a”: “e is not a”);


   Serial.println(” letter r );


     Serial.print (“function isalpha says:r);


   Serial.print (isalpha( ‘#’ ) ? “# is a”: “# is not a”);


   Serial.println(” letter r );


     Serial.print (“function isalpha says:r);


   Serial.print (isalpha( ‘D’ ) ? “D is a”: “D is not a”);


   Serial.println(” letter r );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-11.png" data-lazy- height="680" src="data:image/svg xml,” width=”1080″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-12.png" data-lazy- height="320" src="data:image/svg xml,” width=”1333″>

isascii() character function

If the ascii number of any character is used in the code this isascii() function tells If the number given is ascii of some character or not.

void setup () {


   Serial.begin (9600);


   Serial.print (“function isascii says:r);


   Serial.print (isascii( ‘$’ ) ? “$ is a”: “$ is not a”);


   Serial.println(” ascii r );


   Serial.print (“function isascii says:r);


   Serial.print (isascii( ‘E’ ) ? “E is a”: “E is not a”);


   Serial.println(” ascii r );


   Serial.print (“function isalpha says:r);


   Serial.print (isascii( ‘α’ ) ? ” α is a”: “α is not a”);


   Serial.println(” ascii r );


   Serial.print (“function isalpha says:r);


   Serial.print (isascii(  ‘ẟ’ ) ? “ẟ is a”: “ẟ is not a”);


   Serial.println(” ascii r );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-13.png" data-lazy- height="706" src="data:image/svg xml,” width=”1243″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-14.png" data-lazy- height="340" src="data:image/svg xml,” width=”1356″>

iscntrl() character function

To identify the controlling characters in the Arduino code like end of text(EOH) , end of transmission(EOT) ,acknowledge(ACK), backspace(BS), start of text (SOT), start of heading(SOH) and enquiry(ENQ) the iscontrol() character function is used. Similarly each of the control characters have their ascii. So here in example ascii are used:

void setup () {


   Serial.begin (9600);


   Serial.print (“function iscntrl says:r);


   Serial.print(iscntrl( ‘n’ ) ? n is a “: n is not a”);


   Serial.println(” control function r );


   Serial.print (“function iscntrl says:r);


   Serial.print (iscntrl( ‘t’ ) ? t is a”: t is not a”);


   Serial.println(” control function r );


   Serial.print (“function iscntrl says:r);


   Serial.print (iscntrl( ‘f’ ) ? f is a”: f is not a”);


   Serial.println(” control function r );


   Serial.print (“function iscntrl says:r);


   Serial.print (iscntrl( ‘s’ ) ? “\s is a”: “\s is not a”);


   Serial.println(” control function r );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-15.png" data-lazy- height="704" src="data:image/svg xml,” width=”1449″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-16.png" data-lazy- height="246" src="data:image/svg xml,” width=”1422″>

isprint() character function

In the Arduino program there are some characters which do not get displayed on the screen or in the output. So for the the identification of such characters isprint() character function is used:

void setup () {


   Serial.begin (9600);


   Serial.print (“function isprint says:r);


   Serial.print (isprint( ‘Ø’ ) ? ” Ø is a”: ” Ø is not a”);


   Serial.println(” printing character r );


   Serial.print (“function isprint says:r);


   Serial.print (isprint( ‘>’ ) ? “> is a”: “> is not a”);


  Serial.println(” printing character r );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-17.png" data-lazy- height="492" src="data:image/svg xml,” width=”1023″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-18.png" data-lazy- height="203" src="data:image/svg xml,” width=”1095″>

isalnum() character function

For the identification of the both letters and numbers the alphanumeric function that is isalnum() is used in Arduino programing:

void setup () {


   Serial.begin (9600);


   Serial.print (“function isalnum says:r);


   Serial.print (isalnum( ‘@’ ) ? “@ is a”: “@ is not a”);


   Serial.println(” is alpha numericr );


   Serial.print (“function isalnum says:r);


   Serial.print (isalnum( ‘1’ ) ? “‘1’ is a”: “‘1’ is not a”);


   Serial.println(” is alpha numericr );


   Serial.print (“function isalnum says:r);


   Serial.print (isalnum( ‘a’ ) ? “a is a”: “a is not a”);


   Serial.println(” is alpha numericr );

}


void loop(){

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-19.png" data-lazy- height="602" src="data:image/svg xml,” width=”1076″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-20.png" data-lazy- height="265" src="data:image/svg xml,” width=”1239″>

isgraph() character function

This character function identifies characters which are printable as well as have some content in it. Similarly, if the character has a space but does not have any content then the isgraph() function will not consider it.

char character1 = ‘ ‘;


char character2 = ‘d’;


void setup() {


  Serial.begin(9600);


  Serial.println(isGraph(character1));


  Serial.println(isGraph(character2));

}


void loop() {

}

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-21.png" data-lazy- height="458" src="data:image/svg xml,” width=”1069″>

Output

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/Character-functions-22.png" data-lazy- height="198" src="data:image/svg xml,” width=”1006″>

Conclusion

To store the values for characters in Arduino programming the character data type is used. Similarly, characters used to perform different types of functions. So, to identify the types of characters based on their properties different character functions are used. This write-up briefly explains the different types of character functions used in Arduino with the help of examples.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2022/01/echo/4BF34E1220604634BB421FC7B96CCC0A-150×150.jpg61f7a35ca0c8f.jpg" height="112" src="data:image/svg xml,” width=”112″>

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.