Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink By the end of this session: You will know how to use an Arduino and have a better understanding of how many electronic devices are made © S. Pithouse for use by Warwick Technology Volunteers Page: 1 A microcontroller with many inputs and outputs which you can program to turn lights on, react to button pushes, control motors and do many more things. It acts as the ’brains’ in the circuits. You will use it for every project. Arduino Uno A collection of holes that are connected together in lines to easily join components together. Breadboard Wires to join the breadboard to the Arduino and also to link connections on the breadboard. Jumper Wires LED stands for ‘Light Emitting Diode’. They are lights that only work when they are used the correct way around. LED’s Resistors come in many different values, and have different coloured stripes, they are used to protect LEDs from getting destroyed by too much current © S. Pithouse for use by Warwick Technology Volunteers Page: 2 1) Place the breadboard on the table. As shown in the picture, each column is connected together inside. (All of the red holes are connected together, but they are separate from the yellow column.) 2) Look at the LED, you will see that one leg is shorter than the other, and that one side of the plastic is flat. Make sure that the flat side (short leg) is facing left (<- side). 3) Push the resistor into the breadboard, it does not matter which way around it goes in. 4) Push a wire into the Arduino’s pin 13 and into the column with the resistor. © S. Pithouse for use by Warwick Technology Volunteers Page: 3 5) Connect a wire between the Arduino ‘s GND pin and the column in which the short leg of the LED is inserted. NOTE: Pin 13 is special, it is attached to an LED on the Arduino already, so you don’t have to wire one up separately on a breadboard like this, however it is important to learn how it works . © S. Pithouse for use by Warwick Technology Volunteers Page: 4 1) Plug the USB cable into the Arduino and Computer, then open the Arduino Program. 2) Visit the webpage where you found this document —and copy and paste the ‘Blink template program’ into the Arduino window. 3) An Arduino program has two main sections: The setup function runs once at the start of the program, then the loop function runs over and over again. When it gets to the end, it starts the loop function again. 4) Firstly, type this line to tell the program, that we want to call pin 13 ‘LED’. In the setup function we need to tell the Arduino that we want ’LED’ to be an output. © S. Pithouse for use by Warwick Technology Volunteers Page: 5 5) Now, the Arduino knows that we have an LED connected to pin 13, so we just need to tell it what we want it to do with it. Firstly, make it blink an LED (turn it on and off) over and over again. To do this we need to write code in the loop section: HIGH means turn on LOW means turn off Delay(1000); means delay 1 second 6) Upload the program by clicking on the upload button. 7) Your LED should turn on and off every second. This is because even though you only wrote code to turn it on and off once, because it is in the loop function, it repeats forever! Try changing the delay number to 200 or 2000, repeat step 6 and watch what happens. © S. Pithouse for use by Warwick Technology Volunteers Page: 6 8) Try connecting another LED in the breadboard as shown in the diagram. You will need to connect it to a pin other than pin 13, say pin 12, then connect the other side to the GND pin. You will see that the black wire connects the two LED’s together, but since the first LED’s leg was connected to GND, both LED’s legs become connected to GND. © S. Pithouse for use by Warwick Technology Volunteers Page: 7 9) We need to tell the program that we have added another LED. Firstly, we need to give it a name We need to tell it that LED1 is an output We then need to tell it what we want it to do. Here it is turning LED1 off and LED on, then waiting a second before doing the opposite. 10) Upload the program by clicking on the upload button. © S. Pithouse for use by Warwick Technology Volunteers Page: 8 11) You should see the LEDs flashing alternately. Try experimenting and moving the ‘digitalWrite’ lines so that both LED’s flash at the same time, or make them on for a long time and off for a short time. Remember, whenever you change the program, you need to click the upload button to see the new program working! Extension task Extension task If you finish all of these steps, remove your wires from the Arduino and plug in the circuit board as shown in the picture. If you finish all of these steps, remove your wires from the Arduino and plug in the circuit board as shown in the picture. The LEDs are connected as follows: The board contains LEDs connected to pins 9, 10, 11, 12 and 13. Use these numbers in your program and make them flash alternately, or scroll along the row. Red: pin 11 Amber: pin 12 Green: pin 13 Try and make a program to make them light in a Traffic light sequence. © S. Pithouse for use by Warwick Technology Volunteers Page: 9