Arduino Data Types – Tutorial & Examples
In Arduino programming, variables are used to store data. Each variable has a specific data type
that determines the kind of values it can hold. Below are the most common data types, their
declaration, and usage examples.
1. Data Types with Declarations & Examples
Data Type Declaration Example Usage
int int myNumber; int myNumber = 25;
unsigned int unsigned int myVar; unsigned int myVar = 50000;
long long bigVal; long bigVal = 100000L;
float float temperature; float temperature = 36.7;
double double pi; double pi = 3.14159;
char char letter; char letter = 'A';
byte byte value; byte value = 255;
boolean boolean flag; boolean flag = true;
String String name; String name = "Arduino";
2. Example Codes
// Integer Example
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
counter = counter + 1;
Serial.print("Counter: ");
Serial.println(counter);
delay(1000);
}
// Float Example
float voltage = 5.0;
float resistance = 1000.0;
float current;
void setup() {
Serial.begin(9600);
}
void loop() {
current = voltage / resistance;
Serial.print("Current = ");
Serial.println(current);
delay(2000);
}
3. Arrays & Constants
// Array Example
int numbers[5] = {10, 20, 30, 40, 50};
// Constant Example
const int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
for (int i = 0; i < 5; i++) {
Serial.println(numbers[i]);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
4. Quick Reference – Data Types Summary
Type Size (Bytes) Range
int 2 -32,768 to 32,767
unsigned int 2 0 to 65,535
long 4 -2,147,483,648 to 2,147,483,647
float 4 ±3.4028235E+38
double 4 (Uno) / 8 (some boards) Same as float (Uno)
char 1 -128 to 127
byte 1 0 to 255
boolean 1 true/false
String varies Text