Brandon Roots
  • INTERACTIVE
  • FILM
  • ABOUT
  • CONTACT
September 18, 2020

Lab: Digital Input and Output with an Arduino

broots ITP, Physical Computing

This week I went hands on with an Arduino Nano 33 IoT and setup circuits with logic running through the Arduino. For this first lab I made use of digital IO (inputs and outputs) which are capable of reading the values on and off. The idea for this lab was to control an LED turning on and off through programming. A switch connected to a digital IO pin is used to indicate when to trigger the LEDs. Here is the circuit and code:

  • Arduino Nano on breadboard with lit red LED
void setup() {
  pinMode(2, INPUT);    // set the pushbutton pin to be an input
  pinMode(3, OUTPUT);   // set the yellow LED pin to be an output
  pinMode(4, OUTPUT);   // set the red LED pin to be an output
}

void loop() {
   // read the pushbutton input:
   if (digitalRead(2) == HIGH) {
     // if the pushbutton is closed:
     digitalWrite(3, HIGH);    // turn on the yellow LED
     digitalWrite(4, LOW);     // turn off the red LED
   }
   else {
     // if the switch is open:
     digitalWrite(3, LOW);     // turn off the yellow LED
     digitalWrite(4, HIGH);    // turn on the red LED
   }
 }

By default the red LED is on. When the button is pressed the digital input pin 2 reads a change in value and triggers the red LED (pin 4) to turn off and yellow LED (pin 3) to turn on.

  • Pressing button triggers yellow LED and turns off red LED

The sample code for this worked as expected! On to the next lab…

Lab: Switches and Pushbuttons Lab: Analog In with an Arduino

Related Posts

Fractal Plant – Foiled by  Registers

Homemade Hardware, ITP, Solar Plant

Fractal Plant – Foiled by Registers

Since receiving the PCBs and successfully soldering the board together I have been trying to rewrite code for the I2C port expander. This has been immensely difficult! The Inkplate Arduino Library makes considerable use of an “Mcp” class, which is written to work with the MCP23017 GPIO expander IC. These chips are quite difficult to […]

“Handling” Playtest Week

Handling, ITP

“Handling” Playtest Week

Last week we attended “Playtest Thursday” on the second floor of 370 Jay St with our games. I came away from the experience with some very specific feedback. Seeing a number of people play the game showed me things I didn’t anticipate. Some folks approached the cabinet and immediately treated it as a touch screen. […]

Fractal Plant – Beta Build

Homemade Hardware, ITP, Solar Plant

Fractal Plant – Beta Build

The boards arrived! Amazingly within an hour of one another. Based on the experience I think that JLCPCB is a better value. With shipping OSHPark was $55.50 for 3 boards. JLCPCB was $26.36 for 10 boards. Aside from a higher cost OSHPark also left sharp bits of tabs around the edges of the boards which […]

Recent Posts

  • Fractal Plant – Foiled by  RegistersFractal Plant – Foiled by Registers
    May 9, 2022
  • “Handling” Playtest Week“Handling” Playtest Week
    May 5, 2022
  • Fractal Plant – Beta BuildFractal Plant – Beta Build
    April 24, 2022
Brandon Roots