Digital Outputs

Digital Outputs (DO) are one of the four contexts or types of circuits that are core to tangible. They are a great tangible starting point as they require simple circuits (just 3 parts) and let us start coding right away.

Reference Card:

digital output card

Download:: Digital Output 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 Output

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.

do matrix

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 by the Arduino and sent out to circuits are OUTPUTS.

So, Digital Outputs are ON/OFF signals (V) that move OUT of the Arduino.

Video :: Digital Outputs

This first video is from a project that I completed with David Bouchard. An alternate course specific video with an updated circuit can be found below.

VIDEO UPDATE: Digital Outputs

tangible course introduction to digital outputs — this video follows in-class content more closely than the video above. Please note — I extend the first circuit build from class with an RGB LED in this video. If you do not have an RGB LED you can use 2 single color LEDs. You may want to checkout a manual exploration of RGB LEDs using fixed resistors or with code functions if you want more detials on RGB.

Code samples from this video can be found below.

Get the Class Slides

Download :: digitalOutput-slides-2025

Classic Example

The classic example of a digital output is a blinking LED.

Circuit

The classic circuit for testing a digital output is a simple LED and current limiting resistor. Circuit on left when state = 0, LOW, circuit on right when state = 1,HIGH.

Command :: digitalWrite()

The code that creates a Digital Output is:

    digitalWrite(pin, state);

where:
pin = 2 – 13 (inclusive)
state = LOW (0, Ground) OR HIGH (1, 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:

Write a digital (on/off) signal to pin at level = state (0/LOW or 1/HIGH).

How Does it Work?

If a 1 or HIGH is written, then the voltage (V) at the pin is set to 5V.

If a 0 or LOW is written, then the voltage (V) at the pin is set to 0V (ground).

Important

In Arduino, we Write outputs. Image creating waterfalls on the selected pin.

Check the Arduino Docs for this topic

Code Sample – SINGLE LED

int ledPin  = 5 ; // led on pin 5

void setup() {
  pinMode ( ledPin , OUTPUT) ; // set direction
}

void loop() {

  digitalWrite ( ledPin , 1 ) ;   // turn LED on
  delay ( 1000 ) ;  // wait a bit == 1 second

  digitalWrite ( ledPin, 0 ) ;  // turn LED off  
  delay ( 1000 ) ; // wait a bit

}

CODE Sample – 2 colors of RGB LED

// code sample using B and R, of RGB led

int blueLED  = 5 ;  // connect PIN 5 to BLUE pin of RGB LED
int redLED   = 10 ; // connect PIN 10 to RED pin of RGB LED

void setup() { 
  // put your setup code here, to run once:
  pinMode ( blueLED , OUTPUT) ;   
  pinMode ( redLED  , OUTPUT) ; 
}

void loop() { 
  // put your main code here, to run repeatedly:

  //  blue
  digitalWrite ( blueLED , HIGH ) ;   // turn LED on 
  delay ( 1000 ) ;  // wait a bit == 1 second 
  digitalWrite ( blueLED, LOW ) ;  // turn LED off  
  delay  (1000 ) ; // wait a bit 

  //  red
  digitalWrite ( redLED , HIGH ) ; 
  delay ( 1000 ) ;  // wait a bit == 1 second 
  digitalWrite ( redLED, LOW ) ;  // turn LED off  
  delay  (1000 ) ; // wait a bit 
}

Going Further

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

Also consider:

Digital Inputs

Analog Inputs

And finally – get the overview at: