Arduino — Introduction to Pins


The Arduino Uno is one of the most popular microcontroller boards used for a variety of purposes — from basic DIY projects to complex robotics. In this blog, we’ll be taking a closer look at the Arduino hardware, and more specifically, the Arduino Uno pinout. The Arduino Uno pinout consists of 14 digital input/output pins, 6 analog inputs, a power jack, USB connection and a ICSP header. The versatility of the pinout provides applications of many different options such as driving motors, LEDs, reading sensors and more.

Image for post

Let’s look at the different pins on the Arduino and their functionalities:

Power

The Arduino Uno can be powered via the USB connection or with an external power supply. The Arduino can input and output analog signals as well as digital signals. The recommended range is 7 to 12 volts.

Following are the power pins:

VIN — The pin is used to supply an input voltage to the Arduino board when it’s using an external power source

5V — This pin outputs a regulated 5V from the regulator on the board.

GND — Ground pin.

Image for post

Input and Output

An analog signal can take any number of values, while a digital signal which is limited to two values: High and Low. To measure the value of analog signals, the Arduino has a built-in analog-to-digital converter (ADC). The ADC turns the analog voltage into a digital value. The Arduino does not have a built-in digital-to-analog converter (DAC), but it can pulse-width modulate (PWM) a digital signal to achieve some of the functions of an analog output.

Digital I/O pins

The Arduino Uno board has 14 digital I/O pins. Each of the 14 digital pins on the Uno can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. In addition to this, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX) — They are used to receive (RX) and transmit (TX) TTL serial data.

External Interrupts: 2 and 3 — These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value.

PWM: 3, 5, 6, 9, 10, and 11 — Provide 8-bit PWM output with the analogWrite() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) — These pins support SPI communication using the SPI library.

LED: 13 -There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it’s off.

All these pins can be configured to work as input digital pins to read logic values (0 or 1) or as digital output pins to drive different modules like LEDs, relays, etc.

Analog Input pins

The Uno has 6 analog inputs, labeled A0 — A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts. A few pins have specialized functionality:

TWI: A4 or SDA pin and A5 or SCL pin — used to support TWI communication using the Wire library.

A few other pins on the board are:

AREF — Used with analogReference() to set a reference voltage for the analog inputs.

Reset — Used to reset the microcontroller.

Now that we have a basic idea of the pin layout and their purposes, let’s get started with a basic program to explore their functionality. We will explore the control of the on-board LED on the Uno board with the help of a button.

Prerequisites:

  1. Arduino Uno board
  2. A Button/Switch
  3. 10K ohm resistor
  4. Jumper wires
  5. Breadboard

Following are the circuit diagram and layout for the project:

Image for post

Image for post

Connect the three wires to the board according to the schematic. The first two, red and black, are connected to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10K ohm) to ground. The other leg of the button connects to the 5 volt supply.

When the pushbutton is open (unpressed) there is no connection between the two legs so the pin is connected to ground (through the pull-down resistor) and reads LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, thereby reading a HIGH.

Once you have made the connections, connect the board to your PC and open a new sketch. In case you’re not familiar with the installation of the Arduino IDE and want to verify the process, you can check out the procedure to set it up out here.

After opening a new sketch, run the following code on the IDE to enable the button to control the on-board LED.

Image for post

Image for post


Let’s look at few of the functions used in the code in detail:

  1. pinMode(pin, mode)- Configures the specified pin to behave either as an input or an output.

Parameters:

pin — the Arduino pin number to set the mode of

mode — INPUT, OUTPUT, or INPUT_PULLUP

2. digitalRead(pin) — It reads the value from a specified digital pin, either HIGH or LOW.

Parameters:

pin — the Arduino pin number you want to read

3. digitalWrite(pin, value) — Used to write a HIGH or a LOW value to a digital pin. If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value to 5V for HIGH, 0V (ground) for LOW. If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup, on the input pin.

Parameters:

pin — the Arduino pin number

value -HIGH or LOW

Now upload the sketch onto the board and run the program. The LED should turn on everytime you click the button and turn off when you release it.

In this blog, we explored the functionalities of few of the main pinouts on the Uno board and learnt how to control LED with the help of a button. You can even use an external LED and try to toggle it with a switch.