Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Getting Started
with the
Arduino Uno
by Eric J. Richardson and Vui Nguyen
September 2017
Legal Disclaimer
Arduino is a trademark of somebody, certainly
But not us
Why this Presentation?
● Last year, we started
doing IoT when we
entered the Intel IoT
Roadshow
●“Save the Water Pipes”
wa...
Why this Presentation?
●We entered our project in
the US-China Young Maker
Competition (Sponsored by
Intel) and competed i...
Why this Presentation?
● There was a lot of interest in the Intel Edison
● The Edison is cool, but at $100 it’s a bit pric...
Why this Presentation?
● Raspberry Pi is a great value, single-board computer, and can
be used as the basis for many proje...
Who is this Presentation For?
● This presentation is for software devs interested in
learning about hardware
● You should,...
Personal Disclaimer
For those of you who are already familiar with all of this, Eric
apologizes if he sounds like he's “ma...
Who Are We?
Eric J. Richardson
Lockheed Martin Systems Engineer
Colorado State University
B.S. Electrical & Computer Engin...
Who Are We?
Vui Nguyen
SimplyE iOS Developer
Colorado School of Mines
B.S. Computer Science, 1999
University of Denver
M.S...
Who Are We Not?
● We are not graphic artists!
● We are not full-fledged Arduino experts!
● We fully expect someone here to...
What is “Arduino”?
● 3 things:
– Arduino is an Italian company that designs low-cost
computers designed to interact with p...
Arduino Uno: What Does It Have?
Arduino Uno
● 14 Digital Input / Output pins (6 of these can be used as Analog outputs)
● ...
Arduino Uno: What Does It NOT Have?
The Arduino Uno does not have one of everything. Some things
you can add, and some thi...
Arduino Uno: Required Equipment
● Arduino Uno ($25)
● USB A/B (male / male) cable
● 9V or 12V, center-pin-positive,
500mA ...
Electronics Mini-Lesson #1: Voltage, Current,
Power, and Charge
Direct-Current electricity has 4 dimensions:
● Voltage: Ho...
Electronics Mini-Lesson #1: Voltage, Current,
Power, and Charge
● What we call a power supply is a constant-voltage
source...
Electronics Mini-Lesson #1: Voltage, Current,
Power, and Charge
● Power supplies can also deliver less than their rated
cu...
Electronics Mini-Lesson #1: Voltage, Current,
Power, and Charge
Electrical Power is always calculated by this formula:
Pow...
Electronics Mini-Lesson #1: Voltage, Current,
Power, and Charge
● Batteries, as far as circuits are concerned, work the sa...
Arduino Uno: Optional Equipment
● breadboard ($5, but get 2, or 1 big one)
● Single Pole/Single Throw
Normally Open Switch...
Arduino Uno: Optional Equipment
● LED Assortment ($6)
● Male-to-Male Jumpers ($8)
● 1MΩ Potentiometers ($3)
Install Arduino IDE
● Download and install Arduino IDE for your OS
– https://www.arduino.cc/en/Guide/HomePage
● Follow ins...
Hardware Building Blocks
● We will going to focus the rest of this presentation on using
the Arduino Uno as the basis of a...
Hardware 100 – Blink an LED
● Before that, let's make sure the darn thing turn on
● Making sure you can get an LED to blin...
blinkOneLED
● Wire the green LED up like this:
I/O 3
1kΩ
blinkOneLED
● Physically, it will look something like this:
Demonstration: blinkOneLED
● Let's make sure everything works!
Electronics Mini-Lesson #2: Circuits, Open
Circuits, and Short Circuits
First, some terminology.
This is a circuit diagram...
Electronics Mini-Lesson #2: Circuits, Open
Circuits, and Short Circuits
● Current flows out of the positive (+) terminal o...
Electronics Mini-Lesson #2: Circuits, Open
Circuits, and Short Circuits
● So, for example, if Vin were 3.3V, and the load ...
Electronics Mini-Lesson #2: Circuits, Open
Circuits, and Short Circuits
● In this case, current cannot flow, because there...
Electronics Mini-Lesson #2: Circuits, Open
Circuits, and Short Circuits
+
_Vin
Current?
● Wires have a resistance of 0Ω
● ...
Electronics Mini-Lesson #2: Circuits, Open
Circuits, and Short Circuits
● Instead, the voltage source will attempt to supp...
Electronics Mini-Lesson #3: GND and Vin
Second, some shorthand.
This takes time to draw:
+
_Vin
Electronics Mini-Lesson #3: GND and Vin
● So, we will use two convenient shorthands.
● The positive terminal of the voltag...
Electronics Mini-Lesson #3: GND and Vin
So:
+
_Vin
Vin
==
Electronics Mini-Lesson #4: Breadboards
● Breadboards are useful for wiring up circuit prototypes
without soldering
● Ther...
Electronics Mini-Lesson #4: Breadboards
● The electrical connections are arranged like so:
● It is helpful to plug Vin int...
Electronics Mini-Lesson #4: Breadboards
● Breadboards cannot carry infinite current without burning
up!
– If your circuit ...
Electronics Mini-Lesson #5: LEDs
● “LED” stands for “Light Emitting Diode”
● They do not behave like resistors! We can mod...
Electronics Mini-Lesson #5: LEDs
● VD
is around 1.8V, while RD
is not very much – on the order
of 2Ω or so
● So, if you we...
Electronics Mini-Lesson #5: LEDs
● This is why each LED needs a 1kΩ resistor in series with
it: Vin
1kΩ
● If the LED is to...
Electronics Mini-Lesson #5: LEDs
● Finally, LEDs are diodes, and the magic of a diode is that
they only allow current to f...
digitalOutputs.py
● Wire the green, yellow, and red LED up like this:
I/O 3
1kΩ
I/O 5
1kΩ
I/O 6
1kΩ
digitalOutputs
● Physically, it will look something like this:
Demonstration: digitalOutputs
● Prepare to have your mind BLOWN!
● What it does: lights up a series of LEDs, one at a time...
digitalInput
● Leaving the LEDs in place, wire the switch like this:
I/O 12
This is a single-throw switch. It
only has one...
digitalInput
● Physically, it will look something like this:
Electronics Mini-Lesson #6: Pull-Ups / Pull-
Downs
When the switch is closed, the circuit will look like this:
Now, the I/...
Electronics Mini-Lesson #6: Pull-Ups / Pull-
Downs
What is I/O 12 connected to when the switch is open?
● It's not connect...
Electronics Mini-Lesson #6: Pull-Ups / Pull-
Downs
● We can avoid floating inputs with “pull-up” and “pull-down”
resistors...
Demonstration: digitalInput
● Pretty much the same as digitalOutputs, until you press the button
● What it does: Light up ...
analogOutputs
● Wire the green, yellow, and red LED up like this:
(same as digitalOutputs)
I/O 3
1kΩ
I/O 5
1kΩ
I/O 6
1kΩ
Arduino Uno I/O
By the way, why did we pick pins 3, 5, and 6,
of all the pins that we could have picked?
Because those pin...
Electronics Mini-Lesson #7: Pulse Width
Modulation
● Because of the nature of field-effect transistors, digital
outputs – ...
Electronics Mini-Lesson #7: Pulse Width
Modulation
0V
3.3V
0
m
s
1
m
s
2
m
s
3
m
s
4
m
s
5
m
s
A 1kHz waveform, “off” for ...
Electronics Mini-Lesson #7: Pulse Width
Modulation
0V
3.3V
0
m
s
1
m
s
2
m
s
3
m
s
4
m
s
5
m
s
This 1kHz waveform is “off”...
Electronics Mini-Lesson #7: Pulse Width
Modulation
0V
3.3V
0
m
s
1
m
s
2
m
s
3
m
s
4
m
s
5
m
s
This 1kHz waveform is “off”...
Electronics Mini-Lesson #7: Pulse Width
Modulation
● This seems stupid, but it actually works very well for a
variety of a...
Electronics Mini-Lesson #7: Pulse Width
Modulation
● The PWM pins on the Arduino Uno are either 980 Hz (pins
5 and 6), or ...
Demonstration: analogOutputs
● Behold the wonders of Pulse Width Modulation!
● What It Does: Lights up a group of LEDs all...
Demonstration: analogOutputPulse
● This program shows what's possible with small changes in
PWM duty cycle
● What It Does:...
analogInput
● Finally, we have analog inputs
● Many times you wish to know not merely whether
something is happening, but ...
analogInput
● Wire the green, yellow, and red LED up like this:
(same as digitalOutputs)
I/O 3
1kΩ
I/O 5
1kΩ
I/O 6
1kΩ
analogInput
● And, wire the potentiometer up like this:
+5V
10MΩ A0
The end terminals can be wired
up in any direction, bu...
analogInput
● Physically, it will look something like this:
Demonstration: analogInput
● This program converts an analog input into an LED
readout of sorts
Demonstration: analogInput
● This effect would require a somewhat complicated circuit
to implement if we weren't using the...
Where to go from Here?
● https://github.com/vuinguyen/ArduinoUnoBasics
● What types of projects would you like to build?
●...
The End
Thanks for Coming!
https://github.com/vuinguyen/ArduinoUnoBasics
Sunfishempire.com
@sunfishgurl
@infoGuideApps
Upcoming SlideShare
Loading in …5
×

Intro to Hardware Programming with the Arduino Uno

576 views

Published on

What you will learn from this presentation:
Basic hardware and programming concepts to get started with programming lights and sensors using the Arduino Uno.
• Writing to digital output devices with Arduino
• Reading digital inputs with Arduino
• Writing to analog output devices with Arduino
• Reading analog inputs with Arduino

This presentation was originally delivered to the Girl Develop It! / Women in Robotics meetup in Denver, CO on September 19, 2017

Published in: Technology
  • Be the first to comment

Intro to Hardware Programming with the Arduino Uno

  1. 1. Getting Started with the Arduino Uno by Eric J. Richardson and Vui Nguyen September 2017
  2. 2. Legal Disclaimer Arduino is a trademark of somebody, certainly But not us
  3. 3. Why this Presentation? ● Last year, we started doing IoT when we entered the Intel IoT Roadshow ●“Save the Water Pipes” was an automated faucet dripper – handy to prevent pipes from freezing and breaking in cold climates like Colorado! ● Vui: software architect ● Eric: hardware engineer ● Crystal: web developer
  4. 4. Why this Presentation? ●We entered our project in the US-China Young Maker Competition (Sponsored by Intel) and competed in China! ● Vui presented our “Save the Water Pipes” project to Women Who Code ● Several of the Women Who Code had questions about the Intel Edison board which powered our project
  5. 5. Why this Presentation? ● There was a lot of interest in the Intel Edison ● The Edison is cool, but at $100 it’s a bit pricey to get started with an embedded computing project ● so Eric did a follow up presentation at WWC on the Raspberry Pi ● Why the Raspberry Pi?
  6. 6. Why this Presentation? ● Raspberry Pi is a great value, single-board computer, and can be used as the basis for many projects ● At Raspberry Pi presentation, Eric also provided a good overview of electronics and hardware concepts ● But there is a lot of setup with Raspberry Pi just to get started ● With Arduino Uno, you could get up and running much more quickly, for as much money, with less equipment and setup
  7. 7. Who is this Presentation For? ● This presentation is for software devs interested in learning about hardware ● You should, by the end, know enough to get an Arduino Uno up and running, and writing Arduino sketches ● And, hopefully, driving electronic circuits ● We hope that we cover at least one thing you already know, and at least one thing you don't ● If you have a question about something, please ask! We may wave it off as something we cover later
  8. 8. Personal Disclaimer For those of you who are already familiar with all of this, Eric apologizes if he sounds like he's “mansplaining”! He now has Vui co-presenting to help with this.
  9. 9. Who Are We? Eric J. Richardson Lockheed Martin Systems Engineer Colorado State University B.S. Electrical & Computer Engineering, 2004 LIKES: DISLIKES: ● Antique Cars ● Dogs ● Shadowrun ● Cajun Food ● Old Video Games ● Hand Tools ● Cool Boots ● Cancer ● Fascism ● Lasagna ● TV Commercials Which Assume I'm Familiar with Sports Stars
  10. 10. Who Are We? Vui Nguyen SimplyE iOS Developer Colorado School of Mines B.S. Computer Science, 1999 University of Denver M.S. Computer Science, 2006 LIKES: DISLIKES: ● Fishing ● Eating ● Fishing ● Traveling ● Fishing ● Dogs ● Fishing ● Not Fishing Enough ● Sexism ● Doing Dishes ● Negativity ● Being asked, “Where are you from?”
  11. 11. Who Are We Not? ● We are not graphic artists! ● We are not full-fledged Arduino experts! ● We fully expect someone here to ask us a question we don't know the answer to
  12. 12. What is “Arduino”? ● 3 things: – Arduino is an Italian company that designs low-cost computers designed to interact with physical hardware ● These are open-source hardware designs – “Arduino-compatible” boards have special I/O ports that allow the boards to be expanded with plugin-in modules called shields – It’s also the Arduino-specific programming language (based on C++) and IDE ● We will be working with the Arduino Uno board
  13. 13. Arduino Uno: What Does It Have? Arduino Uno ● 14 Digital Input / Output pins (6 of these can be used as Analog outputs) ● 6 Analog inputs ● Atmel 8-bit microcontroller ● USB or plug-in power ● Arduino-compatible I/O; can plug in additional “shields” ● Ability to run Arduino sketches without any additional software installation ● Low-low price of ~$25
  14. 14. Arduino Uno: What Does It NOT Have? The Arduino Uno does not have one of everything. Some things you can add, and some things you have to live without: ● Networking capability ● Multi-computing ● Native graphics or sound capability ● Case ● Huge Processing Power ● Full-blown O/S
  15. 15. Arduino Uno: Required Equipment ● Arduino Uno ($25) ● USB A/B (male / male) cable ● 9V or 12V, center-pin-positive, 500mA (or more) power supply (optional)
  16. 16. Electronics Mini-Lesson #1: Voltage, Current, Power, and Charge Direct-Current electricity has 4 dimensions: ● Voltage: How Hard The Electricity is Pushing – measured in Volts, or V (also mV) ● Current: How Much Electricity is Flowing Right Now – measured in Amperes, or Amps, or A (also mA) ● Power: How Much Work Electricity is Doing Right Now – measured in Watts, or W (also mW, kW, MW, etc.) ● Charge: How Much Electricity There Is – measured in Coulombs, or more usefully, Amp-Hours (also mAh)
  17. 17. Electronics Mini-Lesson #1: Voltage, Current, Power, and Charge ● What we call a power supply is a constant-voltage source – That is, a power supply will deliver its rated output voltage up to its rated current output – So, a 19.5V power supply, rated for 6.7A of output, can deliver up to and including 6.7A without ill effect
  18. 18. Electronics Mini-Lesson #1: Voltage, Current, Power, and Charge ● Power supplies can also deliver less than their rated current output! – They only deliver the current that the circuit “needs” (more on this later) – But, they always deliver the voltage that they are rated for (unless they are overloaded) ● So, you can use a power supply rated for more current than you need ● BUT, DO NOT use a power supply rated for more Voltage than you need!
  19. 19. Electronics Mini-Lesson #1: Voltage, Current, Power, and Charge Electrical Power is always calculated by this formula: Power = Voltage x Current Or, if you prefer: Watts = Volts x Amps So, if you know the voltage and the current, you know the power being delivered. Back to our earlier example, the 6.7A @ 19.5V power supply is capable of delivering: 19.5V x 6.7A = 130W
  20. 20. Electronics Mini-Lesson #1: Voltage, Current, Power, and Charge ● Batteries, as far as circuits are concerned, work the same as power supplies – A battery will deliver its rated voltage up to its rated current, though battery manufacturers do not always tell you the rated current ● The biggest difference is that you also have to worry about the charge of a battery, which you do not have to worry about with a power supply – A battery with a greater charge capacity (in amp- hours, or Ah) will “last” longer between chargings
  21. 21. Arduino Uno: Optional Equipment ● breadboard ($5, but get 2, or 1 big one) ● Single Pole/Single Throw Normally Open Switch ($2) ● 1kΩ resistors ($1)
  22. 22. Arduino Uno: Optional Equipment ● LED Assortment ($6) ● Male-to-Male Jumpers ($8) ● 1MΩ Potentiometers ($3)
  23. 23. Install Arduino IDE ● Download and install Arduino IDE for your OS – https://www.arduino.cc/en/Guide/HomePage ● Follow instructions to “Install the board drivers”: – https://www.arduino.cc/en/Guide/ArduinoUno – And, from the same page, “Select your board type and port” ● Sample code to get started: – https://www.arduino.cc/en/Tutorial/BuiltInExamples
  24. 24. Hardware Building Blocks ● We will going to focus the rest of this presentation on using the Arduino Uno as the basis of a hardware project ● This will take the form of the “Four Building Blocks” of physical computing: – Digital Output – Digital Input – Analog Output – Analog Input
  25. 25. Hardware 100 – Blink an LED ● Before that, let's make sure the darn thing turn on ● Making sure you can get an LED to blink should always be the first thing you do with any new hardware project – It's the “Hello World” of hardware
  26. 26. blinkOneLED ● Wire the green LED up like this: I/O 3 1kΩ
  27. 27. blinkOneLED ● Physically, it will look something like this:
  28. 28. Demonstration: blinkOneLED ● Let's make sure everything works!
  29. 29. Electronics Mini-Lesson #2: Circuits, Open Circuits, and Short Circuits First, some terminology. This is a circuit diagram: + _Vin Voltage Source Load (resistor) + _ Current
  30. 30. Electronics Mini-Lesson #2: Circuits, Open Circuits, and Short Circuits ● Current flows out of the positive (+) terminal of the Voltage Source, through the circuit, and into the (-) terminal of the Voltage Source ● The amount of current that flows is given by Ohm's Law: ● Where E is Voltage, I is current, and R is the Resistance of the load, in Ohms (Ω) ● Current I can also be express as: E = I x R I = E R
  31. 31. Electronics Mini-Lesson #2: Circuits, Open Circuits, and Short Circuits ● So, for example, if Vin were 3.3V, and the load was 1kΩ, the current in this circuit would be 3.3V / 1000Ω = 3.3 mA ● What if we were to take the load out of the circuit? + _Vin
  32. 32. Electronics Mini-Lesson #2: Circuits, Open Circuits, and Short Circuits ● In this case, current cannot flow, because there is no electrical path from the positive terminal of the voltage source to the negative one. ● This is called an open circuit. ● Think of it as an infinite-resistance load. – So, 3.3V / ∞Ω = 0A ● But what happens if we replace the load resistor with a wire?
  33. 33. Electronics Mini-Lesson #2: Circuits, Open Circuits, and Short Circuits + _Vin Current? ● Wires have a resistance of 0Ω ● So, the current through the system is: 3.3V / 0Ω ● That would be infinite current, if the voltage source could supply infinite current!
  34. 34. Electronics Mini-Lesson #2: Circuits, Open Circuits, and Short Circuits ● Instead, the voltage source will attempt to supply as much current as it can – enough to trip a circuit breaker, or more likely, burn up a wire, or the voltage source itself ● This is called a short circuit ● Do not wire up a short circuit! That's how you burn up components, and destroy circuit boards
  35. 35. Electronics Mini-Lesson #3: GND and Vin Second, some shorthand. This takes time to draw: + _Vin
  36. 36. Electronics Mini-Lesson #3: GND and Vin ● So, we will use two convenient shorthands. ● The positive terminal of the voltage source, and anything connected to it, we call Vin, or we just name it whatever the input voltage is (such as 3.3V) ● We denote it with this symbol: ● The negative terminal of the voltage source, and anything connected to it, we call GND (“ground”). ● We denote GND with this symbol: Vin
  37. 37. Electronics Mini-Lesson #3: GND and Vin So: + _Vin Vin ==
  38. 38. Electronics Mini-Lesson #4: Breadboards ● Breadboards are useful for wiring up circuit prototypes without soldering ● There are different types, but they mostly look something like this: ● The magic of a breadboard is that you can plug one wire into one hole, and have it be electrically connected to another wire plugged into another hole
  39. 39. Electronics Mini-Lesson #4: Breadboards ● The electrical connections are arranged like so: ● It is helpful to plug Vin into the + rail, and GND into the – rail ● On either side of the channel are 5 pins all connected to each other
  40. 40. Electronics Mini-Lesson #4: Breadboards ● Breadboards cannot carry infinite current without burning up! – If your circuit needs to carry more than about 500mA, I recommend not using a breadboard and jumpers: get some thicker-gauge, dedicated wires ● Breadboards cannot handle infinite voltage without arcing internally! – If your circuit needs to deliver more than about 24V, I recommend not using a breadboard and jumpers: get some wires with thicker insulation ● These numbers give a wide safety margin
  41. 41. Electronics Mini-Lesson #5: LEDs ● “LED” stands for “Light Emitting Diode” ● They do not behave like resistors! We can model them like this: + _VD RD
  42. 42. Electronics Mini-Lesson #5: LEDs ● VD is around 1.8V, while RD is not very much – on the order of 2Ω or so ● So, if you were to attach a 3.3V voltage source directly to the LED, you would get: ● This might not sound like much, but the output pins of the Arduino Uno can only output about 40mA or so apiece– if you were to “ask” them for 750mA, it could shut down or even damage the Arduino Uno (3.3V – 1.8V) / 2Ω = 750mA
  43. 43. Electronics Mini-Lesson #5: LEDs ● This is why each LED needs a 1kΩ resistor in series with it: Vin 1kΩ ● If the LED is too dim, try a 470Ω resistor ● If the LED is too bright, try a 2kΩ resistor
  44. 44. Electronics Mini-Lesson #5: LEDs ● Finally, LEDs are diodes, and the magic of a diode is that they only allow current to flow in one direction ● The flat part of the diode bulb, or the shorter of the two legs, should be oriented towards GND ● See http://media.bemyapp.com/control-led-lights/
  45. 45. digitalOutputs.py ● Wire the green, yellow, and red LED up like this: I/O 3 1kΩ I/O 5 1kΩ I/O 6 1kΩ
  46. 46. digitalOutputs ● Physically, it will look something like this:
  47. 47. Demonstration: digitalOutputs ● Prepare to have your mind BLOWN! ● What it does: lights up a series of LEDs, one at a time, in round robin fashion ● The Magic: – Set LED pin mode to OUTPUT: we’re sending signals out to the LEDs, not receiving from them – Set digital write to HIGH to turn LED on – Set digital write to LOW to turn LED off – State is whether LED is currently on or off – Check state of current LED in loop to determine which LEDs need to be turned off/on
  48. 48. digitalInput ● Leaving the LEDs in place, wire the switch like this: I/O 12 This is a single-throw switch. It only has one position in which the circuit is completed. For a “normally open” switch, the connection to GND will be made when you close the switch (press the button)
  49. 49. digitalInput ● Physically, it will look something like this:
  50. 50. Electronics Mini-Lesson #6: Pull-Ups / Pull- Downs When the switch is closed, the circuit will look like this: Now, the I/O pin is connected to GND, which the Arduino Uno will read as “LOW.” I/O 12
  51. 51. Electronics Mini-Lesson #6: Pull-Ups / Pull- Downs What is I/O 12 connected to when the switch is open? ● It's not connected to LOW anymore, but it's also not connected to HIGH ● A digital input only has two options, so the Arduino Uno must read it as LOW or HIGH, but you don't know which one it will “pick” ● This is called a “floating input,” and it is bad, because you never know what you're going to get! I/O 12
  52. 52. Electronics Mini-Lesson #6: Pull-Ups / Pull- Downs ● We can avoid floating inputs with “pull-up” and “pull-down” resistors ● A pull-up will leave the input pin to read HIGH in the absence of any other connection, while a pull-down will leave a floating input to read LOW ● The Arduino Uno can implement pull-ups (but NOT pull- downs) in code, as you will see ● Double-throw switches may not actually need pull-ups or pull-downs, but it won't hurt anything if you implement them anyway I/O 12 Vin
  53. 53. Demonstration: digitalInput ● Pretty much the same as digitalOutputs, until you press the button ● What it does: Light up a series of LEDs, one at a time, in round robin robin. Press a button to make the LEDs light up in the opposite direction and at a faster speed. ● The Magic: – Same concepts as digitalOutputs, but this time uses an array of LED pins – For each LED pin in array, turns LED on, pauses, turns LED off – If button is not pressed, continue moving “forward” in turning LEDs on / off – If button is pressed, move backwards to turn LEDs on /off
  54. 54. analogOutputs ● Wire the green, yellow, and red LED up like this: (same as digitalOutputs) I/O 3 1kΩ I/O 5 1kΩ I/O 6 1kΩ
  55. 55. Arduino Uno I/O By the way, why did we pick pins 3, 5, and 6, of all the pins that we could have picked? Because those pins are 3 of the Input / Output pins that can also act as analog outputs (PWMs) These pins are denoted by the ~ symbol
  56. 56. Electronics Mini-Lesson #7: Pulse Width Modulation ● Because of the nature of field-effect transistors, digital outputs – either HIGH or LOW – are easy for a computer to generate ● Analog outputs, which may have a value between HIGH and LOW – say, 1.7V, or 2.2V, or 3.1V – are NOT easy to generate ● However, since we mostly only need analog outputs for physical devices, which cannot instantly turn on and off, we can simulate an analog input by rapidly turning a digital signal off and on, and varying the percentage of time the signal is “on”
  57. 57. Electronics Mini-Lesson #7: Pulse Width Modulation 0V 3.3V 0 m s 1 m s 2 m s 3 m s 4 m s 5 m s A 1kHz waveform, “off” for 50% of the time, and “on” for 50% of the time. The “duty cyle” is 50%. The output voltage is effectively half of the maximum, or 1.65V
  58. 58. Electronics Mini-Lesson #7: Pulse Width Modulation 0V 3.3V 0 m s 1 m s 2 m s 3 m s 4 m s 5 m s This 1kHz waveform is “off” for 75% of the time, and “on” for 25% of the time. The “duty cyle” is 25%. The output voltage is effectively one-quarter of the maximum, or .825V
  59. 59. Electronics Mini-Lesson #7: Pulse Width Modulation 0V 3.3V 0 m s 1 m s 2 m s 3 m s 4 m s 5 m s This 1kHz waveform is “off” for 25% of the time, and “on” for 75% of the time. The “duty cyle” is 75%. The output voltage is effectively three-quarters of the maximum, or 2.48V
  60. 60. Electronics Mini-Lesson #7: Pulse Width Modulation ● This seems stupid, but it actually works very well for a variety of applications – Your car's fuel injectors – Throttling the electric motors in a quadcopter – Anti-lock brakes ● A PWM signal has two properties: the frequency and the duty cycle – The frequency should be fast enough that whatever you're driving operates smoothly, and slow enough to avoid high-frequency impedence
  61. 61. Electronics Mini-Lesson #7: Pulse Width Modulation ● The PWM pins on the Arduino Uno are either 980 Hz (pins 5 and 6), or 490 Hz (pins 3, 9, 10, and 11) – Both of these frequencies are much too fast for the eye to notice an LED flickering ● The duty cycle can be anywhere between 0 (0%) and 255 (100%) – If you want a percentage duty cycle, you must multiply by 255 and divide by 100 to set the PWM
  62. 62. Demonstration: analogOutputs ● Behold the wonders of Pulse Width Modulation! ● What It Does: Lights up a group of LEDs all at once, at different intervals/steps, from dimmest to brightest and back to dim again ● The Magic: – Instead of just turning on the LEDs all the way on or all the way off, analog output lets us light up the LED within a range of dimmer settings – The settings are in large intervals/steps
  63. 63. Demonstration: analogOutputPulse ● This program shows what's possible with small changes in PWM duty cycle ● What It Does: Gradually lights up a group of LEDs all at once, from dimmest to brightest and back to dim again ● The Magic: ● Much like analogOutputs, except with PWM, the dimmer settings can be much smaller intervals / steps ● Changes in the dim settings can be much more gradual
  64. 64. analogInput ● Finally, we have analog inputs ● Many times you wish to know not merely whether something is happening, but how much it is happening ● Many sensors – temperature sensors, light sensors, pressure sensors, etc. – will deliver an output voltage as a reaction to whatever they're sensing ● We will model this voltage with a potentiometer (variable resistor)
  65. 65. analogInput ● Wire the green, yellow, and red LED up like this: (same as digitalOutputs) I/O 3 1kΩ I/O 5 1kΩ I/O 6 1kΩ
  66. 66. analogInput ● And, wire the potentiometer up like this: +5V 10MΩ A0 The end terminals can be wired up in any direction, but the center terminal should point to the analog input pin
  67. 67. analogInput ● Physically, it will look something like this:
  68. 68. Demonstration: analogInput ● This program converts an analog input into an LED readout of sorts
  69. 69. Demonstration: analogInput ● This effect would require a somewhat complicated circuit to implement if we weren't using the microcontroller ● What It Does: Gradually light up each LED, one at a time, as we turn up the knob on the potentiometer, and then gradually dim each LED, one at a time, as we turn down the knob on the potentiometer. ● The Magic: – Cycling through an array of LEDs, based on the value of the potentiometer, turn the current LED all the way on, all the way off, or somewhere in between – The “in between” is the analog value
  70. 70. Where to go from Here? ● https://github.com/vuinguyen/ArduinoUnoBasics ● What types of projects would you like to build? ● Interest in hands-on workshop? – For nominal fee through GDI (‘cause these workshops take a lot of work to create!) – We can help you build that cool thing you’ve been wanting to build – Sign up for our email list to give us input ● Educators – We can help you create a course for your students – just ask us! ● Please take our survey by Friday, September 22: https://goo.gl/forms/7dn6avLltAg28StD2
  71. 71. The End Thanks for Coming! https://github.com/vuinguyen/ArduinoUnoBasics Sunfishempire.com @sunfishgurl @infoGuideApps

×