Skip to main content

Arduino programming variables

Some guidance regarding the nature of the variables manipulated when programming an Arduino


ordered from smallest in memory size to largest

1 byte

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

boolean
= true or = false

char  - signed
char stores a character value in a single quote.
encodes numbers from -128 to 127
see ASCII table for correspondence between number from 0 to 127 and character


unsigned char  - unsigned
use byte instead

2 bytes

int
first bit used for sign; numbers from -32,768 to 32,767 
(minimum value of -2^15 and a maximum value of (2^15) - 1)
(4 bytes on arduino due)

unsigned int

same as int, but from 0 to 65,535 (2^16) - 1)


word

A word stores a 16-bit unsigned number, from 0 to 65535. Same as an unsigned int.

short

A short is a 16-bit data-type.
-32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1).



4 bytes


long
Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647.
If doing math with integers, at least one of the numbers must be followed by an L, forcing it to be a long. See the Integer Constants page for details.

unsigned long
range from 0 to 4,294,967,295 (2^32 - 1).

double
on arduino uno, 4 bytes
same precision as float

float
4 bytes
6-7 digits precision only
math slow on floats

undefined length

string
declare as an array of chars
define as double quote

String
...


Comments