Arduino Getting Started
Abstract. This article introduces Arduino and microcontroller concepts. The primary purpose of this article is to provide links to existing resources rather than writing a new tutorial. This is a summary microcontrollers that links back to resources I've found useful.
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.
A variation of this article was originally published May 30, 2017 on a previous iteration of my website. It was republished on June 21, 2020 with some updates to increase its relevance for student senior design teams.
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.
- The microcontroller is the part that actually does the computing. It's typically the biggest IC on the board. To learn more about a given microcontroller, lookup the datasheet.
- The Digital I/O Pins, or digital input/output pins, are the pins used to send or receive digital signals. A digital signal is different from an analog signal in that is is either on or off and has no values in between. To learn more about digital vs. analog checkout this Sparkfun tutorial.
- PWM, or pulse-width modulation, pins are digital pins that support PWM. PWM is a technique that allows you to use digital signals to simulate analog signals. This is useful for controlling motors or changing the brightness of a light. SparkFun has a tutorial on PWM here.
- The analog pins are only for input and are great for sensors. Realize that because the microcontroller itself is a digital system these analog signals get converted to discrete digital values. This means that, while the input is an analog signal, the Arduino can only read it in discrete increments based on its resolution. Checkout this tutorial from SparkFun on analog to digital conversion.
- Pay careful attention to the current and voltage specs. Brush up on electric circuits and power and make sure your project is designed to work within the Arduino's limits.
- Flash Memory is where the program you write gets stored. You don't store data here.
- EEPROM can be used to store a small amount of data.
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:
- 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.
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!