Arduino Basics: Variables
Table of Contents
Variables are used to store data in your Arduino programs. They hold values that can be numbers, characters, or true/false states, and can be used throughout your sketch.
Common Variable Types
int: Stores whole numbers (e.g., 0, 42, -10).
float: Stores decimal numbers (e.g., 3.14, -0.5).
char: Stores a single character (e.g., 'A', 'z').
boolean: Stores true or false values (true or false).
Declaring and Updating Variables
Declare a variable by specifying its type and name:
int ledPin = 13; float temperature = 25.5; char grade = 'A'; boolean isOn = true;
Update a variable by assigning a new value:
ledPin = 12; temperature = 30.2; isOn = false;
Variables can be used in calculations, conditions, and to control hardware pins.