CTY SAR FCPS Shawn Lupoli, Elliot Tan Arduino LED Lab CTY SAR FCPS Shawn Lupoli, Elliot Tan
Let’s learn a bit about the parts we will be using…
Ohm’s Law Voltage = Current * Resistance V = IR Voltage Current Electric potential difference Measured in Volts (V) Current Flow of electric charge Measured in Amperes (I) Resistance Conductor’s opposition to passage of electric current Measured in Ohms (Ω)
Reading Resistors
Example Problems
For a quick answer http://www.digikey.com/en/resources/conversion- calculators/conversion-calculator-resistor-color-code-4-band Make sure to select how many colored bands there are on the resistor If the URL has changed, please let your instructional staff know
Programming “Blink”
Overall Structure Global variables Void setup() { } Void loop() { } This function is called when a sketch starts Used to initialize variables, pin modes, and start using library Will only run once Void loop() { } Loops consecutively Allows your program to change and respond
Blink: Part 1 Initializing global variables Setup() The LED will be connected to pin 13, so initialize a global variable “ int led = 13 “ Setup() pinMode(pin, mode) configures the pin to behave either as an input or an output Initialize the digital pin 13 as output using function
Blink: Part 2 Loop() Functions Examples digitalWrite(pin, MODE) – HIGH enables voltage, LOW will disable voltage delay(int x) – Pauses the program for the amount of time in milliseconds Examples digitalWrite(13, High); Delay (1000)
CODE
Building the LED circuit
Supplies 1 Arduino board 1 breadboard 4 long wires (one red, one black) 1 LED 1 resistors (330 kΩ) * Notes: Wires are 22 or 24 AWG, solid Short wires = 5 cm Medium wires = 12 cm Long wires = 16 cm
Wiring the LED correctly
Diagram of LED circuit
Connecting Code and Circuit
Putting it All Together UPLOAD! Remember to check for the flashing RX and TX lights, and a “Successful upload” message in your console Understanding the process Since pin 13 is initialized as output, your computer tells the circuit what the do through pin 13 Turning on the LED, waiting, turning off the LED, waiting The switches will open and close the circuit, allowing the LEDs to either blink or not blink
Questions?