Atlas Object

Lab 2: Digital I/O

Sparks were flying in this one.

Circuit with 2 LED’s and a Pixel Strip

For our second lab in ATLAS Object, we practiced programing our Arduino boards to control more complicated circuits.

Part 1: Two LED circuit, twice as lit as before!

For part one of this lab we were tasked to make an LED circuit with two LED’s and two switches to give two unique outputs.

Before I began making the circuit, I first drew a circuit diagram schematic. Since we were using the Arduino’s input and output pins, there were multiple sections to this circuit.

The next step was to find the proper resistors for the LED’s. I decided to use one green and one blue LED. I calculated the resistance value using the supply voltage, forward voltage, and the forward current.

My calculations

After finishing the resistor calculations, I drew the circuit diagram. I also included two 1K pulldown resistors for the digital inputs.

Circuit diagram.

Next it was time to actually build the circuit. I built the circuit as it was drawn in the diagram.

My 2 LED circuit

But nothing happened when I pressed the switches. My hardware engineering may have been done but now it was time to make the software in the Arduino IDE. I wrote a program that would tell the output pins connected to each LED to turn on if a corresponding input pin measured a high value and off if it reads low. This “high value” would be read if a switch was turned on completing the circuit from the 3V3 pin to the input pin. After a few trial and error attempts, I got the LEDs to turn on when their respective switch was pressed. I was feeling a little “tinkerish” so I decided to add an additional feature to the program. Rather than just turning both LEDs when both switches were pressed simultaneously, I programmed the Arduino to respond to both buttons being pressed with a cool LED sequence. This sequence repeats indefinitely until a button is pressed.

My final 2 LED circuit.

Part 2: The Strip

For the second part of our lab, we were tasked with programing an LED strip to respond to our switch presses. I decided to keep the LEDs on my board and add the strip to the existing circuit. I luckily had previously purchased a Raspberry Pi Nano kit that had a pre-soldered LED strip ready to go. All I needed to do was connect a few wires and write the program to operate the strip.

Writing the program was a learning experience. I had to learn how to use 3rd party libraries in order to operate the LED strip. I used the Adafruit NeoPixel library which worked very well with my generic light strip.

Since I kept my LEDs from the previous part in my circuit, adding in code to get outputs for the LED strip was easy. I made the LED strip turn blue when the switch to the blue LED was pressed and green when the green LED was pressed. To mix things up a bit, I programed my LED sequence that occurs when pressing both buttons to make the strip flash green and blue rapidly.

The code below definitely could have been made much shorter using while/for loops/recursive functions, but I was more concerned with getting my program working rather than making it easy to read and edit. I will definitely do a better job of this in the future.

My circuit with the LED strip

Part 3: Soldering

Soldering the breakout boards was the final part of the lab. I had a little bit of difficulty with soldering since I was not present for the last day of the lab. I was eventually able to get some help during after hours. The first step was to find the appropriate resistor for the two LEDs in series. Next I soldered a red LED, blue LED, a resistor, and two wires to the breakout board. Since I was able to use my existing circuit, connecting the wires to the correct pins was easy and required no coding.

My circuit with the breakout board.

Below is the video demonstrating the circuit working.

My breakout board circuit

Leave a Reply

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