Skip to main content

The Arduino Language

· 3 min read
Software Engineer

Abstract. This article gives a bried overview of the Arduino language along with links to various resources and reference data.

Note

This article is part a series of notes I prepared for UCF mechanical and aerospace senior design students for the summer 2020 semester. I have chosen to publish the contents here in the hopes that it might be useful for students beyond a single semester.

This article was originally published May 30, 2017 on my previous site. It was republished on June 21, 2020 with some updates to increase its relevance for student senior design teams.

The Arduino language is basically just C++ with some Arduino-specific functionality thrown on top of it and some other extra features taken out. For simplicity it is very similar to C and as long as you don't get into any object-oriented programming (OOP), knowledge of C is more or less compatible with Arduino.

Variables and Types

Variables in Arduino are more or less the same as they are in C or C++. If unfamiliar with programming and what a variable is in the context of computer science, it is not all that different from the concept of a variable in mathematics; a variable is simply something that represents something else (e.g. x=3x = 3 or π=3.14159\pi = 3.14159).

Variables in software however can represent more than just numbers. You can have a variable called name represent the data "Josh". As such, variable have data types associated with them. Computers aren't always very smart, so when you declare a variable, you have to tell the Arduino what type of data that variable will hold. Here's an (but certainly not an all-inclusive) example:

int x = 3;                  // x is an integer
unsigned int y = 42; // y is an unsigned integer
float e = 2.71; // e is a floating point number
double pi = 3.14159; // pi is a double precision number

For more on variables and data types, take a look at these tuorials from Arduino and SparkFun.

Conditions and Branching

Conditions, also called Boolean Expressions, are expressions that are either true or false. By checking if a condition is true or false, we can make our program do different things under various conditions or inputs.

The Comparison Operators, (==, <, >, <=, >=, !=), can be used to compare values. The Boolean Operators, or logical operators (&&, ||, !) can be used to logically combine conditions.

Control Structures such as if and if/else are used to make the program do different things based on conditions.

Loops

One of the things that makes computers so useful is the ability to do things over-and-over very fast. Loops are how we make a computer (or in this case a microcontroller) do that. There are two main types of loops:

  • for loops are typically used when you know how many times you want the loop to happen.
  • while loops are good when you want to keep doing something (or not doing something) while some condition is true.