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
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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Arduino Uno: Optional Equipment
● breadboard ($5, but get 2, or 1 big one)
● Single Pole/Single Throw
Normally Open Switch ($2)
● 1kΩ resistors ($1)
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. 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. 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
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. 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. 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. 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. 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. 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
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
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. 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. 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. 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. 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. 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. 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/
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. 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)
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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
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. 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. The End
Thanks for Coming!
https://github.com/vuinguyen/ArduinoUnoBasics
Sunfishempire.com
@sunfishgurl
@infoGuideApps
Editor's Notes
Vui
Eric
Vui
Vui
Eric
Eric
Eric
Eric
Vui
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Vui
Eric
Eric
Eric
Eric
Vui
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Vui
Ask: would anyone like to provide a real-world example of a digital output?
Eric
Eric
Eric
Eric
Eric
Vui
Ask: What’s a real-world example of a digital input?
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Eric
Vui
Vui
Ask: Any more real-world examples of analog outputs?
Eric
Eric
Eric
Eric
Vui
Vui
Ask: Finally, any more real-world examples of analog inputs?