Learn electronics, coding, and projects — step by step.

Arduino Basics: Variables

George Bantique October 4, 2025 No Comments

What are variables in Arduino programming?

Variables are containers used to store data in your program — such as numbers, characters, or logical values. They let your code remember and manipulate information while the sketch runs.

What types of variables are commonly used?

Arduino supports several data types for different kinds of information:

  • int – stores whole numbers, usually from -32,768 to 32,767.
  • float – stores decimal numbers, like 3.14 or -0.25.
  • char – stores a single character, such as 'A' or '5'.
  • boolean – stores true or false values for logic decisions.

How do I declare and use variables?

To declare a variable, specify its type followed by a name. You can assign a value immediately or later in the program.

int ledPin = 13;   // declare and assign
float voltage = 3.3;
boolean isOn = false;

Once declared, you can update a variable’s value as your program runs:

isOn = true;       // update value
voltage = voltage + 0.1;

Why are variables important?

Variables make your code flexible and dynamic. Instead of using fixed values, you can store readings, counts, or states — allowing your Arduino to react to inputs, sensors, and conditions.

×

Leave a Reply

Required fields are marked *






Related Articles: (by Categories)