It’s very easy and tempting to grab code off the internet and plug it into your project if you’re just looking to tinker with Arduino. However, building something more serious requires a fair grasp of the Arduino language, allowing you to drill down on potential kinks and bugs. You’ll probably want to have a handle on the key areas first. Fortunately, data types are almost certainly the best place to start.
Wrongly using data types could lead to unexpected behavior in your project, incorrect results, or even crashes, causing you frustration and wasted time. If you’d therefore like to wrap your head around the different Arduino data types, this comprehensive guide will help you get a solid grasp on the subject. From standard data types like int and float to custom ones like class and struct, we’ll break them down so you can easily learn how to use them effectively.
- Entry-level board to experience Arduino
- Learn how sensors and actuators work
- 14 digital input/output pins (6 can be used as PWM outputs), 6 analog inputs
- 16 MHz quartz crystal
- USB connection and power jack
- ICSP header plus a reset button
The Different Data Types in Arduino
In programming, data types are used to classify different types of data, such as numbers, letters, and true/false values. These data types are crucial in any programming language because they determine how the computer will store, interpret, and manipulate the data.
In Arduino, data types are especially important because the board has limited memory and processing power compared to a full-fledged computer. This means that selecting the appropriate data type is crucial to optimize memory usage and ensure efficient code execution.
Arduino uses low-level languages like C and C++ under the hood since they offer direct hardware access and provide precise control over the device. In these languages, data types are defined based on the number of bits used to store the data, such as 8-bit, 16-bit, or 32-bit.

©StockEU/Shutterstock.com
Standard Arduino Data Types
Continue reading for an in-depth look at some of the standard Arduino data types.
Int
Integers are often among the first data types to encounter in Arduino, as with many other programming languages. The int data type holds whole numbers between -32,768 and 32,767 and is a 16-bit signed integer. Arduino commonly uses it, making it suitable for most general-purpose applications.
If you’re working with values that are always positive, like sensor readings or counters, you can use the unsigned int instead. An unsigned int is a 16-bit unsigned integer that can only store positive whole numbers between 0 and 65,535. This would help when avoiding negative values and simplifying your code.
Long
When you’re dealing with numbers that are too big for an int variable, you can turn to the long data type. The long variable can store a 32-bit signed integer value. So it’s able to handle whole numbers ranging from -2,147,483,648 to 2,147,483,647. This data type is especially useful when you’re working with big values, like readings from sensors or time intervals.
If you’re working with large positive numbers, like data sizes or time values, then you’ll want to use the unsigned long. It’s a 32-bit unsigned integer that can only store positive whole numbers between 0 and 4,294,967,295.
One thing to keep in mind is that long variables use up more memory than int variables. So you should only use them when you really need to. If you’re dealing with smaller values, it’s better to stick with int variables. This will save memory and avoid any memory overflow issues.
Float
Unlike the previous integer data types which only work with whole numbers, the float data type can hold values with up to 6-7 significant digits. The float data type is perfect for storing decimal values with extraordinary precision. This data type is especially useful when you need to deal with precise readings, such as temperature sensors or GPS coordinates. It can hold a wide range of values.
Float data types offer versatility and support a range of mathematical operations, from simple addition and subtraction to more complicated trig functions. They can handle both positive and negative numbers and have an extensive range that goes from -3.4028235E+38 to 3.4028235E+38.
Float data types too consume more memory than integer data types, so it’s vital to use them only when necessary to avoid memory issues. Float data types sometimes lead to rounding errors when performing operations because of how the memory stores them. It’s important to keep this in mind while writing Arduino code.
Double
If you’re looking to store larger decimal values with greater accuracy than what a float variable can handle, then the double data type is a fantastic option. With its 64-bit (8-byte) floating-point value, a double variable can hold an extensive range of numbers from -21024 – 1 to 21024 – 1, making it perfect for those rare scenarios that demand extremely high accuracy.
Unlike float variables, which can only store values with up to 6-7 significant digits, double variables can hold decimal values with up to 15-16 significant digits. This makes them particularly useful in fields like science or complex algorithms where accuracy is paramount.
Boolean
Boolean data types are a highly efficient way to store binary values, taking up only one bit of information. This makes them an ideal choice for logical operations, such as comparisons or boolean logic.
Arduino programmers typically use the boolean data type in conditional statements like if-else or while loops to check whether a condition is true or false. By simplifying the code, it becomes easier to read and understand, allowing programmers to focus on the program’s logic.
Another obvious advantage is that it saves valuable memory space, which helps in embedded systems or microcontrollers like Arduino where resources are limited.
Byte
In Arduino, the byte data type is used to store a single 8-bit (1-byte) value that ranges from 0 to 255. This makes it ideal for use in projects that require minimal memory usage, such as LEDs. You can use a byte data type to indicate the brightness of each LED, for instance.
However, it’s important to keep in mind that accessing byte data types can be slower than other data types like int because the processor needs to access the entire byte even if you only need part of it. Additionally, adding two bytes together can result in unexpected outcomes if the sum exceeds 255, which causes the value to “wrap around” to 0.
To avoid this issue, consider using an unsigned char data type, which stores an 8-bit value from 0 to 255 without wrapping around. If you need to store a character value, a char data type is recommended as it stores a single 8-bit value.
Char
The char data type is a data type used to store a single character, like a letter or symbol. For example, if you wanted to store the letter “A”, you would use a char variable. Char variables are useful in text-based projects, such as printing messages to an LCD screen or reading input from a keypad.
Char data types can also store non-alphabetic characters, like punctuation marks or symbols. This makes them a versatile option for text manipulation. They are smaller in size than integer or float data types, making them ideal for embedded systems or projects with limited resources.
The char data type supports a wide range of operations, including concatenation and comparison. It can also be combined with other data types to create more complex data structures, such as arrays or strings.
Char data types use ASCII encoding, which can be a limitation for internationalization or projects requiring multi-byte character support. However, for most applications, char data types are an efficient and straightforward option for working with text in Arduino projects.

©Dimanet123/CC BY-SA 4.0 – License
Word
You may find yourself needing to store integer values that are too large for the standard integer data types. In such a case the word data type would be the ideal choice.
A word data type can hold values from 0 to 65,535, making it an excellent choice for larger character sets that require more space. For example, if you’re working with Unicode characters or other extended character sets, you may need to use a word variable to store the values.
Word variables can also store larger integer values that don’t require as much precision as double or float variables. This makes them a great option for dealing with numbers that fall within the word data type’s range but aren’t necessary for extremely precise calculations.
Custom Arduino Data Types
In addition to the standard data types mentioned above, there are also custom data types available for more complex applications.
Struct
If you have experience with C or C++, you’ll notice that Arduino borrows this data type from these languages. The struct data type is a collection of variables of different data types that are grouped together under a single name. Structs (structures) are useful when you need to store related pieces of data in a single unit. For example, if you are working with GPS data, you can use a struct to store latitude, longitude, altitude, and other related information.
Here’s an example:
struct GPSData {
float latitude;
float longitude;
};
You can then declare a variable of this struct data type and access its individual variables using dot notation, like so:
GPSData myGPS;
myGPS.latitude = 37.7749;
myGPS.longitude = -122.4194;
Do keep in mind that structs are not the only way to group variables in a program, and they have limitations. For instance, structs cannot contain functions, and they do not provide encapsulation of data, unlike classes.
Class
A class is a user-defined data type that contains variables and functions. It is a more advanced data type than a struct and brings the power of OOP through concepts such as encapsulation, inheritance, and polymorphism to Arduino. Classes are useful when you need to group related variables and functions together.
As in most other languages, classes extend libraries that provide additional functionality to the standard Arduino programming environment. A good example of this is the SoftwareSerial library, which provides a way to create serial connections on any digital pin of the Arduino.
Arduino supports classes through the use of C++ syntax. A class definition specifies the data members and functions that the class contains.
Here’s an example:
class MyClass {
public: int myInt;
void myFunction();
};
The function can be defined outside of the class definition like any other function. When using a class, you of course must create an instance of the class as you would in C++ or other OOP languages like Python.
MyClass myObject;
In this example, we have created an instance of the MyClass class called myObject.
Enum
An enum too is a user-defined data type that assigns names to a set of integer values. Borrowed from C++ as you can probably tell, this data type makes your code more readable and easier to maintain.
An enum data type is used to define a set of named constants. Enums (enumerations) are useful when you need to work with a limited set of values, such as days of the week, directions, or states. By using enum constants instead of hardcoding values, your code becomes more readable and easier to maintain.
An example of an enum for days of the week:
enum DaysOfWeek {
Sunday,
Monday,
Wednesday,
Monday,
Thursday,
Friday,
Saturday
};
By default, the first value is assigned the integer value of 0, the second value is assigned the integer value of 1, and so on.
To use this enum, you would declare a variable of type “DaysOfWeek” like so:
DaysOfWeek today = Friday;
Typedef
In Arduino programming, you can create an alias for an existing data type using a typedef. This comes in handy when you want to simplify complex or lengthy data type names, or when you want to make your code more readable.
To define a typedef, use the keyword “typedef” followed by the existing data type and the new alias name. For example, you can create a typedef for the long data type as follows:
typedef long int32_t;
After defining a typedef, you can use the new alias name instead of the original data type name in your code. For instance, you can declare a variable named “myLongVariable” of type int32_t and assign a value to it like this:
int32_t myLongVariable = 123456789;
Typedefs are especially useful in large and complex programs, as they can help reduce code complexity and improve code readability. However, keep in mind that using too many typedefs can also make code harder to understand, so use them judiciously.
Arduino Data Types Compared to Other Languages
Arduino uses C/C++ as its programming language. As such, many of the data types used in Arduino are the same as those used in these languages as we’ve seen. However, Arduino does provide some additional data types such as byte which are specific to the microcontroller environment.
Arduino data types are designed to be user-friendly and work seamlessly with the hardware. The int data type, for instance, represents a signed integer value that is only 16 bits in size. It’s a popular choice in Arduino since it can represent a wide range of values and is efficient to use on the microcontroller hardware.
Compared to languages like C++, Arduino has fewer data types and lacks some of the advanced features of C++, such as templates and namespaces. This makes Arduino more memory-efficient, simpler and more accessible for beginners.
Arduino Data Types: Summing Up
Nailing down the intricacies of Arduino data types would go a long way in helping anyone tackle even advanced projects confidently. Choosing the appropriate data types for your variables and functions could help reduce memory usage and improve your program’s overall performance.
By getting a good grip on the different data types, you’ll have a better understanding of how your program works, what kind of results it will produce, and an easier time debugging for hobbyists, students, and professionals alike.