Beginner’s Guide to Arduino
Whether you’re an embedded systems vet, high school scientist, or some curious cat from some human-filled continent, there’s always a place to start your electronic explorations. If it turns out the manual wasn’t enough, then check out this beginner’s guide to Arduino.
What’s an Arduino?
Arduino is a brand of open-source microcontroller boards developed by the Arduino company.
When you’re talking about the Arduino, it’s usually about the board. Arduino boards are special because they’re durable – they’re meant to be used by students (or anyone) who’d probably mess things up and break something.
The other thing that’s special about them is that they’re open-source. The datasheets for all Arduino boards and shields are available online. You can make your own Arduino board if you have the technical know-how.
So What Does This Mean to Me?
For a beginner, this means:
- You don’t need to make your own circuits to study microcontrollers.
- These boards come with safety features to keep you from breaking them accidentally.
- The open-source hardware community has made a wide array of boards for different purposes – there’s even one meant for putting electronics on clothes!
Anatomy of an Arduino Board
There are many kinds of Arduino boards. Some are as tiny as a battery while others are as big as a digital camera, but they all have a few parts in common:
- Microcontroller unit
- Header pins
- Power and USB ports
- Indicator LEDs
There are also other third-party, Arduino-based boards. Their own manufacturers make them, but normally have these things on them, too.
Microcontroller Unit (MCU)
The microcontroller unit, aka MCU, reads and controls all the inputs and outputs on the board. It also stores the user-made code that makes it do stuff.
The Arduino Uno R3 has a special MCU chip because it’s removable. This way, you can replace that part once it’s either broken or worn down. Other boards have their MCU chips soldered on the board itself. The drawback there is obvious, but they’re usually made to be way smaller and faster than their non-soldered counterparts.
Header Pins
To the sides, you should see some raised pieces of plastic with holes on top. They are female header pins – you’re supposed to put wires or male jumper pins in them.Arduino Uno pinout.
There are two kinds of pins: GPIO and power pins. GPIO pins let you process inputs and outputs. By default all Arduino pins are inputs. On the other hand, power pins are meant for moving electricity around the board. 5V and 3.3V always emit as much voltage as their name says. GND stands for “ground” and Vin lets you power the board through that pin.
Power and USB Ports
All Arduino boards typically have two types of ports: a USB port and a DC barrel jack. Some don’t have a DC barrel jack. They usually get their power from either the USB port or the power pins.
DC barrel jacks are typically sized as 2.1×5.5mm with the inside as positive and outside as negative. They’re designed to accept anything between 7 and 20 volts, but you’re better off sticking to 9 volts whenever possible.
USB ports come differently depending on the model. Some use Type-A, Type-B, USBmicro, or Type-C. You can power the board through these, and also serves as a communication port.
Indicator LEDs
Lastly, indicator LEDs let you see the state of the board. There are typically three of these:
- RX (Receive)
- TX (Transmit)
- L (LED Built-in)
- ON (Power On)
The L and ON pins are self-explanatory. One is a built-in LED that you can control while the other one turns on whenever electricity passes through the board. The first two, on the other hand, turn on whenever the Arduino receives or transmits information over serial communication.
Arduino IDE
Beginners should start with the Arduino IDE before moving to any other program, like PlatformIO. Part of it is because it’s easy. Everything you need is all over there. But it’s also because you’re less likely to mess things up if you use this. It’s made for Arduino boards, after all.
The Arduino IDE has three important functions:
- Editing
- Building
- Uploading
Normally, the building and uploading functions come hand-in-hand. As soon as you finish typing and editing your code, you can build it then upload everything straight to your board. But there are times when you only have to build it without uploading.
The Arduino IDE can be downloaded through the Arduino website.
Ways to Blink the Built-in LED
Blinking the built-in LED is the Arduino version of a “Hello World” script. This is a simple way to test if the Arduino is working. I’m going to show you all the different ways to make it blink, including telling the computer that it’s already blinking.
Example 1: Basic Blink
We’ll start with the basic blink script. You’ll just have to turn on the built-in LED for 0.5 seconds, then turn it off for another 0.5 seconds.
- Open your Arduino IDE.
- You should be greeted with a new sketch as soon as you open the IDE. If not, click on “File -> New” or press Ctrl + N.
- Replace the code on the IDE with the following code:
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
- Go to “Sketch -> Upload” or press Ctrl + U to upload your code to Arduino.
Arduino code is usually divided into two parts: setup()
and loop()
.
When you see setup()
, that’s where you’re supposed to define your outputs and inputs. In this case, we used pinMode()
to turn the LED_BUILTIN
pin into an output pin.
What’s the LED_BUILTIN
pin? That’s pin 13. This pin is directly connected to the L LED and will turn it on whenever it receives enough electricity to crank it to HIGH. You can even replace all instances of LED_BUILTIN
with 13
, and it will still work.
We’ll discuss setup()
more on the next example. For now, we’ll talk about loop()
. Here, everything starts from the first line within loop()
. The Arduino executes that line. Then it does the second one, then third, and so on until it reaches the last line. And then it’ll go back to the first line after that. That’s why it’s called a loop()
.
In this example, we used digitalWrite()
to power LED_BUILTIN
to HIGH
. This means that 5V of electricity passes through here. Then delay(500)
will temporarily stop the Arduino from reading more code for 500 milliseconds. After that, the Arduino runs the next line which bring down LED_BUILTIN
to LOW
.
It’s actually a loop of turning it on, waiting for half a second, turning it off, waiting for another half of a second, then starting from the starting line all over again. It keeps doing that for as long as it’s connected to a power source.
Read More: Beginner’s Guide to Arduino – Make Tech Easier