Introduction to Arduino

Hey guys! My name is Hannah Lerner and I am a rising junior studying computer science at the University of Massachusetts, Amherst. This summer I am working as a software engineering intern at Viasat Inc. While my current work is focused on encryption and artificial intelligence, I have always had a soft spot for hardware integration.

Last year I participated in the HackHer413 hackathon and built an Arduino-powered musical glove. This glove could play a variety of customizable notes when you touched your finger tips together. It was a super fun project and ended up winning the best hardware hack prize! Today I’m hoping to give you a basic introduction to one of my favorite hacking devices! There are a wide range of choices for making a hardware project, but I personally prefer Arduino devices. Arduinos are helpful as they will provide us with a simple interface to connect hardware and software.

Prerequisites

x1 Arduino board (preferably an Arduino Uno)

x1 breadboard

x1 black solid core wire (jumper wires also work well)

x1 red solid core wire (jumper wires also work well)

x1 LED

x1 resister (150 ohm— 300 ohm should work well)

x1 Arduino button (really any simple button should work here)

x1 2–3" solid core wire (not red or black)

x2 1/2" solid core wires (any color but red/black. Use the same color wire)

Breadboard Layout

Before we start building a circuit, we first need to understand how a breadboard works. Below I have added a diagram of a basic breadboard. In this, all of the connected boxes share electrical connectivity. The most important part to understand is that the power and ground strips go down the board vertically while the rest of the pins go horizontally.

Building Initial Circuit

Now that we’ve gotten that out of the way, we can start building out circuit! First, we will want to plug in the black cord to the Arduino pin that says “GND”. We will then want to connect the other end of the black wire to the column in the bread board that has a black line next to it. Similarly for the red wire, we will plug one end into the 5V pin, and the other end into the column in the bread board with a red line along it.

LED and Resistor

Next, we will add in the LED and resistor! to start, we will want to place one end of the resistor into the ground column. The other end can go in one of the main pin ports. From there, we will place the LED such that the two pins are going into two different rows (mine for example go into row 6 and 7). In this circuit it does not matter what direction the LED is pointing, but if you want to have multiple LEDs in a chain, they all need to be facing the same direction. See here for more information on LEDs in series and here for information on how to know the value of a resistor.

Button

After we add in the LED and resistor, we can add in the button. The button I chose to use was just a basic button that comes in most Arduino starter kits. This part is a little tricky as there is a correct configuration for the button, but it isn’t obvious at first. When you are placing the button make sure the sides with the legs attached are in 2 different rows like with the LED. for simplicity, I suggest using wires to connect the button to the rest of the circuit. Place one wire from one side of the button to the closest side of the LED as shown below. Place the other wire on the other side of the button and have its other side go to the power strip.

Once this is done you should have a basic circuit ready to go! test it now to see if the LED turns on when you press the button!

Here I have set up a basic LED circuit. While there is no real software component to it yet, it shows how we can move some power through the board to hardware elements.

It works!

Building Digital Pin Circuit

Now we’re going to make a circuit that can blink without needing to press a button to turn it on! First we will want to set up a new circuit. This circuit is basically the same as the one we have built, but we can remove the red wire, the two small wires, and the button. We then want to add a longer wire from the end of the LED to a digital pin. For this example, I have chosen to place the wire in pin 7.

The Code

Now that our new circuit is setup, we can start working with the Arduino IDE! First you will see that we have two functions: setup and loop. All programs made for Arduinos need to use these two functions. The setup function is used to initialize any pins you want to use as well as any global variables you want to declare. The loop function is where most of the functional code will be. The function acts as an infinite loop.

To make a blinking light circuit we will need to understand 3 primary functions: pinMode, digitalWrite, delay.

pinMode()

pinMode(pin_number, IN_OR_OUT) is a built-in Arduino function that lets us decide whether we want the pin we name (in pin number) to be used as an input (where we can read information from it), or an output (where we can write information to it). For the circuit I’m using, I decided to use pin 7. Since I want to write to it I set the pin mode to OUTPUT. The pin mode can only be INPUT or OUTPUT.

digitalWrite()

Before we get into digitalWrite, we first need to understand an important note about the pins on our board. There are two different kinds of pins that we can write to! The first type is a digital pin. A digital pin only has two settings: on and off. The actual mechanism to turn it on or off is just how much voltage is sent through that pin (HIGH would correspond to 5V generally and LOW to 0V). The other type of pin is known as an analog pin. These pins can have a variable voltage from 0–5V. you can tell which pins on the board are analog by looking for an “A” before the number. While both of these pins are very useful, we will be focusing on the digital pin for today.

digitalWrite(pin_number, VALUE) is another built-in Arduino function that lets us decide whether or not we want a pin to be on or off. Similarly to the pinMode function, we will want to name the pin that we wish to modify (7 in this case) and decide if we want to set the value to HIGH or LOW. Like I mentioned in the previous paragraph, a HIGH value will correspond to 5V going through the pin (or 3.3V on certain boards), and a LOW value will correspond to 0V going through the pin. In the case of this board, setting pin 7 to HIGH will turn on the LED!

delay()

The final function is the delay function; another built in. It functions similarly to other languages in temporarily stopping the program from running. delay is measured in milliseconds.

With these three functions in mind, we are ready to write our program! I have provided some basic blinking light code below, but feel free to try whatever patterns you want!

I hope this helped you guys get the feel of the board! Good luck hacking!

HackHer413

A hackathon for women (cis and trans) and non-binary students hosted at the University of Massachusettes, Amherst to encourage, empower, and motivate students to become involved in tech-related fields and explore a new spark of interest in innovation.

Hannah Lerner

Written by

HackHer413

A hackathon for women (cis and trans) and non-binary students hosted at the University of Massachusettes, Amherst to encourage, empower, and motivate students to become involved in tech-related fields and explore a new spark of interest in innovation.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade