Physics 222 Name: Exercise 6: Mr. Blinky This exercise is designed to help you wire a simple circuit based on the Arduino microprocessor, which is a particular brand of microprocessor that also includes the Raspberry Pi and similar devices. These microprocessors require coding to even deliver current to the circuit, so there is both a hardware and software component to this exercise please trade off wiring and coding with your partner! The Autodesk Corporation has a pretty good Arduino simulator called Circuits (www.tinkercad.com) if you want to practice your coding or wiring skills out of class. For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment. 1. For the four resistors shown below, which are connected in a meaningful way and which are not? By meaningful, I mean that the resistor could be part of a real circuit. Now build your first circuit with the Arduino. As you saw in the first question, you never connect a device (LED, resistor) in the same connected row or column. Using the breadboard and the supplied jumpers, connect your 220 ohm resistor and LED to the Arduino s +5V power pin and ground (0V). You are simply using the Arduino as a 5V source. LED is an abbreviation for light-emitting diode, and is therefore a diode, and therefore has a polarity; if the LED does not light up in one direction, switch its polarity. 2. Draw the schematic circuit for what you ve just built. For the power source, simply indicate which number pin on the Arduino you connected the jumper to.
The 220 W resistor is limiting the current to the LED. Remember, the LED can only take up to 30 ma of current. Of the 5 volts supplied to the circuit, if the LED draws 30 ma (the maximum), then it would have 2.1 volts across it. That leaves 2.9 volts for the resistor. 3. What is the minimum value resistor that would work for this simple circuit? You would just need to use a resistor that is that value or larger, but not so large the current drops to a level where the LED won t light up, which is around 0.4 ma. (Hint: it is less than 220 W). Show your work. Note you could have just used a 5V battery or other voltage source you don t need a microcontroller to make an LED light up! Now turn on the laptop, and connect the USB cable to the Arduino (the port on the Arduino is not a USB). Your LED should light up; if it does not, flip the leads of the LED around. To do that you will need to move the wire going to the LED from the 5V pin to a digital pin 13. Unlike the 5V pin which always supplies 5V, the digital pins can supply 5V or 0V, controlled by the program you send to the microcontroller. Open the Arduino software (there s an icon on the Desktop, or else Start All Programs AS instruments Arduino). Make sure that Arduino Uno is selected under Tools/Board and you select the COM port listed in the Tools/Serial Port menu. A version of the Arduino called the Ruggeduino has a built-in 220 W resistor; the one that you are using does not. There is only the 220 W resistor that you included in the circuit. Most companies Arduinos doesn t have this built-in resistor, so it is critical you add one if you use one of these Arduinos. Since voltage = current resistance, (2.9 V)/(440 W) = 6.6 ma, well under the 30 ma maximum the LED can handle, but still enough current to light up the LED. Begin by using the variable int or integer and tell the Arduino which pin the LED is plugged into:
Remember that setup is used for things that only need to be done once. Therefore, tell the Arduino that the LED in pin 13 is an output. That means when you input data, it outputs an outcome or result. So add the following: void setup () { pinmode(ledpin,output); } The next step is telling the Arduino what you want to do with the LED. You first need to use the digitalwrite command to turn the LED ON. Then use the delay command to specify the amount of delay time in milliseconds. Use the same command to turn it OFF then wait again. Since this is a loop the process will repeat forever until the power is removed. void loop () { digitalwrite(ledpin,high); delay(1000); digitalwrite(ledpin,low); delay(1000); } To run this program, you first have to compile it (convert the code into the digital information the microprocessor understands) and then send that to the Arduino. To compile your sketch, click the checkmark. Try changing the time for each delay. Click the arrow to download the program to Arduino. If everything is attached correctly after a few seconds the LED should blink.
4. Delete the second of the two delay(1000) commands, then compile and send the program to your Arduino. Explain why you see what you see. 5. Modify your code so that the LED blinks on and off 10 times in 10 seconds, then turns off for 3 seconds, then repeats this cycle. Write your code below and show your instructor your working program.
The Arduino is a digital device, but we can use digital pins 3, 5, 6, 9, 10, and 11 to emulate an analog signal. It does this with Pulse Width Modulation (PWM). Digital pulses are created that vary so rapidly that a human eye cannot detect the changes, so it can be made to look like the LED brightness is changing smoothly. Switch the + LED pin to digital pin #9 (change the integer in the code as well) and then modify your code with this line in the loop replacing the digitalwrite and delay commands: analogwrite(ledpin,new number); where the new number can be any value between 0 and 255 (see the figure above). Try various numbers from 0 to 255. For each different number you should get a different brightness. 6. At which new number can you detect any light from the LED at all? The Arduino microprocessor has been worked on for many years, and a lot of programs have been written to control a large number of devices, including LEDs. These collections of programs, or snippets within programs, are called libraries. A library of programs was downloaded along with the Arduino IDE.
Go to FILE EXAMPLES ANALOG FADING. Follow the hyperlink, which explains how to FADE. Study their code and answer the following question: 7. Exactly how long does it take for the LED to go from 0 brightness to maximum brightness? (How many times does the delay execute?) Show your work.