Back to Course

Arduino Programming using Arduino IDE

0% Complete
0/0 Steps
  1. Chapter-1->How to download Arduino IDE?
    3 Topics
    |
    1 Quiz
  2. Chapter-2-> Introduction to Arduino IDE
    3 Topics
    |
    1 Quiz
  3. Chapter-3–> How to connect any board with Arduino IDE?
    4 Topics
    |
    1 Quiz
  4. Chapter-4–>Steps to write a code in Arduino Programming
    5 Topics
    |
    1 Quiz
  5. Chapter-5–>Introduction to Arduino Uno
    5 Topics
    |
    1 Quiz
  6. Chapter-6–>Explanation of Variables and operators in programming
    5 Topics
    |
    1 Quiz
  7. Chapter-7–>How to use conditional statement and loops?
    6 Topics
    |
    1 Quiz
  8. Chapter-8–>How to use analog input in Arduino IDE ?
    6 Topics
    |
    1 Quiz
  9. Chapter-9–>How to add libraries in Arduino IDE ?
    6 Topics
    |
    1 Quiz
  10. Chapter-10–>How the Arduino Serial library performs serial communication?
    4 Topics
    |
    1 Quiz
  11. Chapter-11–>Interfacing of Dht11 sensor with Arduino
    4 Topics
    |
    1 Quiz
  12. Chapter-12–>Troubleshooting and Errors in Programming
    3 Topics
    |
    1 Quiz
  13. Assessment
    6 Topics
Lesson Progress
0% Complete

A variable is a value that can change depending on the conditions and the information in the computer program. Variable can store information like characteristics, number or quantity which can be measured or counted.

A variable can be thought of as a memory location that can hold values of a specific type. The value in a variable may change during the life of the program—hence the name “variable.”

Each variable has a specific data type, which indicates which type of data it may hold. For instance, a variable that holds text strings has the data type String and is called a string variable. A variable that holds integers (whole numbers) has the data type Integer and is called an integer variable.

When creating a variable, it is necessary to declare a data type it contains. A data types classifies that which type of value a variable has and what type of mathematical or logical operation can be applied without an error.

The most commonly used data types are:

  • int − Used to store an integer value.

  • char − Used to store a single character.

  • float − Used to store decimal numbers with single precision.

  • double − Used to store decimal numbers with double precision.

Below is table showing the different range and bytes of the data types used in programming: 

Data TypesBytesRange
short int2-32,768 to 32,767
unsigned short int20 to 65,535
unsigned int40 to 4,294,967,295
int4-2,147,483,648 to 2,147,483,647
long int4-2,147,483,648 to 2,147,483,647
unsigned long int40 to 4,294,967,295
signed char1-128 to 127
unsigned char10 to 255
float41.2E-38 to 3.4E+38
double82.3E-308 to 1.7E+308

The data types that hold numeric values are: byte, short, int, long, float and double. The difference between them is the size and precision of the value they contain.

How to declare a Variable?

The declaration of variable comprises of three parts :- first data type then the variable name and last the statement is terminated with a semicolon (;).

For example : int Name=10; 

In this example int is the integer data type and Name is the variable.

Note : This is a case sensitive programming so use the Name variable as you declared.

Example Code: 

#include <stdio.h>

int main() {

   // datatypes  

 int a = 10;

char b = ‘S’;  

 float c = 2.88;

 double d = 28.888;