Skip to content

Instantly share code, notes, and snippets.

@kljensen
Last active August 29, 2015 14:28
Show Gist options
  • Select an option

  • Save kljensen/acfda098f248bc464c78 to your computer and use it in GitHub Desktop.

Select an option

Save kljensen/acfda098f248bc464c78 to your computer and use it in GitHub Desktop.

Yale-MGT656-Arduino-LED-activity.md

The purpose of this activity is to "get your hands dirty" with computer hardware and code. We'll be using a microcontroller called the Ardiuno to control light emitting diodes (LED) via software we write.

Step one: light up the LED

To get started, let's make sure we can light up a single LED. You'll need the following supplies, which you should receive from the instructors:

Plug the A-end of your USB into your computer and your B-end into the Arduino to turn on the Arduino. (Don't plug the A-end into anything other than a computer.) Your Arduino should power on. Now, you want to choose a resistor and wire up your system like shown here

wire configuration for step 1 wire configuration for step 1

The LED should light up.

Here are some questions you should be able to answer as a group (likely via searching about on the web and discussing among yourselves).

  • Where is electricity flowing?
  • How much electricity is the Arduino drawing from your computer?
  • What does the resistor do?
  • What happens if you choose a different resistor?
  • How are the resistors different? (Notice their patterns)
  • What is different about the LEDs that you have?

Step 2: blink the LED

The Arduino can be told to do send electricity in varying amounts to the different outputs on the side of the board. In part one, you used the 5V constant power. Now, we're going to use the numbered pins. In order to control the power of those pins, we'll need to write a program for the Arduino and load it onto the Arduino. To do that, you'll need to download the Arduino IDE onto your laptop. We'll write a program with the IDE and upload it via the USB cable onto the Arduino.

Once you've installed the Arduino IDE, you'll want to load up the "blink" example code. Go to File > Examples > 01. Basics > Blink as shown in the following images.

loading arduino blink example

You should see some code that looks like this

arduino blink example code

Save your own copy of that code by going to "Save as" or equivalent on your computer. You can call it anything you want, like "mgt656-led-blink".

At the bottom of the window, the IDE should be showing you how it is connected to the Arduino. This may not be correct. It may look like this

arduino connection information

or

TODO: INSERT IMAGE HERE!

Click on the 'Upload' button. The second button from the left on the toolbar.

arduino upload button

You'll see a progress bar as it uploads the code to the Arduino

uploading

It should complete successfully

upload done

Or, you might get an error if your computer didn't have the right settings to talk to the attached Arduino. If that is the case, you will need to change them. It should be easy, if not a TA can help.

upload error

Now, what should you see on the board? You should see a constant red LED if you left your board the same way it was in part one of this activity: it's still plugged into the 5V pin! If you look at the code you uploaded, you'll notice that it is manipulating the power sent to pin 13. See the line that looks like as follows

int led = 13;

In order to control the LED, we'll want to move the wire from the 5v pin to pin 13. Your writing should look roughly as follows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment