Introduction to Microcontrollers (Arduino)

Introduction to Microcontrollers (Arduino)


Microcontrollers #

Microcontrollers are all around you. They are inside many of the devices that you use in your everyday life. They come in many shapes and sizes, but generally look something like this:

ATMega328

ATMega328p microcontroller Image by oomlout CC BY-SA 2.0

Or nowadays most likely more like this:

ATMega328 SMD

ATMega328p microcontroller Image by oomlout CC BY-SA 2.0

…or like this

RP2040

Raspberry Pi RP2040 microcontroller. Image by Raspberry Pi Foundation CC BY-SA 4.0

Microcontrollers are essentially small computers built into one single chip. You can connect input and output devices to them. You can also program them to do specific things with those input and output devices. Microcontrollers are used when you need a small, low-power device to read data from sensors or to control some output devices.

Microcontrollers Used in This Course #

Over the years we have used differnet types of microcontrollers, generally some variation of the Arduino boards.

Note that microcontrollers and microprocessors are two different things. Microprocessor is the CPU that you have inside your laptop or desktop computer.

For example, Raspberry Pi computers use microprocessors not microcontrollers, but the Raspberry Pi company also makes a microcontroller called RP2040 and the Raspberry Pi Pico microcontroller board.

Raspberry Pi Pico 2 W #

In the 2025 Physical Computing course, we use this microcontroller:

Pico 2W

The Raspberry Pi Pico 2 W is a low-cost microcontroller from the makers of Rasberry Pi. It uses the RP2350 microcontroller that has a wide variety of features and an additonal chip for wireless communication (WiFI and Bluetooth).

Arduino Uno R4 WiFi #

In the 2024 Physical Computing course, we use this microcontroller:

Arduino Uno R4 WiFi

The board that you have in your kit is called Arduino Uno R4 WiFi and it’s the one that we are mainly going to use for everything in this class. You might also want to use some other boards depending on the requirements of your final project.

Arduino Uno R3 #

Arduino Uno

Arduino Uno R3 is the basic model of the Arduino that is based on the ATMega328 8-bit microcontroller. The ATMega328 is quite old and not really recommended to be used on any new designs anymore. There are many newer and more powerful microcontrollers available, but it is still very good place to start with for the following reasons:

  • It is quite robust and durable, it’s not very easy to break one (compared to many of the newer models).
  • If you manage to burn or otherwise break the microcontroller chip, it can be easily replaced without soldering.
  • So many of the examples you find online will be based on the Uno so it is going to be easier to start learning with it.
  • Most of the code that you will create during this class will not be anywhere near hitting the limits of the Uno R3/ATMega328.

Arduino RP2040 Connect #

Arduino RP2040 Connect

The other microcontroller we have quite many of is the Arduino RP2040 Connect. It’s a much more powerful microcontroller than the Uno. It also has two built-in sensors (IMU, microphone) as well as a wireless chip that supports WiFi and Bluetooth.

Please be very careful with these boards! There are two things that can fairly easily break on them.

Arduino RP2040 Connect

  1. The USB connector. Always unplug your USB cable from the board when you pack it up into your kit. Also be careful not to drop the board with the USB cable connected to it.
  2. The antenna. The antenna is very fragile and can also snap off quite easily if you drop the board or otherwise hit the antenna.

Features:

Time Before Arduino #

Before the Arduino boards came along, there were many attempts at creating simple (and not so simple) development boards for microcontrollers that could be used in education and prototyping. Some examples:

Quite many of these were/are quite hard to start working with and none of them were able to become as ubiquitous in the educational/hobbyist/art/design world as the Arduino boards and all the thousands of variations and clones based on the Arduino have. Things started to change around 2003 because of a project called Wiring.

Wiring, 2003 #

Arduino is based on a project called Wiring originally created by Hernando Barragán as his Master’s Thesis project at Interaction Design Institute Ivrea (IDII) in Italy in 2003. You can read the thesis here. The thesis has a nice benchmarking section that looks into some of the options that were available at the time.

The way Wiring worked and how the software looked like was based on Processing. The attempt was to create an environment for working with microcontrollers, physical computing, electronics and programming that would be easily approached by beginners and non-engineers. Just like Processing was attempting to do for programming in 2001.

Hernando Barragán has never been properly (or enough) credited for his work in making the Arduino what it is now so I feel that it is important that I highlight his work here on this page. See below for an interesting text on the history of Arduino.

Arduino #

Arduino Documentary, 2010.

Arduino was created in 2005 as a fork of the Wiring project based on a cheaper microcontroller. The original team behind the Arduino project was:

  • Massimo Banzi (thesis advisor for the Wiring thesis by Hernando Barragán)
  • David Cuartielles
  • Tom Igoe
  • David Mellis
  • (Gianluca Martino) not officially mentioned anymore on the Arduino website, see below to learn why not.

Arduino means multiple things:

  • Arduino, the company that designs and manufactures the Arduino boards, maintains the software, and creates educational content
  • Arduino IDE (open source development tool for writing code and uploading it to your microcontroller)
  • Arduino Language (not really a programming language but rather a collection of functions and classes written in C++)
  • Arduino is also a collection of open source development boards built around different microcontrollers. These boards have unique names like Uno, Nano, MKR 1000 WiFI, RP2040 Connect etc.) Arduino has become in some ways a general term like tupperware to describe a microcontoller.
  • …and a couple of other things, but this is enough for now

You don’t need to use the Arduino IDE or even the Arduino functions to program an Arduino board. You also don’t need to have a board made by Arduino to use the Arduino IDE.

You can use boards made by other manufacturers or you can even make your own boards! The IDE and the code works for many other boards and microcontrollers as well.

This all seems very confusing, but don’t worry. Things will slowly start to make sense.

The Drama #

You wouldn’t think that there could be a lot of interesting controversy in the world of open source electronics, but just like anything that turns into a multimillion business, there will be people fighting for the money and the fame. There was a very strange but interesting legal battle that happened between 2015–2017. Take a look at the following articles, if you have a couple of hours to spend on digging through the drama:

In 2025, Qualcomm bought Arduino, it is quite uncertain still what that will mean to the Arduino project and the open source side.

Arduino IDE #

The Arduino IDE is a code editor and a toolchain for uploading code to various microcontrollers.

Arduino IDE 1.8.19

Arduino IDE 2.0

The old and new version look slightly different but the code will be the same. You can also use the older version of the software if you want/need to.


Raspberry Pi Pico #

In the 2025 class, we use the Raspberry Pi Pico 2 W boards.

Programming the Pico #

The Pico boards can be programmed in multiple ways:

  • Python
    • MicroPython
    • CircuitPyhon. An alternative version of python for microcontrollers maintained by Adafruit. It includes many libraries for sensors and other components that we commonly use in this class. If you wish to use python, I would recommend CircuitPython for our use case.
  • C++
    • You can use the standard C++ libraries from Raspberry Pi
    • Or you can use the Arduino libraries using Arduino-Pico. This is what we will use in this course!

Why C++ and not Python? #

Mainly because of two reasons:

  • Our introductory programming classes use either Processing (Java) or p5.js (JavaScript) which are very very similar to using the Arduino libraries in C++.
  • C++ is faster (although we rarely run into the speed limits of either language)

Arduino-Pico #

Although we use the Pico boards, we are going to program them using the Arduino IDE instead of Python. This is done with the help of a great project by Earle F. Philhower, III . It is called Arduino-Pico and it essentially provides the support for dozens of microcontroller boards based on the Raspberry Pi chips RP2040 and RP2350 chips.

Installing Arduino-Pico #

  1. Download and install the Arduino IDE
  2. Open the software
  3. Open the Settings/Preferences. And click the icn at the end of the field Additional boards manager URLs Boards Manager Button
  4. Paste the following to the pop-up window: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json Boards Manager Filled
  5. Hit ok to close and confirm
  6. Go to the Boards Manager and search for `pico``
  7. Find the option called Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower, III from the search results and install it. Boards Manager Filled

Example done in class #

Class Example

Class Example

Class Example

Class Example

The code below includes the light sensor as well, we did not get so far with our example.

int button;
int light;
int brightness;
void setup() {
  // put your setup code here, to run once:
  pinMode(15,OUTPUT);
  pinMode(16,INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  // read the button
  button = digitalRead(16);

  // read the light level
  light = analogRead(A0);
  Serial.print("light level: ");
  Serial.println(light);

  // map the light level (0,1023) to a value suitable for the LED (0-255)
  brightness = map(light,0,1023,0,255);
  Serial.print("LED: ");
  Serial.println(brightness);

  // only turn on the light if the button is pressed
  if(button==HIGH){
    analogWrite(15,brightness);
  }else{
    digitalWrite(15,LOW);
  }
  // small delay to not send too much data over the serial port
  delay(10);
}
}

Actual Class Example Code (Thursday) #

This is how far we hot actually last time. This code does not have the light sensor.

int button;
int light;
int brightness;
void setup() {
  // put your setup code here, to run once:
  pinMode(15,OUTPUT);
  pinMode(16,INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  // read the button
  button = digitalRead(16);

  // only turn on the light if the button is pressed
  if(button==HIGH){
    analogWrite(15,255);
  }else{
    digitalWrite(15,LOW);
  }
  // small delay to not send too much data over the serial port
  delay(10);
}

Arduino Basics