Skip to content

Digital Inputs

What It Does

Read digital input signals with microcontrollers like the Arduino.

Conditioning

DANGER

Depending on your Arduino / MCU type you need to worry about different voltages. Teensies use 3.3V for instance, and thus the 5V in the circuits below should be replaced with 3.3V.

If you want to read external logic input levels with your Arduino / MCU, you need to be sure that:

  • Incomming voltages are conditioned well so they do not destroy the device.
  • Incomming voltages are clear so they get interpreted correctly.

Gate with diodes

  • Notice the basic input conditioner.
  • Lookup the logic input threshold levels. For 5V Arduino's voltages above 3V are considered HIGH.

TIP

Arduino's and other MCU's read an incoming voltage as HIGH when it is above a certain threshold level. If you are unsure about if the voltage level of an incoming gates can reach that threshold use transistor buffers instead.

Gate with hardware pull-up

  • Notice the hardware pull-up.
  • Notice the logic buffer inverter and the input rectifier.

Gate with software pull-up

  • Notice that this solution uses even one less component than previous one.
  • Although I call it a "software pull-up" it technically is a hardware pull-up set by software. In the Arduino you use "INPUT_PULLUP" to set this.
  • Look at the datasheet of the MCU to see which inputs allow the pullup. Pull-ups are more common than pull-downs. 🤷

Button with hardware pull-up

Button with software pull-up

  • Notice that this solution uses even one less component than previous one.

Button with hardware pull-down

Toggle switch with 3 positions

Using 2 digital pins

  • Notice this solution uses two digital pins.
  • Use a logic table to look up the position.
Position switchINPUT 1INPUT 2
LEFTHL
CENTERLL
RIGHTLH

Using 1 ADC pin 😉

If you want to use only one pin you can also utilise an ADC input.

  • Notice the voltage divider.
  • Use a table to look up the position. Example table (if max = 5V):
Position switchANALOG_READ
LEFT0V
CENTER2.5V
RIGHT5V