Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Arduino data type


May 15, 2021 Arduino


Table of contents


The type of data in C refers to an extended system that declares different types of variables or functions. /b10> The type of variable determines how much space it takes up in memory and how it interprets the stored bit pattern.

The following table provides all the data types that you will use during Arduino programming.

void Boolean char Unsigned char
byte Int Unsigned int
Word
long Unsigned long
short float double array String-char array
String-object


void

The void keyword is used only for function declarations. /b10> It indicates that the function is not expected to return any information to the function that called it.

Example

Void Loop ( ) {
   // rest of the code
}

Boolean

Boolean values save one of two values, true or false. /b10> Each Boolean variable takes up one byte of memory.

Example

boolean val = false ; // declaration of variable with type boolean and initialize it with false
boolean state = true ; // declaration of variable with type boolean and initialize it with false

Char

A data type that consumes a byte of memory and stores a character value. /b10> Character text is written in single quotes: 'A', and for multiple characters, the string uses double quotes: 'ABC'.

However, characters are stored as numbers. Y ou can view specific codes in the ASCII chart. /b11> This means that characters that use ASCII values can be arithmetic. /b12> For example, the value of 'A' plus 1 is 66, because the ASCII value of the capital letter A is 65.

Example

Char chr_a = ‘a’ ;//declaration of variable with type char and initialize it with character a
Char chr_c = 97 ;//declaration of variable with type char and initialize it with character 97
Arduino data type

unsigned char

unsigned char is an unsigned data type that consumes one byte of memory. /b10> The unsigned char data type encodes numbers from 0 to 255.

Example

Unsigned Char chr_y = 121 ; // declaration of variable with type Unsigned char and initialize it with character y

byte

One byte stores an 8-bit unsigned number, from 0 to 255.

Example

byte m = 25 ;//declaration of variable with type byte and initialize it with 25

Int

Integers (ints) are the primary data types of digital storage. /b10> Int stores 16-bit (2-byte) values. /b11> This produces a range of -32768 to 32767 (minimum value is -2^15 and maximum value is (2^15)-1).

The size of the int varies from board to board. F or example, in Arduino Due, int stores 32-bit (4 bytes) values. This produces a range of -2147483648 to 2147483647 (min-2^31 and max (2^31)-1).

Example

int counter = 32 ;// declaration of variable with type int and initialize it with 32

Unsigned int

unsigned int (unsigned integer) stores 2 bytes, the same as int. /b10> However, they store only positive values, producing a valid range of 0 to 65535 (2-16)-1. /b11>Due stores 4 bytes (32 bits) of values, ranging from 0 to 4294967295 (2^32-1).

Example

Unsigned int counter = 60 ; // declaration of variable with 
   type unsigned int and initialize it with 60

Word

On Uno and other ATMEGA-based boards, a word stores a 16-bit unsigned number. /b10> On Due and Zero, it stores a 32-bit unsigned number.

Example

word w = 1000 ;//declaration of variable with type word and initialize it with 1000

Long

The Long variable is an extended size variable for digital storage that stores 32 bits (4 bytes) from -2147483648 to 2147483647.

Example

Long velocity = 102346 ;//declaration of variable with type Long and initialize it with 102346

unsigned long

The unsigned long variable is an extended size variable for digital storage and stores 32 bits (4 bytes). /b10>Unlike standard long, unsigned long does not store negative numbers, which range from 0 to 4294967295 (2^32-1).

Example

Unsigned Long velocity = 101006 ;// declaration of variable with 
   type Unsigned Long and initialize it with 101006

short

Short is a 16-bit data type. /b10> On all Arduinos (BASED on ATMega and ARM), a short stores a 16-bit (2-byte) value. /b11> This produces a range of -32768 to 32767 (minimum value is -2^15 and maximum value is (2^15)-1).

Example

short val = 13 ;//declaration of variable with type short and initialize it with 13

float

The data type of the floating point is a number with a number of points of a few. /b10> Floating points are typically used to approximate analog and continuous values because their resolution is higher than integers.

Floating points can be as large as 3.4028235E plus 38, or as low as -3.4028235E plus 38. /b10> They are stored as 32-bit (4-byte) information.

Example

float num = 1.352;//declaration of variable with type float and initialize it with 1.352

double

On Uno and other ATMEGA-based boards, double floats take up four bytes. /b10> That is, the double implementation is exactly the same as the florat, with no gain in precision. /b11> On Arduino Due, double has 8 bytes (64 bits) accuracy.

Example

double num = 45.352 ;// declaration of variable with type double and initialize it with 45.352