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 could 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.

What Does This Mean to Me?

For a beginner, this means:

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: There are also other third-party, Arduino-based boards that are built by their own manufacturers, but normally, they have these things in common.

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 removable MCU chip. This way, you can replace that part once it’s either broken or worn down. Other boards have their MCU chips soldered to the board itself. The drawback there is obvious, but they’re usually made to be much 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. 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 DC barrel jack, but 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 are different, depending on the model. They may use Type-A, Type-B, USBmicro, or Type-C. You can power the board through these, and they also serve as communication ports.

Indicator LEDs

Lastly, there are typically three indicator LEDs that let you see the state of the board. The L and ON pins are self-explanatory. One is a built-in LED that you can control, while the other 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, partly because it’s easy, with everything you need there. You’re also 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: Normally, the building and uploading functions work 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 and don’t have to upload. The Arduino IDE can be downloaded through the Arduino website.

Blinking the built-in LED is the Arduino version of a “Hello World” script and is a simple way to test whether the Arduino is working. I’m demonstrating all the different ways to make it blink, including telling the computer that it’s already blinking.

We’re starting 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. Arduino code is usually divided into two parts: setup() and loop(). When you see setup(), you’re supposed to define your outputs and inputs. In this case, we are using pinMode() to turn the LED_BUILTIN pin into an output pin. The LED_BUILTIN pin is pin 13 and is directly connected to the L LED. It 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. setup() is discussed more in the next example. Here, everything starts from the first line within loop(), and the Arduino executes that line, then does the second one, then third, and so on, until it reaches the last line. It will then 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. 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 bringsLED_BUILTIN down 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 going back to the starting line again. It keeps lopping for as long as it’s connected to a power source.

This time, we’re playing around with setup() so that we can make the built-in LED quickly blink three times before blinking slowly every 0.5 seconds. The previous example talked about loop() and how it works. Let’s go back a bit and expand on setup(). Everything that you place in setup() runs once, just as the pre-written comment says. With this, you can make your Arduino do something to tell you that it’s going to start working. If you have an LCD, OLED, or AMOLED screen, you could even give it a fake loading animation! This is also where you’re supposed to start up special commands, like establishing communication through serial.

Example 3: Using Serial Communication

In contrast to a parallel communication, a serial communication sends data from the source to the destination one bit at a time. This time, Arduino will send some messages over serial to give you status updates. As software uses a console for debugging, you’re supposed to use Serial in hardware for the same thing. In setup(), you added the line Serial.begin(9600);. This tells Arduino to open a channel with the computer for serial communication. The number next to it shows how fast it should send data. The 9600 refers to 9600 baud. This means it’s going to send 9600 bits per second. Baud rates range from 300 to more than 2 million baud for the Arduino IDE. Smaller rates are better for longer wires (think telephone wires for distance), while larger ones are for shorter wires. 2 million bauds is overkill, though. In many cases, even 19200 bauds is more than enough for even the most sensitive hobbyist sensors. With that out of the way, let’s talk about Serial.println(); next. This command stands for “print, line new” and makes a new line after it prints what’s inside the () area. Serial.println() accepts either strings or variables that contain strings. It behaves oddly when you add numbers in them, especially if it starts with 0. If you look at your serial monitor’s results, you should also notice that it prints “Arduino, starting up!” only once. Meanwhile, “LED on” and “LED off” are repeatedly printed out every blink cycle. That’s the big difference between setup() and loop(). In fact, you can even put your code from setup() into loop(), but that’s usually bad practice. You may end up turning an input pin into an output pin, potentially breaking your microcontroller chip.

This helps very much. A for-loop lets you do a mini loop() that ends after a given number of times. Let’s try making complex blinking patterns with multiple for-loops. On first load, the LED should blink 13 times, on for 500ms and off for 250ms, and just once. Then it should loop, blink four times, on for 1000ms and off for 1000ms, then blink two more times, on for 500ms and off for 250ms. The for-loop is a simple, yet easy-to-learn tool. It has three parts: for, (int i = 0; i < x; i++), and whatever’s inside the { }.

for tells the Arduino IDE that it’s a for-loop function. There are many others, like while, if, and switch.(int i = 0; i < x; i++) is a condition. It says that while the integer i, which is 0, is below the value of x, then do i++ and execute the function. i++ is shorthand for i + 1. You can even replace it with i + x where “x” is any number or make it count down using the “-” operator.The { } contains everything the loop will do. It doesn’t need a ; in the end. You just leave it as is.

Conclusion

With this simple beginner’s guide to Arduino, you can start making your own custom light effects or maybe a fancy Christmas light. There’s more to learn, of course, but you’re better off learning as you go. You could try out motors, sensors, relays, and a bunch more! If you’re up for the challenge, you may want to program an Arduino using a Raspberry Pi.