Digital Inputs

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

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.

Context :: Digital Input

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.

Card

Your kit contains a reference card for digital inputs.

Each card indicates the context, command, circuit and offers a code sample.

Video :: Digital Inputs

Get the Slides

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

Some follow up Arduino references:

pinMode

Serial

Leave a Reply

Your email address will not be published. Required fields are marked *