What are Data Types ??
- If you recall your basic mathematics in which we have learned about sets like Whole Numbers, Natural Number, Prime Numbers etc.
- So, in simple words, Data Types are such sets, but Data Types are different on the nature of element storing in them.
- Data type is like a place, so when we initialize our variale then we tell our compiler that our newly introduced integer is of which type.
- Is it an integer or it has decimal as well in it or its some character like A, B, C etc.
- So, we have to tell our compiler the nature of our variable and that's where Data Types are required.
- So, that's a little Introduction of Data Types, now let's have a look at Arduino Data Types:
Arduino Data Types
- Arduino Data Types are almost similar to C++ Data Types because it roughly follows the same syntax.
- So, now I am gonna discuss the most commonly used Arduino Data Types one by one:
Int - Arduino Data Types
- Int is short form for Integer.
- This Arduino Data Types can store a data of 16 Bit.
- Int data ranges from -32,768 to 32767.
- In Arduino Programmer, Int variable in initialized in several ways, which are:
int Value = 0;
int Value1, Value2, Value3;
- You should read Arduino LED Example or How to write Arduino code where I have used the Int variable.
Char - Arduino Data Types
- char is short for character.
- This Arduino Data Type has a memory of 8 Bit or 1 byte.
- Char Data Type saves charracters like A, B, C etc.
- If you are initializing a single character then it will be in single quotes like 'A'.
- But if you are dealing with character Array then it must be enclosed in doule brackets like this "ABCD".
- When we save any character then in actual the ascii code of that character is being saved.
- For example if you save a character '1', then its not integer 1 it is a character '1' and its ascii value is 49.
- So, in that variable the value saved is 49.
- All the Serial Communication is done using this char Data Type.
- You should read How to do Arduino Serial Communication in which I have used this char variable.
Boolean - Arduino Data Types
- Boolean data type is also used quite a lot in Arduino Programming.
- Boolean is also of 8 Bit just like char and it can be either True or False, that's why we call it Boolean.
- So, we can initialize a Boolean variable as:
Float - Arduino Data Types
- Float is another very important Arduino Data type.
- The unique thing of Float Data Type is that we can store decimal numbers in it.
- For example I want to save 2.51 then I have to use Float because this value can't be save in Int or Char.