Arduino Input and Output Pins

Created on: 2 February 2022

Arduino input and output pins for beginners in electronics. What is an input pin, output pin, and PWM pin on an Arduino Uno or Arduino MEGA 2560? This final part of the Arduino tutorial for beginners looks at the most basic Arduino concepts. That is, how to use Arduino digital pins as inputs and outputs. In addition PWM pins are covered.

Part 14 of the Arduino Tutorial for Beginners

Basically, Arduino digital pins are configurable between three different functions as follows. Firstly input pins for reading the state of a pin, or attached switch for example. Secondly as an output to switch or drive an electric load such as an LED. Thirdly some pins have special functions such as serial communications and PWM (Pulse Width Modulation). Digital Arduino input and output pins are briefly covered in part 8 of this tutorial on how to use a push button switch with Arduino. This part of the tutorial includes more details on digital input and output pins. In addition the basics of PWM pins are explained.

Arduino Digital Pins and PWM Pins

The following subsections highlight the main Arduino Uno and Arduino MEGA 2560 pins. That is, the digital pins and PWM pins. Digital pins that are configurable as either inputs or outputs are called input/output pins. Input/output is often written I/O for short.

Arduino Uno Digital Input Pins, Output Pins, and PWM Pins

The following image marks the Arduino Uno digital pins. Some of the the digital pins have PWM capabilities. Digital pins are configurable as input pins or output pins. In addition, the two pins at the top right of the below image are for serial communications.

Arduino Uno Digital Input Output Pins, PWM Pins and Communication Pins
Arduino Uno Digital Input Output Pins, PWM Pins and Communication Pins

In addition to the marked pins, there are actually other communication pins. These are known as TWI or I2C, and SPI pins. Analog pins at the bottom right of the Arduino Uno are also configurable as digital pins. Refer to the Ultimate Arduino Uno Hardware Manual for diagrams that show the multiple pin functions of Arduino Uno boards. Whereas this Arduino tutorial for beginners covers some parts of the Arduino Uno hardware, the Ultimate Arduino Uno Hardware Manual covers a lot more. For example, board handling precautions, details on the microcontroller, what the programming headers are for, as well as a pin reference, interfacing examples and fault finding techniques, to name only some of the book contents.

Arduino MEGA 2560 Digital Input Pins, Output Pins and PWM Pins

The following image marks Arduino MEGA 2560 digital input and output pins that are also PWM pins on the top left. To the right of these are digital input and output pins that are also communication pins. That is, pins used for serial communications. In other words, these pins are configurable as either communication pins, or digital input pins, or digital output pins. At the right end of the Arduino MEGA 2560 is a double row of digital pins. All digital pins are configurable as input pins or output pins.

Arduino MEGA 2560 Digital Pins with PWM and Communications Pins
Arduino MEGA 2560 Digital Pins with PWM and Communications Pins

There are actually some communication pins and PWM pins on the double connector at the end of the Arduino MEGA 2560. Refer to the Ultimate Arduino MEGA 2560 Hardware Manual for diagrams that show many more details of the Arduino MEGA 2560 pins. In addition, this manual contains a lot of valuable information on all aspects of the Arduino MEGA 2560 hardware.

Arduino Digital Input Pins

Configure Arduino digital pins as input pins to read the state of a switch for example. Digital input pins enable the state of a pin to be read in Arduino sketch code. That is, an input is either HIGH (also called logic 1), or LOW (also called logic low). Refer back to part 8 of this Arduino tutorial for beginners that covers how to read the state of a switch connected to an Arduino pin.

Arduino Digital Output Pins

Configure Arduino digital pins as outputs to drive or switch a load. For example, a LED and series resistor are an electrical load. Another example of an electrical load is a 5V buzzer. A TDB05LFPN is the part number for a 5V buzzer. There are many other examples of 5V buzzers, but the TDB05LFPN draws less than 30mA of current. This means that this buzzer can be directly connected to and driven by an Arduino Uno or Arduino MEGA 2560 pin.

Arduino Uno and MEGA 2560 Pin Current Limits

Arduino give the maximum current draw of a digital output pin as 20mA. In fact it is possible to draw more than 20mA from a pin. As a result, it is possible to directly drive or switch a buzzer that draws up to 30mA. This applies to Arduino Uno and Arduino MEGA 2560 boards.

Arduino output pin current limits are actually more complex than just stating a maximum current draw such as 20mA per pin. Arduino pins are divided into groups or banks of pins. These groups or banks of pins have limits to how much current can be drawn from them. As a result, 30mA can be drawn from some pins, but not too many in a pin group or bank.

Refer to the Ultimate Arduino Uno Hardware Manual for information and diagrams about the pin groups and current limits for Arduino Uno boards. The same applies to Arduino MEGA 2560 boards, however these boards have different pin groups to the Arduino Uno. Refer to the Ultimate Arduino MEGA 2560 Hardware Manual for information and diagrams on pin groups and current limits for Arduino MEGA 2560 boards.

How to Connect a Buzzer to an Arduino Output Pin

Connect a buzzer directly to an Arduino Uno or Arduino MEGA 2560 output pin if the buzzer is low power. In addition, the buzzer must also be able to work from 5V. This is described in the next subsection. Connect a buzzer to an Arduino Uno or MEGA 2450 using a transistor if the buzzer draws more current than about 30mA. Also use a transistor when the buzzer operates from a voltage that is higher than 12V. The second subsection below describes how to do this.

Directly Connect a Buzzer to an Arduino Digital Output Pin

Connect a TDB05LFPN or similar 5V buzzer to an Arduino Uno or Arduino MEGA 2560. Make the connection as shown in the article on how to connect a buzzer to an Arduino Uno. This article specifies an Arduino Uno. Make the same connection to an Arduino MEGA 2560. As a matter of fact, this very simple article connects the buzzer to Arduino digital pin 13. Use the blink example sketch to beep the buzzer on and off, as described in the article.

Connect an Buzzer to an Arduino Output Pin using a Transistor

Connect a buzzer using a transistor as the Arduino buzzer circuit for beginners article shows. This method reduces the amount of current drawn from an Arduino Pin. In addition a buzzer that operates from more that 5V must be connected using a transistor and external power supply. This is explained in the article.

Arduino Output Pin Projects

A knight rider or LED chaser circuit is fun to build for beginners. The Arduino knight rider circuit is part of the Start Electronics Now tutorial series. This project is not repeated here because it is already available at the above link. Build this project using an Arduino Uno or Arduino MEGA 2560. The circuit shows an Arduino Uno. Use the same pin numbers for an Arduino MEGA 2560.

See the Arduino MEGA 24 LED knight rider display beginner’s circuit. A knight rider display or LED chaser that consists of 24 LEDs is built in this article.

Arduino PWM Output Pins

PWM stands for Pulse Width Modulation. Some Arduino Uno and Arduino MEGA 2560 digital pins have PWM capabilities, as is mentioned above. Control the brightness of an LED using PWM and the Arduino fade example sketch. Refer to the tutorial on how to fade an LED’s brightness. Control an LED attached to pin 9 of an Arduino Uno or MEGA 2560 using the fade example sketch. The links to the Arduino tutorial page from the above tutorial page show a 220 ohm resistor in the circuit. Use a 470 ohm resistor if you do not have a 220 ohm resistor.

Build a Circuit without Arduino

This final part of the Arduino tutorial for beginners shows a simple circuit built without an Arduino. Build the dual LED flasher circuit on a breadboard and power it from Arduino 5V. This circuit demonstrates a cheap alternative to Arduino that flashes two LEDs alternately. The circuit consists of resistors, capacitors, LEDs and transistors. It is part of the Start Electronics Now tutorial series.

Where to from Here?

This 14 part Arduino tutorial for beginners introduces beginners to Arduino. In addition, it explains how some of the example sketches work. There is a lot to learn about Arduino. This is because Arduino consists of building circuits, connecting components, and programming. This tutorial touches on some of these aspects of Arduino. It is kept simple intentionally so as not to overwhelm new Arduino users. Some suggestions on where to proceed from here are as follows.