Lab 2

In this lab you will get set up with the Arduino prototyping environment and explore digital inputs and outputs using a microcontroller.

Objectives

  • Get set up with the Arduino environment
  • Build a circuit with one digital input (a switch) and two digital outputs (LEDs)
  • Program the Arduino to power the LEDs based on the switch state
  • Laser cut a project enclosure

Resources

Part 1: Build the Circuit

On a breadboard, setup a digital input (a switch) - connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch (or build your own!).


Digital Input

The resistor connecting the switch is a pulldown resistor. It provides the digital input pin with a reference to ground. Without it, the input will behave unreliably. If you don’t have a 10-kilohm resistor for the switch, you can use any reasonably high value. 4.7K, 22K, and even 1 Megaohm resistors have all been tested with this circuit and they work fine.

Next, add digital outputs (LEDs) - connect a 220-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.


Digital Outputs

Note on LED Resistor Values - For the resistor on the LED, the higher the resistor value, the dimmer your LED will be. So 220-ohm resistors give you a nice bright LED, 1-kilohm will make it dimmer, and 10K or higher will likely make it too dim to see.

Part 2: Program the Microcontroller

Connect the microcontroller to your computer via USB.

Select your board - choose Tools > Board then select Arduino/Genuino Uno.

Select your port - When you plug the Arduino into your computer, you’ll find a new serial port in the Tools > Serial Port menu (for details on installing the software, and USB-to-serial drivers for older Arduino models, see the Arduino Getting Started Guide). In OSX, the name will begin with /dev/tty.usbmodem- if it’s an Arduino Uno later, and /dev/tty.usbserial- if it’s a Duemilanove or earlier. In Windows it will start with COM like all the other serial ports.


Board Port

Write a program that reads the digital input (button) on pin 2. When the switch is pressed, turn LED1 on and LED2 off. When the switch is released, switch them (LED1 off and LED2 on).

Hint: use the following functions in your program:
pinMode()
digitalRead()
digitalWrite()

TAKE IT TO THE NEXT LEVEL - this isn’t required, but I want to push you to expand on this lab! Try incorporating an RGB LED and changing the colors based on the button input. You could get really fancy and use Arduino State Change Detection to rotate through many different colors.

Part 3: Laser Cut Enclosure

For Lab 2, you must laser cut an enclosure for your circuit. Come up with a clever concept for your enclosure, and carefully plan out the construction before beginning. Your enclosure must fully encompass your electronics (including the breadboard), although it is acceptable to have a power cord coming out. You may also choose to solder your components to a breadboard or extend them using hookup wire; the goal is to have everything securely enclosed.

Be intentional with your material selection - wood and cardboard are much more sustainable for an exercise like this. If you need to diffuse light or have another great reason to use plastic, then acrylic is also acceptable.

You are welcome to work in groups of 2 to build your enclosure.

Blog Response

Thoroughly document each part of your lab and post it to your blog with written explanations of what you did. Document your lab in a step-by-step format and please focus on taking informative and clear photos!

Bring your enclosure to class!

Lab 2 is due before class on February 13th

©2018 - Arielle Hein