Bogatin Arduino - Workshop - 2017 02 08
Bogatin Arduino - Workshop - 2017 02 08
• My approach:
I do
We do
You do
www.EricBogatin.com slide 1
Three Sections
www.EricBogatin.com slide 2
1
2/8/2017
Vocabulary
www.EricBogatin.com slide 3
Experiments Section 1
www.EricBogatin.com slide 4
2
2/8/2017
www.EricBogatin.com slide 6
3
2/8/2017
www.EricBogatin.com slide 7
Experiment: Heartbeat-1
• In void loop()
digitalWrite(pin#, HIGH, LOW) //changes state
www.EricBogatin.com slide 8
4
2/8/2017
void setup() { // put your setup code here, to run once: pinMode(13,OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(13,HIGH
Heartbeat-2
www.EricBogatin.com slide 9
Heartbeat-3
• Waiting using the delay() function
• Delay(500) waits for 500 msec = ½ second
• Hint: use tools/auto format to clean up the code
• Turning LED off and on with delay
www.EricBogatin.com slide 10
5
2/8/2017
Heartbeat-4
www.EricBogatin.com slide 11
Experiment Variables-1
• Variable: a place in memory to hold a piece of data
• Location identified with a name
• Two common types of numbers:
Integers (whole numbers, -3, -2, -1, 0, 1, 2, 3)
Floating point (with a decimal point: 3.1415 x 103)
www.EricBogatin.com slide 12
6
2/8/2017
Variables-2
www.EricBogatin.com slide 13
Variables-3
www.EricBogatin.com slide 14
7
2/8/2017
www.EricBogatin.com slide 15
External LED -2
www.EricBogatin.com slide 16
8
2/8/2017
LED -3
www.EricBogatin.com slide 17
Experiment: Tone-1
9
2/8/2017
Experiment: Tone-2
• Testing tone:
Open up and use a NEW sketch to exercise any function
On pin 11, play a note for 2 second, then a different one
www.EricBogatin.com slide 19
Tone-3
• Connect up a buzzer
• Pin spacing between the buzzer
leads = 3 pins
• One side to pin 11 with tone, pin 8
as other pin
• Pin 8 set to HIGH or to LOW
• Remember pinMode
www.EricBogatin.com slide 20
10
2/8/2017
Tone-4
• Simple exercises:
Play a single frequency for 0.3 sec
Play multiple tones
www.EricBogatin.com slide 21
Tone-5
www.EricBogatin.com slide 22
11
2/8/2017
Tone-6
}
• Good habits:
name your functions with func_ as the
beginning of the name
Initialize all variable at beginning of sketch
(as global variables)
www.EricBogatin.com slide 23
www.EricBogatin.com slide 24
12
2/8/2017
Servo Motors-2
0 degrees
180 degrees
www.EricBogatin.com slide 25
Servo Motors-3
www.EricBogatin.com slide 26
13
2/8/2017
Servo Motors-4
• Examples:
Use for loop to sweep servo back and forth like
a radar sweep
How fast can you sweep?
How to adjust the sweep time?
Use servo with arrow as analog voltage meter
www.EricBogatin.com slide 27
EricBogatin.com 28
14
2/8/2017
Section 2
• Electronics
www.EricBogatin.com slide 29
15
2/8/2017
An Electricity Analogy-2
• Questions
What is the sign of the charge carriers?
What direction does current flow in a
circuit?
What direction does current flow in a
battery?
What drives the current?
What limits the current?
What is the resistance in a wire?
If the voltage increases, what happens to the
current in a circuit?
If resistance increases, what happens to the
http://www.windows2universe.org/physical_science/physics/electricity/circuit_analogy_water_pipes.html
current in a circuit?
What is ground?
EricBogatin.com slide 31
An Electricity Analogy-3
• Questions
What would happen if:
5v =
EricBogatin.com slide 32
16
2/8/2017
Experiment:
Using DMM to measure voltages-1
• Goal: get comfortable with voltage
measurements
• Principles:
Voltage is always the voltage difference
between two points
Voltage difference is the “pressure” that
drives current
How much current depends on the voltage
and series resistance
“gnd” is the label for the lowest voltage in
circuit, usually a pin of the power supply
• Good habits:
Black is always com
Red is always multi function
Use the most sensitive scale that is still
not off scale
www.EricBogatin.com slide 33
17
2/8/2017
I
+ -
DV
V V IR
V IR V
I V
V
R I R R
I
R I
V
R
I
www.EricBogatin.com slide 36
18
2/8/2017
Resistor Properties-2
• V = 5 v supply
R = 100 Ohms, What is I?
V
R = 15 Ohms, what is I?
• I = 100 mA
R = 100 Ohms, what is V? I R
R = 0.1 Ohms, what is V?
• R = 1 Ohm
V = 0.2 v, what is I?
V = 10 v, what is I?
HackingPhysics.com slide 37
V R I
voltage
www.EricBogatin.com slide 38
19
2/8/2017
Resistor Properties-4
V V 5V
R I
I R 330
www.EricBogatin.com slide 39
Resistor Properties-5
current
V
voltage R
I
www.EricBogatin.com slide 40
20
2/8/2017
www.EricBogatin.com slide 41
www.EricBogatin.com slide 42
21
2/8/2017
Experiment
Engineer an LED Circuit
• Goal: Engineer a circuit to drive 10
mA thru LED
• What value resistor to use?
• When the LED is on, voltage across
it is about 2 V, independent of the
current.
• If pin voltage is 5 V, what is the
voltage across the resistor?
• For 10 mA, what resistance do you
need?
V 5 2V 3V
• Build it, measure it R 300
I 0.01A 0.01A
www.EricBogatin.com slide 43
Requiv R1 R 2 Requiv R1 R1 2 R1
1 1 1
R equiv R1 R 2 1
Re quiv R1
1 1 1 2 2
Requiv R1 R1 R1
www.EricBogatin.com slide 44
22
2/8/2017
www.EricBogatin.com slide 45
Time
23
2/8/2017
options:
Analog, or digital
Bandwidth: 10 MHz
1 GHz
Standalone, USB
Old, new Recommended, best
value first scope:
PicoScope 2204A
1 channel 4 https://www.picotech.com/
channel products/oscilloscope
www.EricBogatin.com slide 47
www.EricBogatin.com slide 48
24
2/8/2017
www.EricBogatin.com slide 49
Projects
www.EricBogatin.com slide 50
25
2/8/2017
• In void loop():
Serial.print(iVar1);
Serial.println(iVar2); (as the last line)
Delay (100);
• Serial.print(number)
• Serial.print(“text”) // prints on same line
• Serial.println(number) // line feed
• Exercises:
Print the integers from 1 to 32000
(hint, use iValue=iValue++)
How fast a baud rate can you go?
Print the random frequency values generated in 10-150 Tone, as it
plays
Copy and paste numbers into an excel spreadsheet
Open serial plotter
EricBogatin.com
52
26
2/8/2017
Experiment
PWM (Pulse Width Modulation) output
www.EricBogatin.com slide 53
www.EricBogatin.com slide 54
27
2/8/2017
www.EricBogatin.com slide 56
28
2/8/2017
www.EricBogatin.com slide 57
www.EricBogatin.com slide 58
29
2/8/2017
Set up wiring
Try color coding the wires
9
11
10
https://www.sparkfun.com/products/10988
www.EricBogatin.com slide 60
30
2/8/2017
• Resolution
At 10 bit: 0 1023 adu and 0 v 5 v
1 bit = 1 adu is 5 V/1023 adu ~ 5 mV/bit= 5 mV/adu = 0.005 V/adu
Temperature sensor is 10 mV/deg C = 0.01 V/degC, or 100 degC/V
Resolution is 100 degC/V x 0.005 V/adu = 0.5 degC/adu
Sketch: read A0, convert to temperature
• Types of variables
Integers: long, -2,147,483,648 to 2,147,483,647, whole numbers
Float: -3.4028235E+38 to 3.4028235E+38
www.EricBogatin.com slide 61
Scaling:
T[degF] = T[degC]*9/5 + 32
www.EricBogatin.com slide 62
31
2/8/2017
• Algorithm
Read the analog channel (A0): analogRead(A0)
Add the units to the end of the variable
Convert adu voltage
Convert voltage temperature degC
Convert temperature degC temperature degF
Print to serial monitor: Serial.println(temp_degF)
Look on serial plotter (plots variable on strip chart)
www.EricBogatin.com slide 63
www.EricBogatin.com slide 64
32
2/8/2017
Experiment:
10-190 The Resistance Potentiometer (pot)
www.EricBogatin.com slide 66
33
2/8/2017
Experiment 10-200
Turn a Resistive Sensor into a Voltage
• Sensors: flex, pressure, thermistor
Rsensor
Vout Vsource
R1 Rsensor
• Convert to R of sensor
Vout
• Print R sensor Rsensor R1
Vsource Vout
• Plot R of sensor
EricBogatin.com slide 67
• What do we do?
www.EricBogatin.com slide 68
34
2/8/2017
www.EricBogatin.com slide 69
• Like:
Motors
Speakers
Big LEDs (still need current limiting resistor)
Large relays
www.EricBogatin.com slide 70
35
2/8/2017
• Driving a motor
• Normally rated at 5 v, but needs 100 mA- 200 mA
• Arduino digital pin ~ 40 mA-90 mA (can’t drive the motor)
• Use transistor follower circuit
• Add R1 = 1k Ohms as safety- limits max pin current to 5 V/ 1 kOhm = 5 mA
• Now motor can get art least 5 mA x 50 = 250 mA current
www.EricBogatin.com slide 71
Experiment: 10-230
What the Heck is Ground?
• The is no such thing as an absolute voltage.
• There is only voltage difference.
• We measure the voltage of one node relative to or “with
respect to” another location
• We call the low voltage side of a circuit, “circuit ground.”
• All circuit ground nodes in a circuit are connected together.
• Voltages in a circuit are really voltage differences from the
low side as the reference.
• There are really 3 kinds of “ground”. Each are different.
HackingPhysics.com slide 72
36
2/8/2017
• Earth Ground
• Earth ground is literally the connection to the physical
ground, with a copper stake in the ground.
Voltage difference between different stakes typically very small
Defines a convenient reference point
HackingPhysics.com slide 73
• Chassis Ground
• If the enclosure is metal, there
is a screw drilled into it
connected to a wire.
• Can be connected to earth
ground (required by UL), but
doesn’t have to be.
• Sometimes connected to circuit
ground, but not always.
• Plastic enclosures do not have a
chassis ground.
HackingPhysics.com slide 74
37
2/8/2017
• Floating Ground
• “Circuit ground” is often the low voltage side in a circuit or power supply
• If the circuit ground is not connected to earth ground, we say, the low side is “ground”
but “floats” above earth ground.
• Floating grounds are in:
Cars
Planes
Satellites
Cell phones
Battery powered devices
Devices plugged into the wall with two prong plugs
Devices plugged into wall with “wall adapters”
Watch out!
HackingPhysics.com slide 75
Input resistance of
an ideal voltmeter
= infinite R = 1 MegOhm
slide 76
38
2/8/2017
slide 77
Rinternal
• What is internal R?
• How does it vary with scale?
Rexternal
slide 78
39
2/8/2017
slide 79
Vopen Vloaded
Rint ernal Rload
Vloaded Vloaded
I
Rload
slide 80
40
2/8/2017
Vopen Vloaded
Rint ernal Rload
Vloaded
slide 81
Vopen Vloaded
Rint ernal Rload
Vloaded
5.256 5.235
Rint ernal 329 1.32
5.235
slide 82
41
2/8/2017
Voltage source:
Vopen = Vopen Vloaded
Rload =
Vloaded = I Rload
Rinternal=
Vopen Vloaded
Rint ernal Rload
Vloaded
slide 83
84
EricBogatin.com
42