Purpose:
The purpose of this lab activity is understand the basic framework of an Arduino sketch (program) and browbeat your Arduino into doing some fancy flashing. It is practically universal that the first activity all new Arduino users do is to make an LED flash. The the sketch is traditionally called Blink but Blinky sounds more cheerful to me.
We are also going to get you started learning how to identify some of the creatures in the electronics menagerie (resistors, LEDs, breadboards) that are the basic tools of working with digital electronics.
It seems fair to offer you some explanation for why I am asking all of you to learn this electronics stuff when only a handful of you are headed into electrical engineering. To be a little impudent, expecting a scientist/engineer to know how to operate an Arduino is little like expecting that you can operate a coffee maker or a toaster. It's sort of at the same level. I will also note that several of my students (NOT electrical engineering students) from years past have used their Arduino skills to impress the heck out of their internship employers to the point of generating offers of permanent employment - seriously.
Procedure:
- For this lab you will need your Arduino, an LED of any color (if you're not sure which of the many bits in your kit that is we'll teach you!), a resistor (200 - 300 Ohms), your breadboard, and some jumper wires. If you have a multimeter you will find it potentially helpful today. We will explore how to control a particular output pin using the Arduino IDE, learn how protoboards work and how to use them to wire simple circuits, learn about technical limitations of the Arduino and how we work with them, and finally how to dim and LED using PWM.
i) In our previous lab we learned to access the Arduino and control the blinking of the on board LED. Our first step this week is to create a new sketch, copy some code, and learn how to control any pin we want on the Arduino. Here is a process for getting your personal copy of MyBlink saved on your machine. Within this process document is a section by section discussion of the structure of an Arduino sketch.
ii) Now that we have verified that we are talking to our Arduino we need to turn our attention to understanding the protoboard that is in every basic Arduino kit. The first 3 min of this video gives you the basics of how they work and introduces you to Collin who will come back to instruct us at regular intervals.
iii) No need for me to reproduce the work of others. Here is a link to the next tutorial you will complete. This tutorial uses the breadboard (protoboard), and LED, a resistor, and some wires to connect an LED to an arbitrary pin on the Arduino and make it flash. Once you have this wired up you can use your MyBlink code (with a suitable choice for testPin) to make the LED flash. Since your kits are still fresh and new you should still have labels on the resistors. You can also use a digital multimeter (DMM) to measure a resistor or you can use the color codes. If you want to use your multimeter to measure the resistance instead of figuring out all those silly colors you can watch this multimeter tutorial from Collin - the resistance part starts at 2:45!
Here is a link to a useful resistor color code decoder for those little lines painted on the resistor. It is an interactive tool. You can indicate how many lines there are on your resistor by selecting the appropriate option at the top. Click on the colors you see for each line and it will show you the resistance. Be aware that the colors can be tough to distinguish depending on the background color of the resistor.
iv) Why do you need to put the resistor in the circuit with the LED? It has to do with the amount of current that the Arduino can send out of a particular pin. You can find the basic tech specs for an Arduino Uno here. We will slowly learn to read these tech specs like a good engineer. What is important for us here is that the output pins of an UNO can only provide 20 mA of current. We haven't gotten to the place where we have developed these concepts yet so we are going to have to wing it here for a few weeks. Basically more voltage means more force pushing charges through the wire depending on how much resistance the object (an LED in this case) offers. The problem is that the if I push on the LED with 5 V it wants to draw way more than 20 mA which will damage the Arduino. The LED will be quite bright enough if we push on it with 2 V so that leaves 3 V that we have to deal with. Read this discussion on stackexchange for a fairly complete explanation. Much of this won't make too much sense for a few more weeks but read it anyway:) Placing a resistor (200 - 1000 ohms) before, or after, the LED will limit the current enough to keep the Arduino safe and still allow the LED to be bright enough.
v) Make your chosen pin (could be any of them from 1 to 13) flash your external resistor/LED slow and then fast in sequence and repeat.
vi) Bonus Round: For some there will be sufficient challenges either because of equipment or because this is very new to you that getting through v) will be sufficiently challenging. For those who are interested or have time read this discussion of dimming an LED with PWM. LED's do not dim in the normal sense of the word. The brightest we can make an LED is to just leave it on. What we do to make an LED dimmer is turn it off and on rapidly. If we do it fast enough your eye won't notice. If the LED is on half the time and off half the time it will seem dimmer (not actually 1/2 as bright because of how our eyes work). If it is on 10% of the time it will see even dimmer. As it turns out that some of the pins on the Arduino are specifically designed to allow this possibility which is called Pulse Width Modulation PWM). Read a good description of PWM here. For this bonus round make your LED blink 5 times in a row but each time make it dimmer. Rinse and repeat. You will need to use the analogWrite() command instead of the digitalWrite() command. Documentation is linked as you see.
- LAB DELIVERABLES:
-
I) Drop into my office hours (zoom) or during the lab and hold your Arduino and protoboard up to the camera so I can see that you have accomplished the task(s).