paint-brush
Arduino UNO Board: Under The Hoodby@dilpreet
222 reads

Arduino UNO Board: Under The Hood

by Dilpreet LuthraNovember 27th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Arduino UNO is an open-source microcontroller board developed by Arduino. This article gives you a complete description of the very famous Arduino. The article discusses the hardware technicalities and programming of the board. It is inexpensive and easy to use. One can make a wide range of projects using the Arduino platform. The Arduino board takes the input from the devices like switches, sensors, etc. and the output is obtained based on the code uploaded on the board. At the end of the article I have demonstrated the working of the UNO board with a simple example of LED control.

Company Mentioned

Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - Arduino UNO Board: Under The Hood
Dilpreet Luthra HackerNoon profile picture

This article gives you a complete description of the very famous Arduino UNO board. The article discusses the hardware technicalities and programming of the board. If you are a beginner then, you may find this article very useful.

Arduino UNO is an open-source microcontroller board developed by Arduino. cc. Arduino UNO board is a mini-computer that gives a controlled output when provided with some input. One can make a wide range of projects using the Arduino platform. It is inexpensive and easy to use. In order to obtain more out of the Arduino platform, you just need to be familiar with the basics of C or C++ and the basics of circuit connections. You can use the Arduino IDE (Integrated Development Environment) for writing the code for your project and upload it on the board using the same. The Arduino board takes the input from the devices like switches, sensors, etc. and the output is obtained based on the code uploaded on the board.

Below I have given a brief description of Arduino UNO hardware and software. Also, at the end of the article, I have demonstrated the working of the UNO board with a simple example of LED control.

Hardware description

Microcontroller on the board

Arduino UNO boards have the famous ATmega328P installed on it which is an 8-bit Atmel AVR microcontroller based on RISC architecture. It has 32 KB of flash memory where the program gets stored and out of this 32 KB, 0.5 KB is used by the bootloader. Besides this, it has 2KB SRAM and 1 KB EEPROM. ATmega328P has 32 general-purpose registers out of which 31 registers are directly connected to the arithmetic logic unit(ALU). This makes these microcontrollers code efficient and 10 times faster than conventional CISC microcontrollers. It has a clock speed of 16MHz.

Pinout

In order to make proper circuit connections, you need to understand the purpose of each pin. Arduino UNO board has 14 digital pins, 6 analog pins, a power jack, a USB connection, and an ICSP header. These pins allow us to connect the board with different sensors, keypads, LEDs, and more. The pins of the Arduino UNO board can be categorized into 3 classes:

  1. Power Pins:
    Barrel Jack: Arduino board can be powered by connecting the barrel jack to the DC power supply. Usually, barrel jacks are connected to the wall adapter. It is recommended by the manufacturer to use a voltage supply of 7–12 Volts. The voltage supply lower than 7 Volts might not be sufficient and above 12 Volts might overheat the voltage regulators on the board.

    VIN: This pin is used to power up the board using an external power source like a battery. The voltage range should be between 7–12 Volts.

    USB: Using a USB cable the board can be connected to the computers. It provides 5 Volts at 500 mA. Using a USB cable you can burn your program on the microcontroller.

    3.3 Volts and 5 Volts: These pins provide a regulated supply to power external components.

    GND: Ground pins

    RESET
  2. IN Analog Pins:
    Pin A0 to A5 are the analog input pins. These pins read the analog input. But in order to perform further operations, these analog inputs should be converted into bits so that microcontroller can understand it. This conversion of the analog input to bits is done by ADC (analog to digital converter). In the Arduino UNO board, the input analog voltage can be represented in a 10-bit format that implies 2¹⁰ = 1024 levels.
  3. I/O Digital Pins:
    Arduino board has 14 digital input-output pins starting from 0 to 13. These pins are capable of reading only two states HIGH(1 or high voltage) or LOW (0 or low voltage). Among these pins, pin 3, 5, 6, 9, 10, and 11 are capable of performing Pulse Width Modulation.
  4. Pulse-width modulation is a modulating technique where messages are converted into pulses. PWM involves two components, frequency, and duty cycle. Frequency determines the number of times the signal fluctuates in a unit time period. The duty cycle determines how long the pulse remains in the HIGH state. The PWM is basically used to control the speed of the DC motor and to control the dimming of LEDs.

    Pin 13 is connected to the LED in-built on the board.

    Pin 2 and 3 can be used to trigger external interrupt INT0 and INT1.

    Arduino UNO has 6 ICSP header pins. ICSP stands for In-circuit serial programming and is used to program Arduino board’s firmware. Also, it has 1 AREF pin.

Communication

Arduino boards can communicate serially with computers and other Arduino boards (not specifically UNO). Atmega328P provides UART TTL which is available in digital pins 0 (receiving pin or RX) and 1 (transmitting pin or TX) for serial communication. In serial communication, data of 1-bit size is transmitted and received at a time.

Communication can also be established via USB cable. The Arduino board has TX and RX which flashes when data is transmitted and received via USB connection only.

ATmega328P also supports I2C and SPI communication

Software Description

Arduino IDE

Arduino Integrated Development Environment is a software where you can write the code and upload it on your Arduino board. It can be used in Windows, Linux, and Mac operating systems. The environment supports both C and C++ programming languages. Before programming, you need to select which Arduino board are you using in your project. The main code
of the Arduino project is called the sketch. Whenever you compile the sketch a .hex file generated. This .hex file is then uploaded to the microcontroller on the board.

In the above image, you can see the six options that Arduino IDE provides:

  1. VERIFY — Once you have written your code press this button. It will compile your code and will give information about errors in the program.
  2. UPLOAD — After connecting your Arduino board to the computer via USB cable, press this button to upload the program on the microcontroller.
  3. NEW — Press this to create a new sketch.
  4. OPEN — Press this to open the existing sketch or example programs.
  5. SAVE — Press this to save your sketch.
  6. SERIAL MONITOR — Useful for sending data from the Arduino to the PC for debugging purposes.

A basic Arduino sketch has two functions: void setup() and void loop().

Under the void setup(), you need to write the code that you want to run only once as soon as the program starts running. Below is two basic functions that are often used under in setup() function:

  • begin() — Sets the data rate in bits per second (baud) for serial data transmission and initializes the device. For communicating with the computer, use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. This function can be used to set up serial monitor, LCD, etc. Example: Serial.begin(), lcd.begin().
  • pinMode(pin, mode) — Using this you can set pins to INPUT or OUTPUT mode. Example: pinMode(8, OUTPUT)

Under the void loop(), you need to write the program that you want to run as long as there is no interruption. Below are some basic functions that are often used under in loop() function:

  • analogRead() — for reading the status of analog pins
  • digitalRead() — for reading the status of digital pins.
  • digitalWrite() — for setting the pin to either HIGH or LOW.

You can also use arithmetic operators, comparison operators, boolean operators, bitwise operators, and compound operators as per your requirement. The syntax is very much like C++.

EXAMPLE: LED CONTROL

Now, for a better understanding, I am going to make a simple project with the Arduino UNO board. Any Arduino project involves three things:

  1. Make circuit connection.
  2. Write a program for the circuit functionality.
  3. Burn (upload) the program on the board.

Circuit

I have used the Proteus simulation software for the project simulation. In the above circuit, the digital pin 3 is connected to LED and in between, there is a resistor of 330 ohms. When using the simulation tool there is no need to connect the VIN and GND pin of the Arduino UNO board. But the same is not applicable when making physical connections.

Now, we need to write the program as per the above connection. Suppose we want to make the LED blink continuously at an interval of 1sec.

Code

In the above code, you can see that in the setup function I have set pin 3 as the output pin and its state is continuously being toggled at an interval of 1sec in the loop function.

Output

In the above image, LED glows for the first 1 sec.

In the above image, LED does not glow for the next 1 sec.

Conclusion

In this article, we discussed the Arduino UNO board, how to use Arduino IDE for programming it and lastly, we made a simple LED control project.