Digital Inputs

Digital Inputs (DI) are one of the four contexts or types of circuits that are core to tangible.

Reference Card:

Download:: Digital Input card [PDF]

You should print or download a copy of the reference card above and bookmark this page.

There is a unique card for each context in the tangible matrix and each one indicates the context, command, circuit and offers a code sample.

Context :: Digital Input

If you have not yet looked at the tangible matrix Building Block, you should check it out now. It will introduce you to all four contexts and give a deeper background to the ideas presented here.

Digital refers to signals, circuits, or logical systems that only have two states; ON, OFF.

Input and Output are defined from the perspective of our Arduino. Electrical signals generated in circuits and sent into the Arduino are INPUTS.

So, Digital Inputs are ON/OFF signals (V) that move INTO the Arduino.

Video :: Digital Inputs

Get the Class Slides

Download :: digitalInput-slides-2025

Classic Example

The classic example of a digital input is a button.

Circuit

The classic circuit for testing a digital input is a simple push button (tho any two wires could do). The circuit on left indicates electrical state (state = 0, LOW) when a button is unpressed . The circuit on right indicates electrical state (state = 1,HIGH) when button is pressed.

Command :: digitalRead()

The code that creates a Digital Input is:

    state = digitalRead(pin);

where:
pin = 2 – 13 (inclusive)
state = 0 OR 1 (gnd or 5V)

Note 1: pin can also include 0,1; but these are reserved for communication, so best to avoid them.

Note 2: pin 13 has the built in LED attached

The line of code above means:

Read the digital (on/off) state of pinX and store that reading in a variable called state.

How Does it Work ?

If the button is pressed, a 5V signal reaches pinX and a 1 ( conceptually a HIGH) is stored in state.

If the button is not pressed (released), a 0V or GND signal reaches pinX and a 0 ( conceptually a LOW) is stored in state.

Important

In Arduino, we read inputs.

Check the Arduino Docs for this topic

Code Sample

int buttonPIN = 12;
int state = 0;

void setup() {
  pinMode( buttonPIN, INPUT ); 
  Serial.begin(9600);
}
void loop() {
  state = digitalRead( buttonPIN ); 
  Serial.println(state);
}

Going Further

Check out analog inputs to see how they compare and contrast with the digital inputs covered here.

Also consider:

Analog Outputs

Digital Outputs

And finally – get the overview at: