Using a Microcontroller

What’s a Microcontroller?

A microcontroller is a small computer that can take in information from inputs such as sensors and switches and control outputs such as lights, motors and other computers. Microcontrollers are widely used in many different ways; DIY and robotics, art installations, industrial applications, and the internet of things.

When you are using a microcontroller, or in our case a microcontroller platform, there are two components: hardware and software. The hardware includes the microcontoller and its input and output pins, and any input or output devices you want to attach to it. The software is programs you write that control the microcontroller and the devices you have attached to it.

In this class we will be using the Arduino microcontroller platform. It was developed by a team of teachers to help their design students who were not engineers create physical interfaces.

intro-Arduino_Logo

The Arduino has an IDE, (integrated development environment), that is free and downloadable from the Arduino site (download it here). This is a set of software that allows you to write code, then upload it directly to the Arduino. The computers in the

Arduino Uno

There are many different versions of the Arduino but we will be using just one, the Arduino Uno. intro-uno-01-1

In order to program the Arduino, download the Arduino IDE and install it (detailed instructions on downloading and installing are here). The laptops we have in our Maker Space already have the software installed. Connect the Arduino to the computer with a USB A-B cable. If you have a newer Macintosh laptop, you will have to use an USB-C to USB adapter.

ch1-uno-usb-laptop-01

Parts of an Arduino Uno

Let’s look a bit more closely to the parts of the Arduino. We’ll look at the left side first.
ch1-uno-left-side-labelled-01

Reset Button: This button will restart the code currently uploaded on your Arduino. The reset button may be in a different location on your board than in this diagram, but it is the only button.

USB Port: The USB port takes a standard A-to-B USB cable, often seen on printers or other computer peripherals. The USB port serves two purposes: First, it is the cable connection to a computer which allows you to program the board. The USB cord will also provide power for the Arduino if you’re not using the power port (described below).

Voltage Regulator: The voltage regulator converts power plugged into the power port (described below) into the 5 volts and 1 amp standard used by the Arduino. BE CAREFUL! This component gets very hot.

Power Port: The power port includes a barrel-style connector which allows for either power straight from a wall source or from a battery. This power is used instead of the USB cable. The Arduino can take a wide range of voltages (5V – 20V) but will be damaged if power higher than that is connected.

Now let’s look at the rest of the board.

ch1-uno-right-side-labelled-01

Built-in LEDs: The LEDS indicate that there is power, and if your Arduino is sending or receiving data.

Digital I/O pins: The holes on this side of the board are called the digital input/output pins They are used to either sense the outside world (input) or control lights, sounds, or motors (output).

TX/RX pins: Pin 0 and Pin 1 are special pins labeled TX and RX. They control how information is transmitted to and from a computer. It is best not to use them empty.

ATmega328P, black chip: The black chip in the middle of the board is an ATmega328P. This is the “brains” of the Arduino: it interprets both the inputs / outputs and the programming code uploaded onto your Arduino.

Power and ground pins: All of the pins related to power are located here. You can use these pins to run power from your Arduino to your breadboard circuit.

Analog pins: These pins take sensor readings in a range of values (analog), rather than just sending whether something is just on or off (digital).

Settings in the software

We have seen a bit about the parts of the Arduino and we have seen that we program it through the Arduino software. Before we start programming the Arduino, we have to set a couple of settings in the software to ensure that the Arduino can communicate with your computer.

Load the Arduino software. Once it is loaded, go to the To do this, go to the Tools menu, select Board. From the fly out menu, select Arduino Uno/Genuino.

ch3-ide-select-board-screenshot-01

It is also necessary to specify a Serial Port for your Arduino to communicate with the computer. A Port is a channel of communication which connects your Arduino and the computer. On a Windows machine, go to the Tools Menu, select Port then select the COM port that is specified. It should look something like the screenshot below.
serial_com

Once you have connected the Arduino to the computer and set the version and the port, you are ready to start programming the Arduino.

Further reading/resources