Lecture slides and class recordings are available below.
Notice how this pinout diagram looks slightly different from the one in the lecture slides? Small differences in notation and labeling are common for pinout diagrams, so learning to spot them is important.
See how some of the pins are called IO# here instead of D#? That's another common prefix MCU documentation uses to refer to GPIO pins. There are also labels for the internal naming of each pin (like PCINT18 or ADC3); if you read the ATMega328P datasheet (it's only 300 pages!), it will use these more specific pin naming schemes instead of a simple D or A prefix.
What other differences do you spot between the two diagrams?
Different microcontroller platforms and companies will present their pinouts in different ways, so it's helpful to keep an open mind as you read documentation and try to spot the differences.
And, to be fair, sometimes documentation just sucks. As a good engineer, someday it'll be your job to make sure yours doesn't!
The Arduino Reference is your friend. Bookmark it; keep it open in a pinned tab; use it as you write code. In the real world, you'll often have reference materials to look at, and OPS is the same way (i.e., we're not going to make you memorize every Arduino function and code operator, and there will be no tests on this).
The Arduino platform makes embedded development (that's what working with MCUs is called) very friendly to beginners by providing functions that make doing common embedded tasks on an MCU easier. Rather than having to read the full microcontroller datasheet and know exactly what registers, memory locations, and bits you must access to control a certain feature (often called peripherals) on the MCU, you can simply call a function that does all of that for you.
This is commonly referred to as a Hardware Abstraction Layer, or HAL. These hardware abstraction functions include the ones we discussed in class like digitalWrite() and analogRead(). On the Arduino reference, you'll find explanations of every function, what arguments it takes (like pin numbers, INPUT/OUTPUT, HIGH/LOW, etc.), and example code for how to use that command in your Arduino sketch.
If you ever want to do "real" embedded development though, you must remember that the functions you'll learn on Arduino's don't exist out there in the big leagues. So, if you're feeling adventurous, try right clicking some of those functions (just put your text cursor on the function name itself) in the Arduino IDE and click "Go to Definition." This will take you to the internal Arduino files where the code for that function exists. Give it a read, maybe even ask your favorite AI program to summarize what each line in the function is doing if you get lost. That stuff is what "real" embedded C looks like. And if you ever take ECE 306, you'll learn all about it.
You'll need (at least) the following materials to complete this project with the minimum specs:
1x Arduino Nano (with USB cable)
1x Breadboard
1x 10kΩ Potentiometer
2x 470Ω Resistor (color bands: yellow, purple, brown)
2x LED of any color.
The LEDs in your kit are rated for an operating current of 20mA and must always be connected in series with a current limiting resistor.
Make sure you aren't using the clear IR LED from your kit; it's one of the two LEDs with longer legs (the black one is actually a photodiode). Infrared (IR) light isn't visible to us silly humans so you won't be able to tell when it's on!
(We'll be using the IR components in Project 3)
Jumper wires to connect everything up
470Ω Resistor
(Yellow, Purple, Brown)
Potentiometer
Make sure you connect your LED with the correct polarity or it won't light up! Remember: Diodes only allow current to flow in one direction, like a one-way valve.
There are two parts in the schematic above.
On the right side, you can see the potentiometer symbol with the two outer terminals connected to GND and 5V and the middle terminal connected to an analog input pin (A2). Make sure the middle terminal is not connected to 5V or GND!
This creates a voltage divider between 5V and GND, with Vout connected to the analog pin so we can read the position of the potentiometer (the output of the voltage divider) with analogRead(pot);.
On the left side, you can see the LED circuits consisting of two LEDs and resistors in series respectively. We call these current limiting resistors. They have two jobs to protect our circuit: they prevent us from drawing too much current from the MCU (pins 2 and 5 on the dev board), and they prevent us from putting too much current through either LED. Allowing too much current to flow through a component is a common way beginners (and experts!) accidentally kill their components, and can also damage the MCU.
Let's do some "napkin math" on a current limiting resistor to see what exactly is going on in the LED portion of our circuit:
When we turn an LED on (with digitalWrite([led pin], HIGH);) we'll have ~5V at the LED pin (and ~0V on that pin if we set the pin to LOW, turning the LED off). For circuit analysis, think of the pin as a node with a voltage on it.
We know that the full 5 volts will drop across the LED and resistor, because they're in series, and the other end of the two components is connected to the ground (GND) pin, and GND = 0V.
So we can use Ohm's Law to find the current going through both the resistor and the LED: 5V / 470Ω ≈ 0.0106A (or 10.6mA).
This works because, as you'll learn in ECE 200, we can assume LEDs have zero resistance (when they're turned on) for simple circuit analysis like this (although that's obviously not the case in reality, because physics!). So the only resistance we need to use in the Ohm's law equations is the current limiting resistor.
From our pinout diagram above (or the Arduino Nano's spec sheet), we know we shouldn't draw more than 20mA from any one pin, and we're drawing about half that, so our Arduino is safe.
And, from the LED specifications in our parts list, we know these LEDs are designed to operate at a max of 20mA. The LED will still light up, but not at it's full brightness—and it definitely won't have enough current going through it to burn it out.
You might've also noticed a few extra components floating around on the schematic. This is a reminder that OPS is an open project space; you're more than welcome to build additional features onto your projects. Add more LEDs (and current-limiting resistors!) to create a light pattern of your choice! You have all the parts (that we've covered so far) in your kit and all the programming knowledge you've learned at your disposal!
Reminder: The code projects / files we create in the Arduino IDE are called sketches and have a .ino file extension. In other software (like in ECE 209), you'll often only work with .c and .h files. We'll talk more about the differences later on.
You can download a copy of the pseudocode file here. You'll need to create a new folder for this project inside your Arduino sketches directory (see: how to find your Projects folder) and put the .ino file into that project folder.
Your program first needs to configure the pins you're using in your circuit correctly (this goes in setup()). You'll also need to start the Serial connection.
In each loop, you should take a reading from the potentiometer as an input (we gave you this line of code for free!). Then, if you like, do some math on that reading depending on the way you want to use it.
You need to write a blink function to do the following: toggle LED on, delay for some time, toggle LED off. We've given you the structure of this function in the pseudocode.
For the outputs of the program, your LEDs need to blink, alternating between one and the other being turned on (like a railroad crossing light).
OR you can use more LEDs and create your own pattern!
Something about how they switch on and off must be controlled by the potentiometer reading. This might be the delay between them toggling between each other, how long they stay on, or off, etc. Get creative!
You also need to print some value to the Serial monitor on your computer.
This might be the potentiometer value, your LED delay time, or maybe something else—as long as the output changes as you turn the potentiometer knob.
Below is the pseudocode for your project (to give you a general idea of what your Arduino sketch will look like):
e.g., #define redLED 2
Note: #define (and all # compiler directives) do not have a ; on the end!
This is a funky syntax difference you'll learn more about in ECE 209.
Serial.print(“Some statement to print to the serial monitor on your laptop”);
e.g.,
int x = 0;
x = analogRead(A2);
Reminder: There are 1000 milliseconds in 1 second
For a simple guide on how to connect and upload code to your Arduino, you can review the demo we did in the lecture video, or read step by step instructions from arduino.cc here.
When you first plug in your Arduino, some of the lights on the board should turn on and blink a few times.
This is caused by the startup sequence running on the MCU. At least one of them will stay on all the time—it's the one with "ON" or "POW" next to it, and means exactly what the label says; power is connected to the Arduino. (And the RX and TX LEDs blink when the serial interface is being used; we'll learn more about that later on).
The LED with a simple L next to it is called the User LED and is internally connected to digital pin 13 (through a current limiting resistor, of course) on the Nano's PCB. You can address it in your code with the LED_BUILTIN keyword (e.g., with digitalWrite(LED_BUILTIN, HIGH); or digitalWrite(13, HIGH);). You don't need to define LED_BUILTIN anywhere in your program like you do with other pins; the compiler already knows it's there.
This LED is a great tool for debugging if you want to test something without sending anything to the Serial monitor or connecting an external LED and resistor; all you need to do is blink it in some kind of identifiable pattern within your code. But remember, because this LED is always connected to pin 13, if you use pin 13 as an input, you won't be able to use that LED in your program anymore. And likewise, if you use pin 13 as an output, you can't draw as much current from that pin since the LED will also turn on whenever the pin is HIGH.
We know this might be a simple project for some; the goal here is to get used to using your Arduinos, the breadboards, and writing code in the Arduino IDE. As always with OPS, we want you to explore. Play with the code, try building different circuit with more LEDs and blinking them with different patterns (Knight Rider, anyone?), or open some of the example sketches (under File -> Examples -> Built-In Examples) and see if you can build those circuits.