How to Configure Microcontroller Digital Pins – Arduino

This article is a followup to my previous post. Here I would like to illustrate the concepts discussed in the previous article with the help of Arduino Uno board. I felt Arduino is the best and the easiest platform to understand these concepts without involving any sort of complexity. Just as a precursor to this article, I assume the reader is familiar with running sketches in Arduino.

In the previous post we saw following modes in which a microcontroller pin can be operated.

  1. Output Mode
    • Sourcing
    • Sinking
  2. Input Mode
    • Reading Pin State – floating
    • Need for pull up resistor
    • Need for pull down resistor

Output Mode – Sourcing

In output mode, the selected pin will output either +5v or it can be zero volts. When in sourcing we mean that the pin is at +5V and this can be connected to any external circuit to power it up. Following schematic show how this can be done in Arduino Uno board.

Output Sourcing
Output Sourcing
Output Sourcing Code
Output Sourcing Code
Output Sourcing Button Not Pressed
Output Sourcing Button Not Pressed
Output Sourcing Button is Pressed
Output Sourcing Button is Pressed

Output Mode – Sinking

When in sinking we mean that the pin is at zero volts and this will act as a ground pin . Following schematic show how this can be done in Arduino Uno board.

Output Sinking
Output Sinking
Output Sinking Code
Output Sinking Code
Output Sinking Button Not Pressed
Output Sinking Button Not Pressed
Output Sinking Button Is Pressed
Output Sinking Button Is Pressed

Input Mode – Floating

When a pin is set to read the voltage level, we might initially connect the pin as shown below.

Input Floating
Input Floating
Input Floating Code and Observed Behaviour
Input Floating Code and Observed Behaviour

Though this is technically correct, It may most of the times lead to a situation called floating(shown above).

Input Mode with pulldown – Default LOW

To fix the floating issue. We can either default the pin to be always to LOW or always to HIGH. We achieve the default LOW mode using a pull down resistor. By using a pull down resistor we effectively make the pin to be grounded via a resistor(pulldown). Without the resistor the pin will be always grounded even when external +5V is applied, Because the external +5V will take the shortest path to ground and cause the microcontroller pin to in LOW state. Following picture will illustrate this configuration.

Input with pulldown resistor
Input with pulldown resistor
Input with pulldown resistor code
Input with pulldown resistor code
Input with pulldown resistor circuit
Input with pulldown resistor circuit

Input Mode with pullup – Default HIGH

The other way to fix the floating issue is making the pin always to be at HIGH and read it low when external 0v is applied. We achieve the default HIGH mode using a pull up resistor. By using a pull up resistor we effectively make the pin to be connected to voltage less than the measured voltage via a resistor(pullup). Without the resistor voltage drop the pin will always read is the default pullup voltage not the external voltage. Following picture will illustrate this configuration.

Input pullup resistor
Input pullup resistor
Input pullup resistor Code
Input pullup resistor Code
Input pullup resistor circuit
Input pullup resistor circuit

2 thoughts on “How to Configure Microcontroller Digital Pins – Arduino

Leave a Reply