Data Types in Arduino
Welcome back to my blog. We have described the previous articles as practical projects. But today’s article is theoretical. We have learned a piece of basic knowledge about Arduino from previous articles. Today we are going to talk about something that is most important for Arduino coding. It is Data types or variables. Do you remember we have used variables in the previous posts? today we’re going to talk about data types.
Supplies
What are Data types?
When we write codes, the data contained in them must be provided separately to the Arduino compiler. These data are called Data types. Arduino compiler is a program that translates the code we write into machine language so that it can be understood by the microcontroller. Machine language is a language that uses only 0 and 1. We do not understand this language. The code we write using the English language is translated into codes 0 and 1 by the compiler.
Ex: – 010001010101001
These codes are called binary codes. This process also occurs in other high-level languages. All data and programs in this microcontroller use this binary language. These binary codes have installed the register in the microcontroller.
What Is the Register?
A register is a part that installs a binary code. It is the hardware of the microcontroller. The registers have different bit sizes. Take a look at the 8-bit register below.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
0 | 0 | 1 | 0 | 1 | 1 | 0 | 0
The 8-bit register is 0-7. It can put eight values containing 0 or 1. The Arduino Uno board has an 8-bit register. This is not common for all microcontrollers. There are microcontrollers on the market that contain registers with different bits. The microcontroller includes two types of registers. That is a volatile memory register and a nonvolatile memory register. These data types are stored in volatile memory. The data in this memory is lost due to a power-off. When writing this code we have to work with different data types. Different names are used to identify these data types separately. These data types must be named before the code can be written. This is called a variable declaration. Okay, let’s look at the data types we use the most.
Have a good day
Boolean
It can be set to ‘true or false’, ‘high or low’, and ‘0 or 1’. This data type takes up 1 byte of memory.
Byte
We can use this data type if we want to store a value from 0-255. This datatype memory is 1 byte.
Char
This data type can only store characters. It is a number, a letter, or a symbol. It is a 1-byte memory.
Double
We can use this datatype for decimal numbers. This datatype memory is a 4 byte.
Int
This data type is the most used. Its data range is -32 768 to +32 767. This datatype memory is a 2-byte.
Long
This data type can be used to store long data. Its range is -2 147 483 648 to +2 147 483 647. The Memory is a 4 byte.
String
Words can be stored in this data type. For example “sritu hobby”.
Void
This data type is used for function definitions.
So, today we have learned many data types that are used in Arduino coding. These data types are included in other programming languages as well. The Arduino language is created using high-level languages C and C ++. I hope you have learned about data types through this post. We will meet in the next post.