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.
- Output Mode
- 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 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.
Input Mode – Floating
When a pin is set to read the voltage level, we might initially connect the pin as shown below.
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 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.