Intro to Arduino

Table of Contents

  1. Why this Learning Series?
  2. Arduino Uno R3 vs. Arduino Leonardo
  3. Arduino uses C++
  4. Intro to Output
  5. Intro to Input

Welcome πŸ‘‹ to the second module in your Physical Computing journey: Introduction to Microcontrollers using Arduino. Here, you will learn about digital output, analog output, digital input, and analog input and build interesting musical instruments along the way from a button piano to a Jedi-force instrument! Get started with our first lesson: L1: Turning on an LED and start building! βš’πŸ› 

New to this interactive textbook? While you can start here (with learning Arduino, woohoo! πŸ₯³), we highly recommend completing Intro to Electronics first. We frequently build on fundamental concepts from that moduleβ€”like voltage, current, resistance, and circuit analysisβ€”without re-explaining them here.

Why this Learning Series?

There are many Arduino resources online, many good, some bad. Our two favorites are, perhaps, Adafruit’s 18-Step Guide and Jeremy Blum’s Exploring Arduino: Tools and Techniques for Engineering Wizardry, 2nd Edition, Wiley, 2020. See our Resources page for more.

Our lessons are different both in approach and scope. They are based on years of experience in teaching physical computingβ€”to design students, computer scientists, and engineers at the undergraduate and graduate levelβ€”and we attempt to address common confusions head-on.

Thus, while other resources start with digital/analog input (or quickly intermix input and output), we’ve found that it’s easier to start with output. For novices, input is simply harderβ€”it requires an understanding (or at least an awareness) of concepts like pull-down resistors, voltage dividers, and that a microcontroller reads voltages rather than current or resistance.

So, our lessons start and stick with output to solidify understanding of how to programmatically control microcontroller pins before adding in inputβ€”where the fun, of course, really starts! Moreover, most resourcesβ€”at least those we are aware ofβ€”strike a different balance between depth and breadth. We love Adafruit’s tutorials but they tend towards step-by-step construction recipes rather than explaining why or how things work. As a college-level resource, we attempt to provide a deeper understanding at a cost of complexity and longer lessons. But we think it’s worth it.

Arduino Uno R3 vs. Arduino Leonardo

For this introductory lesson series, we use two of the most popular 5V Arduino models: the Arduino Uno Rev3 and the Arduino Leonardo; however, the lessons themselves should translate to almost any Arduino boardβ€”which is the beauty of the Arduino hardware-software ecosystem!

Image showing both the Arduino Uno and the Arduino Leonardo

Both the Uno and Leonardo have similar form factors, memory, clock speeds (16MHz), and GPIO pins (20 digital I/O pins); however, there are some differences:

  • The Uno uses the ATmega328P microcontroller while the Leonardo uses the ATmega32u4

  • The Leonardo’s ATmega32u4 has built-in USB support whereas the Uno actually has a second microcontroller (the ATmega16U2) to provide USB communication. On the Uno, pins 0 and 1 are used to communicate with the 16u2 co-processor, which can conflict with components plugged into those pins (so our examples will often avoid using pins 0 or 1, even on the Leonardo)

  • Because the Leonardo natively supports USB, it can be mounted as a Human Interface Device (HID) and thus used as a mouse, keyboard, or joystick.

  • The Leonardo has 12 analog inputs vs. the Uno’s 6

  • The Uno has series reverse-polarity protection on its barrel jack, which drops the voltage by ~0.7V but safely protects the board if a power supply is plugged in backward. The Leonardo wires the barrel jack directly to VIN (no voltage drop, better for high-current loads like servos) but uses a parallel shunt diode for protection. If you plug an unprotected battery pack into the Leonardo backward, it will likely destroy the diode and the board. See Reverse Polarity Protection: Uno vs. Leonardo.

A Note on the Arduino Uno R4 Released in June 2023, the Arduino Uno R4 (available in β€œMinima” and β€œWiFi” versions) is a significant hardware leap from the R3 while maintaining the same physical footprint and 5V operating voltage. It upgrades from an 8-bit AVR chip to a 32-bit ARM Cortex-M4 microcontroller, boasting a 48 MHz clock speed (3x faster), vastly expanded memory (256 kB Flash, 32 kB SRAM), a modern USB-C connector, and a true built-in DAC for actual analog output. Because it maintains backward compatibility, the code and concepts in these lessons translate perfectly to the R4!

In the lessons themselves, we’ll mark specific differences between the Uno and Leonardo, when relevant.

Arduino uses C++

Before we begin, a note about Arduino’s programming language.

Arduino programsβ€”aka β€œsketches” in Arduino parlanceβ€”are written in standard C++ (which inherently supports C). When you compile a sketch, the Arduino IDE processes the code and feeds it to a standard GNU C++ compiler (such as avr-g++ for traditional AVR boards or an ARM equivalent for newer ones).

What is often referred to as the β€œArduino language” is simply C++ combined with the Arduino core libraries. These libraries provide the built-in functions (like digitalWrite(), analogRead(), etc.) and the hidden main() function that calls your setup() and loop(), abstracting away the raw microcontroller register manipulations.

Programming background In our lessons, it’s helpful to have some programming experience, especially with a typed, compiled language like C++, Java, C#; however, it is not absolutely necessary. The programming requirements in the intro lessons are relatively minor though you should know how to use loops, conditionals, functions, variables, and more. As we move to the more advanced lessons, we expect stronger programming background.

Now, let the fun begin! πŸš€πŸ₯³

Intro to Output

🚦 Start Here! We highly recommend completing the Output lessons first to build a solid foundation before moving on to the Input series. We’ve learned from years of teaching this material that output is easier to start with than input!

In the Output lesson series, you will learn how to programmatically control Arduino’s GPIO pins to drive LEDs, produce colors with RGB LEDs, generate sounds with piezo buzzers, and build your first C++ class. Topics include digital output (digitalWrite), debugging with Serial.print, analog output (analogWrite and PWM), sound generation (tone), current sourcing vs. sinking, and multi-rate blinking without delay().

All Arduino code is open source and in this GitHub repository.

Start the Output lessons β†’

Intro to Input

In the Input lesson series, you will learn about digital and analog input using buttons, potentiometers, and force-sensitive resistors. You’ll build musical instruments along the wayβ€”from a button piano to a Jedi-force instrument!

Start the Input lessons β†’


This website was developed by Professor Jon E. Froehlich and the Makeability Lab using Just the Docs. If you found the website useful or use it in your teaching, we'd love to hear from you: jonf@cs.uw.edu. This website and all code is open source (website GitHub, Arduino GitHub, p5js GitHub). You can find the MakeabilityLab_Arduino_Library here. Found an error? File a GitHub Issue.

Made with β™‘ by the The Makeability Lab logo which is a large geometric M with an embedded L