Learning Arduino: Arduino Tutorial for Beginners

Currently, electronic circuit design has taking a pronounced direction in the area of programmable logic devices or the use of Microcontroller units (MCU).  Non-programmable logic Integrated circuits are useful for their tasks, but when the tasks become too many, like in the design of robots, embedded systems, automation and control systems, etc, a different device that is capable of handling such tasks is needed, and that is where microcontrollers and microprocessors come into play. To mention programmable devices without mentioning Arduino will mean an offence to the tech community. Though not the only programmable logic device, we also have microcomputers also called single board computers, like the Raspberry Pi, etc.

Arduino is so popular that the name presently dominates comparatively in the realm of embedded system programming. Here, you’ll get all you need to learn arduino from scratch.

In this Arduino tutorial, we shall learn the following:

  • What is an arduino
  • Arduino Board Specifications
  • Getting started to learning arduino programming
  • Designing and programming our first circuit with Arduino board

Materials Used in this Arduino Tutorial:

For an electronic hobbyist to design a robot years back requires he or she uses a bunch of integrated circuits and some discrete components, but with a microcontroller unit like an Arduino board, designing a robot is easier, faster, requires few components and neater.

Arduino Ant hexapod robot
Fig 1. Arduino Ant hexapod robot (courtesy of howtomechatronics.com )
Arduino robot arm
Figure 2. Arduino robot arm (courtesy of howtomechatronics.com)

Figures one and two above, show robots designed and built with an Arduino Microcontroller Unit.

What is Arduino?

Arduino is an open-source electronics prototyping and computing platform based on a simple input/output (I/O) board.

What open source means is that everything about arduino is open and free to the public to modify and use, provided the user adheres to the user’s policies of arduino original makers. Both the hardware and software development environment are open source, you can build compatible hardware modules for the board, and add libraries to the software integrated development environment (IDE). That’s why you can find various arduino boards by various makers.

Arduino can be used to design a standalone project or an embedded system. It can also be connected to computer software like Makerplot, Processing, Matlab, etc. The board can be purchased as an already made module or assembled by parts by the designer. The Arduino free open source Integrated Development Environment (IDE), can be downloaded from www.arduino.cc.

Arduino boards are capable of taking in inputs from sensors, through its input channels, these inputs are converted to currents and voltages, it will then process this inputs using the program written to it and bring out output in form of currents and voltages. This outputted currents and voltages can be used to light up light emitting diodes (LEDs), display characters on a screen, converted into motion with the use of motors, send a message online, etc. A lot can be done with arduino as far as electronics is concerned. Progressively, we will be having arduino tutorials to design and implement various devices and systems.

Arduino boards that are not from the original markers (Arduino LLC) from Italy are sometimes referred to as “clones”. Although most of these boards look exactly like the original, but with experience and practice, you can spot the counterfeit. Some makers try to mimic the original boards verbatim in colour and parts, while some clones differentiate their boards openly. A good example of this is the Sparkfun Red Board, Sparkfun does not call their boards Arduino; they call it “RED BOARD”. And you will see their logo and name boldly printed on the boards. Again the microcontroller chip used in the Sparkfun RED BOARD is an SMD i.e. Surface Mount Device, unlike the Arduino UNO which can come in both plated-through-hole (PTH) and SMD. Most of these clones really serve well as the original arduino board, like the Sparkfun RedBoard which I have used in the past. However, some clone boards sometimes are not really very efficient. Some clones come in various colours while the Arduino board comes in mix of green and blue colour or the classic arduino teal.

Below is a typical Arduino UNO board:

Arduino Uno front view
Figure 3. Arduino Uno front view
Arduino UNO back view
Figure 4. Arduino UNO back view

Sparkfun RedBoard:

Sparkfun RedBoard back and front views
Figure 5. Sparkfun RedBoard back and front views

Some Arduino clones:

Yellow UNO Clone
Figure 6: Yellow UNO Clone
Orange UNO Clone
Figure 8: Orange UNO Clone
Blue UNO Clone
Figure 9: Blue UNO Clone
Black UNO Clone
Figure 10: Black UNO Clone

Arduino Board Specifications

Here, we are going to use the Arduino UNO R3 as a case study, because most of our projects in this arduino tutorial series will be done using the Arduino UNO R3. It should be noted that the Arduino Board had undergone revisions and upgrade. The first version was the Arduino UNO, the second version was the Arduino UNO R2 while the third version is the Arduino UNO R3 and the latest version of the Arduino UNO, the R means Revision, so we have Revision 2 and Revision 3.

Below is a breakdown of the Aduino UNO R3 Specifications:

Labelled diagram of an Arduino UNO R3
Figure 1: labelled diagram of an Arduino UNO R3

Arduino Hardware

Arduino BoardUNO R3
MicrocontrollerATmega328
Clock Speed16 MHz
Flash Memory32 KB (ATmega328) of which 0.5 is used by the bootloader
SRAM2 KB (ATmega328)
EEPROM1 KB (ATmega328)
Operating Voltage5V
Input Voltage (Recommended)7-12 Volts
Input Voltage (Limits)6Volts MIN, 20Volts MAX
Digital Input and Output (I/O) Pins14 (of which 6 pins can provide pulse width modulation (PWM) outputs)
Analog Input Pins6
Direct Current (DC) per I/O Pin40mA
Direct Current (DC) for 3.3V Pin50mA

ATmega328 microcontroller: The ATmega328 microcontroller is the brain of the Arduino board. Sometimes the board is referred to as Arduino microcontroller.

Power Supply/ USB Plug: To power the board, you either do so via the USB port (USB plug in the diagram) or through the Barrel Jack (Power supply in the diagram). The current supplied from the USB port of the PC is not really large, but it’s enough to blink LEDs, so, to power devices like motor, relays, etc, you need an external power supply unit.

Reset: Reset button and pin are used to reset the microcontroller

AREF: Analog Reference Pin offers reference voltage for analog input. By default, the reference voltage is from 0 to 5 volts.

Anolog pins: There are 6 analog input pins/ports, labelled A0 through A5. Each analog input pin provides 10 bits of resolution (i.e.1024 different values). By default they measure from ground to 5 volts. Some of the pins on Arduino UNO board can also be used for other specialized function.

Ground: Digital ground serves as the negative terminal of the board. There are many ground pins on the board abbreviated as GND.

Digital pins: There are 14 digital pins/ports (0 to 13) on the Arduino UNO. They all operate at 5V and can be used for input or output. Each pin can give or receive approximately 40mA of current. These pins can be used for both digital input (like telling if a button is pressed) and digital output (like supplying power to an LED) However, pins 0 and 1 can be configured to be used in receiving and transmitting serial data to peripheral device or computer.

ICSP: The in-circuit Serial Programmer ICSP is used to program another arduino or used to connect the arduino to a computer to upload a code especially when USB port is not available on the board.

Voltage in Pin: You can supply voltage to the Arduino from an external power source through this pin. Supplying voltage via the voltage in pin bypasses the regulator, and can damage your board, so, be careful when doing so. Recommended voltage to be supplied to this pin is just 5 volts.

5V Power pin: This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7-12V), the USB connector (5V), or the VIN pin of the board..

3V3 Power Pin: A 3.3V supply generated by the on-board regulator. Maximum current draw is 50 mA.

External Interrupts: pin-2 and pin-3 can be configured as external interrupt.

PWM:  The tilde symbol   ̴  found on the following pins 3, 5, 6, 9, 10 and 11 means they can be configured to produce Pulse width modulation (PWM) outputs.

SPI: This means Serial Peripheral interface.  Pin-10 (SS), pin-11 (MOSI), pin-12 (MISO), pin-13 (SCK) pins can be configured for serial communication using SPI protocol.

On board LED: An SMD-LED is connected to pin-13 of the board. When the pin has logic-high, the LED is ON, and when it is logic-low it is off.

Pin-A4 (SDA) and pin-A5 (SCL): these pins support TWI communication as well as I2C communication protocol. The pins are separate in the Sparkfun RedBoard. SDA means Serial Data while SCL means Serial clock.

Having had a comprehensive overview of the arduino hardware, it’s time to talk about the software. Let’s recall that the arduino platform is composed of two major parts, the hardware which we just treated and the software which is called the IDE or integrated development environment which is modelled after processing (check out www.processing.com). Arduino IDE is the software you install and run on your computer. You use the IDE to create what we call a sketch. Please note that the name given to Arduino source code or program is “sketch”. When you write this sketch in the arduino IDE with your computer, by clicking the upload button, the code or sketch is translated into C language and is passed to the Avr-gcc compiler which makes the final translation into the language understood by the microcontroller, and that his how you program the arduino microcontroller.

Arduino microcontroller comes with a pre-burned boot-loader, which allows the microcontroller to upload new code to it without the use of external hardware programmer.

Getting started with Learning Arduino Programming

Arduino programming language is based on wiring; wiring is based on C/C++. Arduino programming language is a simplified version of C/C++ programming languages. So, if you have smattering of C or C++ programming languages, to program arduino will be an easy task. But if you do not have such knowledge, don’t worry, arduino programming is very easy to learn. If you follow this tutorial, you will learn arduino programming.

Installing the Arduino IDE

To get started with learning arduino programming, you need to download and install the Arduino IDE.  Here are the steps:

  1. Visit the website arduino.cc/en/Main/Software to choose and download the compressed package (.zip file) based on your operating system (windows, Linux and Mac). I’m using windows OS, so I will give you a guide for windows operating system.
  2. After downloading the zip file navigate to the folder where you downloaded the “Arduino IDE.zip” file.
  3. Right-click on the .zip file and unzip the file using 7-zip or Winrar software if you have it in your system, and select Extract to “arduino-…”.
  4. Open the extracted folder. You can move this folder to a different location, if desired. A common place is to create a C:\Arduino folder.
  5. Double-click exe. The Arduino IDE opens.

You need to do one more thing, and that is to install the driver. The Original Arduino Uno R3 and some clones use the ATmega16U2 USB-to-Serial chip which has its driver included in the Arduino IDE .zip file you downloaded, hence installing the Arduino driver posses no challenges, all you need to do is locate the driver in the directory you saved it and update it. Below is the process of installing Arduino drivers for windows OS.

Installing Arduino UNO Driver in Windows OS

  1. Plug your arduino UNO into the computer using the USB cable. When the Found New Hardware Wizard window comes up, Windows will first try to find the driver on the Windows Update site.
  2. Click on the Start Menu on your computer, and open up the Control Panel. While in the Control Panel, navigate to System and Security.
  3. Click on System. Once the System window is up, open the Device Manager. Look under Ports (COM & LPT). You should see an open port named “Arduino UNO (COMxx)”. If there is no COM & LPT section, look under “Other Devices” for “Unknown Device”.Right click on the “Arduino UNO (COMxx)” port and choose the “Update Driver Software” option. Choose the “Browse my computer for Driver software” option.
  4. Navigate to and select the driver file named “arduino.inf”, located in the “Drivers” folder of the Arduino Software download (not the “FTDI USB Drivers” sub-directory). If you are using an old version of the IDE (1.0.3 or older), choose the Uno driver file named “Arduino UNO.inf” and Windows will finish up the driver installation from there.

NB: If you are using a sparkfun RedBoard which uses FTDI 231X USB-to-Serial chip that works with FTDI VCP drivers, you will have to download the driver separately and update it in your PC drivers’ database. Or if you are using some clone from China which has the CH304 USB-to-Serial chip you will have to download the driver and update it as well.

Just one more step and we start the programming!!

You need to know the COM port your board is connected in the PC. To do so, you have to have your arduino board connected to your PC, then go back to device manager, look through the existing COM ports, now unplug the arduino board from the PC, the COM port that disappeared is the COM port your arduino board is connected to.

If you don’t want to go through the process of downloading and installing The IDE on your PC, you can program your arduino online using the arduino web editor and create platform, click the link https://create.arduino.cc/editor

Circuit implementation (hardware and software)

Now we are ready to start the circuit programming, firstly, connect the circuit as shown below, this is the hardware part of the circuit implementation.

Arduino circuit connection on breadboard
Figure 13: Arduino circuit connection on breadboard

Your connection should look like the image shown above.

From the image above, pin 13 of the arduino board is connected to one leg of the resistor; the other leg of the resistor is connected to the anode leg of the LED (i.e. the long leg of the LED); the short leg of the LED (which is the cathode of the LED) is connected to the ground pin of the arduino board. Now the circuit is ready to be programmed.

Figure 14: Arduino circuit connection on breadboard
Figure 14: Arduino circuit connection on breadboard

After you have connected the circuit as shown above, the next action is to program it. Programming is the software part of the design.

Follow the steps to implement your first code (sketch):

  1. Open the Arduino IDE software on your PC. The image you will see is something like this:
Arduino IDE bare minimum sketch
Figure 14: Arduino IDE bare minimum sketch

Plug the arduino Uno board to your USB port as shown in the figure below

Arduino connection to PC
Figure 15: Arduino connection to PC

Check if your board is connected to the right COM port and if the arduino board you are using is what is already selected in the IDE. You can do so by clicking on tools, then place the mouse cursor on “port” you will see a drop-down of all the available COM ports; select the one your board is connected to (mine is COM 14 yours can be a different thing). Then place the cursor on “Board”, Board manager menu will appear, you will see a drop-down menu of various arduino boards, select the board you are using, in our case, we are using Arduino Uno. See the image below.

Checking for arduino board type
Figure 17: Checking for arduino board type

NB: The code in figure 14 is called a BareMinimum code. When you upload the code to your arduino board, it does nothing to the arduino, sometimes it is used to clear every other sketch previously uploaded to the board.

After the right COM port and arduino board have been selected, the next thing is to write your first code. Just like in other programming platforms, the first program for beginners is always a “Hello World”. In arduino, Hello World is simply writing a code that blinks an LED ( we can also use the arduino to write a code that can display “Hello World” message, we will treat that in the subsequent tutorials). One of the benefits of using arduino platform is the in-built example sketches. To open this sketch, follow the following steps:

  1. Open the IDE and click on File
  2. Select Examples
  3. Select Basics
  4. Select Blink

See the image below:

Selecting the blink sketch
Figure 18: Selecting the blink sketch

When you open the blink sketch, the image below is what you will see. Don’t be scared by the code, it’s a simple code, the code lines are explained in in the comment lines.

Figure 19: Blink Sketch

After the sketch is ready, you verify it first by clicking the verify button  located at the top left corner of the IDE.

If no errors were detected, you can then upload your code to the arduino board by clicking the upload button  also located at the top left corner of the IDE just after the verify button. As the code uploads, you will see some LEDs of the board flicker, after some seconds, the sketch will be done uploading, and you will see the LED connected to pin 13 and the LED on the board which is also connected to pin 13 of the board also blinking. It stays ON for 1 second and stays OFF for 1 second. It continues like this as long as the arduino board is powered either via the PC or external power supply or a battery.

In our next arduino tutorial, we will explain the various parts of an arduino code. Nevertheless, congratulations!! You’ve just built your first arduino circuit.

Summary

  • Arduino is an open-source electronics prototyping and computing platform based on a simple input/output (I/O) board.
  • It has hardware and software parts. The Hardware part requires the use of arduino board while the software requires an arduino integrated development environment IDE. There are many arduino boards; you just have to choose the one that serves the purpose of your design. There are in-built example codes or sketches you can implement in the IDE with little or no knowledge of programming.

Assignment

How can you make the LED connected to pin 13 blink faster?

Leave a Reply

Your email address will not be published. Required fields are marked *