Back to Posts Download PDF

The Bare Minimum: Arduino

by Josh Kaplan, May 30, 2017

As an undergraduate, I remember many occasions where I needed to become proficient in a topic as a step to achieving some further goal. It still happens to me today and I see it happening to my students. This post on Arduino is for people in that situation. You need to build the skill, but diving deep into it isn’t your priority and you just want to learn enough to get by for now. With that in mind, this post deliberately glosses over many of the details, but tries to provide links wherever possible to allow to dive deeper on the topics that either don’t quite sink in right away or that you want to learn more about.

A Quick Overview of Arduino

An Arduino is a microcontroller board. In simple terms, think of it as a computer that only runs a single program. There are a lot of different Arduino boards (here), but some of the common ones are the Uno, the Nano, and the Mega. The biggest difference you’ll for most of these is the number of pins they have available.

Arduino Hardware

Different Arduino boards have different capabilities. Take a look at the Technical Specs to get a brief overviews.

Arduino Software

An Arduino program is structured like this:

void setup 
{
    // Insert setup code here
}

void loop 
{
    // Insert loop code here
}

Where the code in setup runs once, when the board is powered on and the code in loop runs over-and-over (after setup) as long as the board remains powered on.

A Basic Arduino Program

The Arduino Uno (and some others) has a built-in LED connected to pin 13. This means if you turn on pin 13 (have power going to it) the LED will be lit. Turn off the pin (remove power) and the LED will turn off. The blinking LED is the Hello World of Arduino. It’s how you know every is working (check out this tutorial.

/**
 * blink.ino
 *
 * Makes the built-in LED blink.
 */

void setup() 
{
    pinMode(13, OUTPUT);
}

void loop() 
{
    digitalWrite(13, HIGH);   // turn the LED on 
    delay(1000);              // wait 1000 milliseconds 
    digitalWrite(13, LOW);    // turn the LED off
    delay(1000);              // wait 1000 milliseconds 
}

The Arduino Language

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. or ).

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:

Diving Deeper

This was just a brief overview to get you started with Arduino and, hopefully, there are enough links and resources to give you some areas to dive a little deeper. In case you’re looking for more or want some more guided tutorials here are a few more resources to get you started:

Enjoy!