Lesson 1 – Control the Blink!
I figured we should start our journey going over many components commonly used and to get our feet wet with some cool projects. My goal here is to go beyond just simply wiring diagrams and code snippets, but to get into a level deeper on what is actually happening and how it is all working. Let’s get started!
Lesson Overview
In this lesson we will control 2 LEDs (light-emitting diodes). We will control whether the LED is on or off from a button push and the other LED we will control the brightness of the LED with something called a potentiometer (sometimes called a trimpot or thumbpot or even just a pot).
Parts Needed
You may be better off buying a complete kit as opposed to individual parts. If you already have an Arduino Uno, this kit will provide the majority of the parts we will use for the lessons in the Arduino crash course. If you don’t have an Arduino Uno yet, then this kit (with a clone version of the Arduino Uno), is a great starter kit and you can use all the parts through this Arduino crash course. Elegoo is a very reputable supplier of parts. I have bought many of their parts over the years, and never had a single issue.
- Arduino Uno
- 2 220-ohm resistors
- 1 SPST button (Single Pole, Single Throw)
- 1 Potentiometer
- 2 LEDs (any color will be fine, but don’t use an RGB LED)
- Wires (dupont connectors wires are most commonly used)
- Bread Board – optional but extremely helpful for all prototyping
Parts Explained
Arduino – all the lessons in this Arduino course will be using an Arduino board, so I will just go into explanation of what the Arduino is in this first lesson. Arduino is the blanket term for the open-hardware (Arduino boards) and open-software (Arduino IDE) solution. Because it has become super popular, and the fact that it’s an open hardware, there are many clones available on the market, and for the most part all act the same. The Arduino Uno contains an Microchip ATmega328 microcontroller, which is an 8-bit microcontroller with many key features that allow it to be very versatile (including 23 GPIO pins, 6 PWM channels, 10-bit ADC, and interfaces to the most common communication protocols which will all be covered in future lessons). I do recommend just looking at the microcontroller datasheet and try to see how many things you understand at this point (http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf). Once you are done with all the lessons, revisit this datasheet and see how much you have learned and picked up with just these tutorials.
220-Ohm Resistor – A resistor is one of the most prevalent and important components for circuits and for good reason. Resistance is the 3rd major factor in Ohm’s Law (more on this below).
SPST Button – A button is one of the easiest interfaces to allow user input to control some sort of output. A single pole, single throw simply means single input and a single output. If you think about the button being in the OFF state when it is not pressed on. When the button is pushed, it connects the the pin(s) and completes the circuit. When the button is not pushed, the circuit is broken and does not flow to the output. Note: do not get confused if your button has 4 pins, it can still be a SPST button. most SPST buttons available in the market and especially ones that come in Arduino kits will have the proper spacing to sit between the center and straddle the 2 strips allowing you to connect have the input and the output on different lines of a breadboard. As you would imagine, we will be using this button in our lesson to complete a circuit to an LED via a resistor to light up the LED when pushed.
Potentiometer – This common component allows user input to change the resistance into a circuit. As someone turns a potentiometer clockwise, it will increase the resistance to the output. A potentiometer can be used for many applications. Here we will be using it to control the brightness of an LED by increasing/(decreasing) the resistance to lower/(higher) the brightness of the LED. In more technical words, we will be resisting more or less current into the LED. Too much resistance, and the LED will not light up. On the flip side, 0 resistance, the LED will be the brightest.
LEDs – Light emitting diodes are no doubt fun. They also provide some output to the end user for things such as status (how many gadgets do you have that have some sort of light to represent that it is on?). A diode in general is an electrical component that conducts electricity in one direction. Other diodes are used to protect components from backwards current flow. An LED (as well as most other diodes) have an anode (positive lead – power source) and a cathode (negative lead – to ground).
Wires – wires are simply ways to allow electricity to flow through the circuit and connect components together. Since wires are just carriers of electricity, you want a wire to be a great conductor and to have as close to 0 resistance as possible. A dupont connector (in particular male-to-male) are very common when prototyping with Arduino. Female dupont connectors are also popular when dealing with other quick prototyping systems (such as raspberry pi).
Breadboard – although optional, it definitely makes prototyping significantly easier by allowing you to place components directly onto the breadboard, and then connect wires in the other available ports on the same line. Most breadboards have a power strip along the sides to allow quick access to positive (5v for Arduino Uno) and ground rails. Most breadboards are split into at least 2 parts where each line is connected (through internal conductor) so each hole in that row will be connected the the other holes within same row and part.
Ohm’s Law
The first major thing to truly understand in doing any electronics project is Ohm’s Law. The three main components of electricity are Voltage (V, although sometimes referenced as E) measure in Volts (V), Current (I) measured in Amps (A), and resistance (R) measured in Ohms (Ω). Quite simply Ohm’s Law is as follows:
V=IR
This means that voltage = current times resistance.
Resistor Calculation for This Project
If you bought a specific LED, always check the datasheet for max current draw and forward voltage. If you bought a bunch of LEDs in a kit without any documentation, there is a good chance that it will follow these characteristics.
To fully understand why we are using the 220Ω resistor in this project. Most of the common 5mm LEDs on the market, have max current (I) of 20mA (milliAmps, this is equivalent to .02A).
The forward voltage of an LED (the voltage needed for the electricity to flow through the Diode) is based on the color spectrum (more specifically the material the LED is made out of to make the color). Typical forward voltage by color are:
| Color | Forward Voltage |
| Red | 1.8V |
| Orange | 2.0V |
| Yellow | 2.2V |
| Green | 3.5V |
| Blue | 3.6V |
| White | 4.0V |
So now we know the forward voltage and the initial voltage (5V for Arduino) and we know that the typical LED will draw a max of 20mA. So if we algebraically work with Ohm’s Law we have the following calculation for the min resistance we need to not burn out the LED:
R = (5 - 4) / .02 = 50Ω for white R = (5 - 3.6) / .02 = 70Ω for blue R = (5 - 3.5) / .02 = 75Ω for green R = (5 - 2.2) / .02 = 140Ω for yellow R = (5 - 2.0) / .02 = 150Ω for orange R = (5 - 1.8) / .02 = 160Ω for red
Keep in mind, is calculation for the lowest resistor value we should use to not damage the LED. So 220Ω will give us a bright LED while still giving room for some tolerances on both the resistor, input voltage, and the LED itself.
Try it yourself!
So we calculated these values based off the Arduino voltage source of 5V, but what resistance values should we use if we had a 12V power source instead of a 5V source? Should our resistance increase or decrease? Do some of the calculations yourself and see if the result matches what you would have expected.
Let’s Build
Finally, let’s get to building our project. Here is a drawing of the connections to this lesson:

There are a couple things wrong with this wiring diagram that I want you to try to figure out. If you wired this up this way, it will not work (hint: remember LEDs are diodes and diodes will only allow current to flow from the anode to the cathode).
Hopefully you were able to recognize that the LEDs themselves are actually flipped (anode is incorrectly connected to the ground, and cathode is incorrectly connected to the power source). There is a minor change for the push button that should be done as well. Since we are using an SPST button, 2 of the pins are always connected together and the other 2 pins are connected if the button is pushed. When dealing with buttons, it’s always advisable to connect to the pin diagonally from your first connection, as that will almost always guarantee your circuit is not continuing on unless the button is pushed.
We will start on the left side. You will see that GPIO pin 9 from the Arduino is connected to one of the pins of the push button. What we should do is take the corner of that button and connect the resistor to (what should be) anode of the LED (the longer leg). The shorter leg can then be connected to the ground (the ground is connected to the Arduino GND pin as well to form a common Ground). On the right side, we have the left pin of the potentiometer connected to GPIO 8 of the Arduino, middle connected to ground, and the 3rd pin connected to the resistor which is then connected to the (what should be) anode of the other LED. Finally the cathode of that LED is also connected to the common ground.
Note: Please be careful with connecting the LEDs and ensure the polarity is correct (source -> anode -> cathode -> ground). If it is reversed, it could potentially damage the LED.
Great! All Wired up, Let’s Code!
For coding for this lesson (and all other lessons in this Arduino crash course), we will be using the Arduino IDE. You can install it from here. They now even have a web IDE (although I have never used that). While it’s downloading/installing, you should read some introduction to the IDE just to get a feel for the software and how to use it to program your Arduino.
Since this is the first lesson, I will just supply the code and describe it line by line. In future lessons, I may only provide snippets or may just describe what the code should do and have you give it a go on your own (the only way to truly understand something is to actually work through it, not by copying and pasting).
void setup() { // the setup function runs once when you press reset or power the board
pinMode(9, OUTPUT); // initializes digital pin 9 as an output.
pinMode(8, OUTPUT); // initializes digital pin 8 as an output.
digitalWrite(9, HIGH); // sends power along the wire connected to pin 9 (the potentiometer)
digitalWrite(8, HIGH); // sends power along the wire connected to pin 8 (the button)
}
void loop() { // the loop function runs over and over again forever, but nothing to do here
}
That’s it?!?! Yeap, that is all that is needed for this example. Arduino libraries do a lot of abstracting away (and we may uncover some of those layers in future lessons), but let’s see what we are actually doing here.
pinMode – this function call takes the pin number (8 and 9 for our wiring), and tells the microcontroller that this is an output pin. That is, I want to turn on and off this pin whenever I want and control this pin.
digitalWrite – this function takes a pin that has already been defined by pinMode, and a value of either HIGH or LOW (this is encapsulation within Arduino itself with a #define in one of the core libraries). When we set the pin high, we are basically telling the microcontroller to set the voltage of the pin to a high state (5V in Arduino case). This will then in essence turn on the circuitry connected to the that pin as it is now “attached” to the circuit. When we set the pin LOW (go ahead and try it), we are telling the microcontroller to set the voltage of the pin to Ground (i.e. 0V), therefore shutting down the circuit that it is connected to.
As you will see, each Arduino sketch we make will have a setup() and a loop() function that we need to define. You can view the setup function as everything that needs to get done and initialized before hitting the main processing. Setup is called just once each time the system gains power. The loop function is the function that will continuously be called forever as the board holds power. We could have certainly thrown our digitalWrite functional calls in the loop, but it is unnecessary as we are only setting the voltage once and letting our components handle the LEDs.
Now to what’s happening. The LED connected to the button should be off. But if you press the button, you should see the LED stay lit for as long as you press it. This is because, as stated before, the pushing of the button is actually pushing down a conductor connecting the 2 sides together, thus allowing the circuit to continue on to the resistor and then the LED.
On the potentiometer side, depending on the initial state of the potentiometer, you should see either a very faint LED (or maybe even off) or a bright one. But as you turn the potentiometer, you should see the brightness of the LED follows. This is happening because when you turn clockwise, the resistance is increasing. More resistance to the LED means dimmer light. Conversely, turning the potentiometer counter-clockwise will reduce the overall resistance of the LED, causing it to have more power and allowing it to be brighter.
What’s Next
Play around with your wiring and the code. Maybe change the GPIO pin that these things are connected to? How would the code change? How would you change the wiring if you wanted the button to control the potentiometer circuit as well? Where should the button be placed and how do you order your components so you have a push button to allow the light to turn on, and also a potentiometer to control the brightness of the LED? Play around with the digitalWrite function. Can you write code that turns the LEDs (even if button is pushed) for 5 seconds, then enables it for 5 seconds and repeats (hint: https://www.arduino.cc/reference/en/language/functions/time/delay/)? While you are looking at that documentation for delay, preview the documentation for digitalWrite and pinMode (and peruse some more of the related functions). The power of Arduino is in the community that supports it, the amazing documentation, and the flexibility and power of being able to conquer projects even beyond basic hobbyist projects such as this.
2 thoughts on “Arduino Crash Course – Lesson 1”