Lab #2: Digital I/O with Arduino Boards

Felicia Renelus
4 min readSep 14, 2021

--

Felicia Renelus. Professor Kimiko Ryokai. NEW MEDIA 262, Fall 2021.

Description

In this lab, the goal was to improve upon our Arduino skills and not only make just one LED light glow but make three LED light glow. More specifically, we examined pulse width modulation (PWM) and serial communication. With these, we used Arduino to control the blinking and fading of multiple LED lights with key presses.

First, I set up my breadboard, Arduino and LEDs. The wires were placed in pinholes 9,10 and 11 and the other ends placed on the breadboard. I then connected each LED light to the breadboard with the positive ends on the positive side of the breadboard and negative ends on the negative side. Each LED was in the same row as a wire. I did the same for the resistors. Lastly, I connected the black wire to the ground and the other end of the wire in the same row as the negative end of the LED light.

Components Used:

  • Arduino
  • Breadboard
  • 4 x colored wires
  • 3 x LED
  • 3 x 220 ohm-resistor

Video (Fade)

Further Exploration

After getting three LED lights to fade simultaneously, I moved on to being able to control the brightness of each light via serial communication. Using the code given to us in class, I was able to tell the Arduino to make each LED go to a certain brightness. For example, ‘r0’ would make the red LED light turn off, but ‘r127’ would make it go to a middle brightness.

Video (Serial Communication)

Even Further Exploration

Instead of declaring in the serial monitor the brightness I wanted a certain LED light to go, I wanted to try and increase the brightness of each LED by a certain degree with each keypress. For example, by just pressing ‘r’ in the serial monitor, the red LED would go up by a specified amount of brightness. To accomplish this, I ended altering the original code given to us to have the LED lights start off a 0 brightness. I created a variable called ledcolorCurrent that declared a value for what the LED light would glow to when a key was pressed. In this case, the LED lights were at 30, however, when a key was pressed, it would not only go to 30 brightness but also increase by 10 brightness. So in theory, the LED light was at 40 brightness. If the key coded to an LED light was pressed again, it would increase the brightness by 10 and so it would now be at 50. This is the code I used to accomplish this:

char serInString[100];

char colorCode;

int redCurrent = 30; // i believe once a key is pressed, this is the brightness the LEDs go to

int greenCurrent = 30;

int blueCurrent = 30;

int redPin = 9; // Red LED, connected to digital pin 9

int greenPin = 10; // Green LED, connected to digital pin 10

int bluePin = 11; // Blue LED, connected to digital pin 11

void setup() {

pinMode(redPin, OUTPUT); // sets the pins as output

pinMode(greenPin, OUTPUT);

pinMode(bluePin, OUTPUT);

Serial.begin(9600);

analogWrite(redPin, 0); // set them all to 0 brightness

analogWrite(greenPin, 0);

analogWrite(bluePin, 0);

Serial.println(“enter color command (e.g. ‘r’) :”);

}

void loop () {

// clear the string

memset(serInString, 0, 100);

// read the serial port and create a string out of what you read

readSerialString(serInString);

colorCode = serInString[0];

{

if(colorCode == ‘r’) // start here

{redCurrent += 10; // increases by 10 brightness with every key press

analogWrite(redPin, redCurrent);}

else if(colorCode == ‘g’)

{greenCurrent += 10;

analogWrite(greenPin, greenCurrent);}

else if(colorCode == ‘b’)

{blueCurrent += 10;

analogWrite(bluePin, blueCurrent);}

}

delay(100); // wait a bit, for serial data

}

Video (Serial Communication Key Presses)

Creating a Diffuser

Since the LED lights can be a bit harsh and concentrated, our last task of this lab was to create a diffuser. This helped scatter the light and make it a bit softer. It also created a cool effect in blending the lights to create different colors. I used polyester toy filling to create my diffuser.

Summary

I really enjoyed this lab. Some challenges I faced were trying to alter the code given to us to make the lights increase by a certain brightness. This was more difficult for me than expected as I would get small errors I didn’t fully understand. With a ton of trial and error and Google searching, I was able to alter the code to make the LED lights accomplish what I intended. Another very small challenge with the diffuser was I originally had my LED lights spread out far on the breadboard. With a suggestion from a classmate, they said I should try moving my lights closer together to make it easier once I add the diffuser. This was very helpful information. Overall, I definitely learned a lot from this lab and want to challenge myself even further in the upcoming labs.

--

--

Felicia Renelus

I’m a first year Master of Design at UC Berkeley. My interests are in neuroaesthetics, speculative design and overall design for health and wellness.