Vidyasagar Academy Wishes a Very Happy, Healthy & Prosperous Diwali to all our Students & Teachers!
- Basics of Arduino Coding
- How to use Android Phone to write codes and upload in Arduino?
- Effective coding techniques in Arduino: More about datatypes
- Effective coding techniques in Arduino: More about variables
- How to design Cathode Ray Oscilloscope using Arduino? Code of just 9 lines!
- How to start learning NodeMCU in simple steps? Basic Tutorial on NodeMCU
- How to use array to rotate servo motor in different angles?
- Blinking LED code for Arduino in Assembly Language Programming (ALP)
- Having trouble to drive Servo motor with Arduino Uno SMD? Get perfect solution now…
In programming, datatype is a classification which specifies which type of value a variable is assigned with and what type of mathematical, relational or logical operations can be applied to it.
Some of the datatypes regularly used in Arduino are given below. The chart shows the memory and range of the datatypes also.
About int datatype
Integers are the primary datatype for storage of numbers without decimal points and store a 16-bit value with a range of 32,767 to -32,768.
int variable_name = 1500; // declares 'variable_name' as an integer type
Note: Integer variables will roll over if forced past their maximum or minimum values by an assignment or comparison.
For example, if x = 32767 and a subsequent statement adds 1 to x, x = x + 1 or x++, x will then rollover and equal -32,768.
About long datatype
Extended size datatype for long integers, without decimal points, stored in a 32-bit value with a range of 2,147,483,647 to -2,147,483,648.
long variable_name = 90000; // declares 'variable_name' as a long type
About float datatype
It is a datatype used for floating-point numbers or numbers that have a decimal point. The floating point numbers have greater resolution and accuracy than integers and they are stored as 32-bit value with the range from 3.4028235E+38 to -3.4028235E+38.
float pi = 3.1415926; // declares pi' as floating-point type
Note: The floating-point numbers are not exact and may produce strange results when compared. Floating point math is also much slower than integer math while performing calculations.