2017-11-21 07:03:24 -05:00
---
author: Titus Ferguson, Shawn Nock
institute: UnPacked Digital Literacy
title: Arduino for the Classroom
subtitle: Let's Talk Science Instructional Design Team
lang: en-CA
colorlinks: true
...
## Goals
By the end of this class, you'll:
- Be familiar with basic electionics concepts
2017-11-22 07:26:54 -05:00
- Assemble a kit of sensors into a complete system
- Know how to program the Arduino platform to collect and plot the sensor data
2017-11-21 07:03:24 -05:00
## UnPacked / Unlondon
\begin{center}
{\huge Enabling Exploration, Creativity, and Excellence In Art+Make+Tech}
\end{center}
Challenging and embracing ideas related to new technologies and social
platforms through the education, entertainment and engagement of our
membership and the community-at-large.
- 121Studios: Coworking for Creatives
- STEAM Outreach & Education
- ExplodeConf
- Nuit Blanche
# What's in your kit?
## Kit Contents
###Arduino Uno R3
###Solderless Breadboard
###Connecting wires
###Sensors
- Temperature / Humidity
- Light Sensor
2017-11-22 07:26:54 -05:00
- CO2 Gas Sensor
2017-11-21 07:03:24 -05:00
## What is Arduino?
2017-11-22 07:26:54 -05:00
\center{\includegraphics[width=0.75\textwidth]{images/arduino-annotated.png}}
2017-11-21 07:03:24 -05:00
It's a kit (on a board) with the bare minimum components to easily use the $\mu$C
hardware. They do the basic, boring design needed for any board, so users only
need to add the neat stuff.
## Arduino Software
The Arduino folks also adapted an *Integrated Development Environment*
(IDE) to their boards. This IDE allows us to easily write programs for
2017-11-22 07:26:54 -05:00
their boards and then transfer the programs to the $\mu$C.
2017-11-21 07:03:24 -05:00
\Large Get the Arduino IDE:
[https://www.arduino.cc/en/Main/Software ](https://www.arduino.cc/en/Main/Software )
2017-11-22 07:26:54 -05:00
Get the libraries and sample code for this workshop:
[https://monadnock.ca/lts-workshop-Nov2017.zip ](https://monadnock.ca/lts-workshop.zip )
2017-11-21 07:03:24 -05:00
<!-- ## Installation -->
<!-- \Large Get installing -->
# Circuit Basics
## Current
Current is the flow of charge through a circuit. Measured in Amperes
(\si{\ampere}).
## Resistance / Impedance
Circuits have a resistance to current flow that depends on the parts
in the circuit.
Measured in Ohms (\si{\ohm})
## Voltage
Voltage is a potential (akin to a pressure) pushing the current
through a circuit. Current is said to flow from higher (+) voltage
to lower (-) voltage.
Measured in Volts (\si{\volt})
## Ohm's Law; Light
Voltage, Current and Resistance are related to each other.
- As voltage increases, current increases
- As voltage decreases, current decreases
- As resistance increases, current decreases
- As resistance decreases, current increases
## \si{\volt}, \si{\ohm}, \si{\ampere}: The Water Analogy
If charge were water, then:
- resistance = obstacles blocking flow
- current = flow rate
- voltage = change in height *or* pressure.
## Diode
\begin{columns}[c]
\column{0.50\textwidth}
\begin{itemize}
\item One way value for current\footnotemark[1]
\item LED $\equiv$ Light Emitting Diode
\item Band marks (-)\footnotemark[2]
\item Longer leg marks (+)
\end{itemize}
\column{0.50\textwidth}
\begin{center}
\includegraphics[width=0.75\textwidth]{images/diode.png}
\vspace{5mm}
\includegraphics[width=0.50\textwidth]{images/led.jpg}
\end{center}
\end{columns}
\footnotetext[1]{\tiny \url{https://learn.sparkfun.com/tutorials/diodes}}
\footnotetext[2]{\tiny \url{https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity}}
## Diode Problems
* Diodes don't limit current
* Diodes aren't perfect (some current turned to heat)
* Too much current $\rightarrow$ Too much heat $\rightarrow$ \
\
\center{ \huge{\emph{What's that smell?} } }
## Resistor
\begin{columns}[c]
\column{0.50\textwidth}
\begin{itemize}
\item \emph{Resists}/limits the flow of current
\item Needed for LEDs: $\approx\SI{1000}{\ohm}$\\
\item Button Pull-up/down: $\ge\SI{10}{\kilo\ohm}$
\item Color coded, Google it
\end{itemize}
\column{0.50\textwidth}
\includegraphics[width=0.98\textwidth]{images/resistor.png}
\end{columns}
## Buttons
- Buttons connect _or_ disconnect two wires/parts
- Momentary Switch: Normally Closed (NC), Normally Open (NO)
- Toggle Switch
## Circuits
A circuit is a completed loop from HIGH potential (voltage) to LOW,
which causes current to flow through some other components along the
way.
## Transducers {.fragile}
Often these *other* components are *transducers* , which convert
electrical energy into another sort of energy:
| |
-------|--------:
Speaker|Electrical $\rightarrow$ Sound
Microphone|Sound $\rightarrow$ Electrical
LED|Electrical $\rightarrow$ Light
LED|Light $\rightarrow$ Electrical
Piezoelectric|Electrical $\rightarrow$ Motion
<!-- ## Piezo Buzzer -->
<!-- - Piezoelectric elements change shape when voltage is applied -->
<!-- - Thin discs can be made to oscillate and create sound. -->
<!-- - Contains oscillator circuit -->
<!-- - Two connections: Vcc, GND -->
<!-- - Use a switch; connected = annoying tone, disconnected = glorious silence -->
## Power
The power supply provides the energy to drive the system.
Can be a:
* Voltage Regulator (converts one potential to another)
* Batteries
* Solar Panel
2017-11-22 07:26:54 -05:00
In our circuits, your computer is converting it's power source to $\SI{5}{\volt}$ and
2017-11-21 07:03:24 -05:00
delivering power to our circuit via USB.
## $\mu$Controller
Microcontroller ($\mu$C) is a *processor* , *memory* and a few *peripherals* on a standalone
chip.
Processor
: is a group of transistors that understands a dozen or so
commands (ADD, SUB, JUMP..)
Memory
: a circuit that can hold values.
Peripherals
: Vary chip to chip, but often include timers, communications and
ADC, DAC.
Seems complicated, but really simple. They read a command from the
start of memory, then execute the command. At the end of the command,
read the next command from the next memory cell and
repeat^[some commands change the address of the next fetched command]
## Digital Signals
- Vcc: The power supply of the circuit elements
- GND: The reference voltage (usually \SI{0}{\volt})
- Connecting a part to Vcc = Logical 1 or High
- Connecting to GND = Logical 0 or Low
- Connecting various pins to Vcc or Ground is all the $\mu$C can do to
talk to the world [^4]
[^4]: w/o fancy peripherals or dirty tricks
## $\mu$Controller INPUT and OUTPUT
Most of the pins on the Arduino can be set for INPUT or OUTPUT mode.
2017-11-22 07:26:54 -05:00
- INPUT mode pins listen for a signal (High or Low) from another device
2017-11-21 07:03:24 -05:00
- OUTPUT mode pins drive the pin High or Low
## Floating Pins
What's happens if an INPUT mode pin tries to read the value of a pin
that is connected to nothing? Is that a $1$ or $0$?
\center{\huge {No one knows!}}
It's dependant of transient charges, static, nearby electric fields,
the phase of the moon, \ldots Whenever you want to check a digital
signal, make sure that something is *driving* it (ensuring Vcc or GND).
## $\mu$C + Digital Signals as Switches
If one end of an LED is connected to ground, and the other end is
connected to an OUTPUT pin on a $\mu$Controller, then:
- If the $\mu$C sets the pin High (Vcc, $\SI{5}{\volt}$) then current
will flow from the pin through the LED and turn it on.
- If $\mu$C sets the pin Low (GND, $\SI{0}{\volt}$) then the current
will not flow and the LED is off.
# Let's start programming
## Configure Arduino
\begin{center}
\includegraphics[width=0.98\textwidth]{images/arduino-board.png}
\end{center}
* Board: Arduino/Genuino UNO
* Port: \ldots
2017-11-22 07:26:54 -05:00
## Fetch the Class Code
Download and extract: [https://monadnock.ca/static/lts-workshop-Nov2017.zip ](https://monadnock.ca/static/lts-workshop-Nov2017.zip )
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
- File$\rightarrow$Preferences
- Browse for sketchbook
- Point it at the `sketchbook` subfolder of the extracted download
- You should now see a list of projects in the
File$\rightarrow$Sketchbook menu.
## Setup the Sensor Libraries (Sketchbook)
\begin{center}
\includegraphics[width=0.5\textwidth]{images/preferences.png}
\includegraphics[width=0.5\textwidth]{images/preferences2.png}
\end{center}
For the *Sketchbook Location* browse to the extracted lts-workshop-Nov2017/sketchbook directory.
2017-11-21 07:03:24 -05:00
## The Code Environment
\begin{center}
\includegraphics[width=0.95\textwidth]{images/arduino-toolbar.png}
\end{center}
## Your first Program
~~~ C
#define LED 13
/* the setup function runs once on reset / power */
void setup() {
pinMode(LED, OUTPUT);
}
/* loop() repeats until reset or power off */
void loop() {
digitalWrite(LED, HIGH); // turn on LED
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the off LED
delay(1000);
}
~~~
2017-11-22 07:26:54 -05:00
# Lets Add Some Parts
2017-11-21 07:03:24 -05:00
## Breadboard
![Breadboard ](images/breadboard.png )\
2017-11-22 07:26:54 -05:00
2017-11-21 07:03:24 -05:00
- Connectors gently pinch component leads, wires.
- Have internal connections
## Power Up the Rails
We use the long rows to distribute power. The Arduino outputs
$\SI{5}{\volt}$ on the pin marked `5V` , the reference (GND) is marked
`GND` .
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.92\textwidth]{images/rails.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## DHT11: Temperature and Humidity Sensor
2017-11-21 07:03:24 -05:00
\begin{center}
2017-11-22 07:26:54 -05:00
\includegraphics[width=0.98\textwidth]{images/dht11-wide.png}
2017-11-21 07:03:24 -05:00
\end{center}
2017-11-22 07:26:54 -05:00
## DHT11: Zoom
2017-11-21 07:03:24 -05:00
\begin{center}
2017-11-22 07:26:54 -05:00
\includegraphics[width=0.25\textwidth]{images/dht11-zoom.png}
2017-11-21 07:03:24 -05:00
\end{center}
2017-11-22 07:26:54 -05:00
Connect left pin to Vcc rail ($+$) and right pin to GND ($-$) rail. Second from left connects to Arduino pin #2 *and* a resistor to Vcc
2017-11-21 07:03:24 -05:00
## Pullup / Pulldown Resistors
2017-11-22 07:26:54 -05:00
The DHT11 uses an *Open Collector* output that switches between *Not Connected* and *Connected to Ground* . When it's not connected, the pin is left *floating* . How do we make a floating pin look like a High signal?
2017-11-21 07:03:24 -05:00
\vfill
**Solution:**
Connect the pin to Vcc so that it reads High; use a
resistor to prevent short circuit (limit current).
2017-11-22 07:26:54 -05:00
## DHT11: Run example code
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
We can test the sensor by running sample code from the library.
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Open the sample: File$\rightarrow$Examples$\rightarrow$DHT Sensor Library$\rightarrow$DHTtester
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Once the sample is loaded click the *upload* button (looks like right arrow)
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## Arduino Serial Monitor
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Once the sample code is uploaded, you can open the *Serial Monitor* to view the output. It can be found under:
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Tools$\rightarrow$Serial Monitor
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## DHTtester Output
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.98\textwidth]{images/monitor-dht.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
<!-- ## Programming Note: *If* Statement
2017-11-21 07:03:24 -05:00
~~~ C
if (condition) {
// body: Runs if condition true ( != 0)
} else {
// Runs if condition false ( == 0 )
}
~~~
- body code inside curly braces: `{` `}`
- **condition** evaluates to 0 $\rightarrow$ body code skipped
- else section is optional, runs if **condition** evaluates to 0
- **condition** evaluates to *not* 0 $\rightarrow$ body code runs
## Programming Note: `==`
In C-like languages, the `==` operator checks if two things
(statements, variables, \ldots) are equal to each other.
- It returns `1` if the items are equal, *or*
- It returns `0` if the items are not equal
2017-11-22 07:26:54 -05:00
-->
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## TSL2561: Ambient Light Sensor
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.98\textwidth]{images/tsl2561-wide.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## TSL2561: Zoom
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.3 \textwidth]{images/tsl-zoom.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Connect Vin to ($+$) rail, GND to ($-$) rail, SDA to Arduino pin A4 and SCL to A5
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## TSL2561: Run example code
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
We can test the sensor by running sample code from the library.
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Open the sample: File$\rightarrow$Examples$\rightarrow$Adafruit TSL2561$\rightarrow$sensorapi
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Once the sample is loaded click the *upload* button (looks like right arrow)
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## TSL2561 Sample Output
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.98\textwidth]{images/monitor-tsl.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## CCS811: Gas Sensor
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.98\textwidth]{images/CCS811-wide.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## CCS811: Zoom
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
\begin{center}
\includegraphics[width=0.3\textwidth]{images/ccs11-zoom.png}
\end{center}
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
*Vin* to ($+$) rail, GND *and* WAKE to ($-$) rail, SDA to TSL2561 SDA, SCL to TSL2561 SCL
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## CCS811: Run example code
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
We can test the sensor by running sample code from the library.
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Open the sample: File$\rightarrow$Examples$\rightarrow$Adafruit CCS811 Library$\rightarrow$CCS811_test
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Once the sample is loaded click the *upload* button (looks like right arrow)
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## CCS811 Sample Output
2017-11-21 07:03:24 -05:00
\begin{center}
2017-11-22 07:26:54 -05:00
\includegraphics[width=0.98\textwidth]{images/monitor-ccs.png}
2017-11-21 07:03:24 -05:00
\end{center}
2017-11-22 07:26:54 -05:00
# Programming
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## Part 1; Includes
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
~~~ C
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include "Adafruit_CCS811.h"
#include "DHT.h"
~~~
## Part 2; Definitions
2017-11-21 07:03:24 -05:00
~~~ C
2017-11-22 07:26:54 -05:00
#define DHTPIN 2
#define DHTTYPE DHT11
~~~
## Part 3; Objects
~~~ C
Adafruit_CCS811 ccs;
DHT dht(DHTPIN, DHTTYPE);
Adafruit_TSL2561_Unified tsl =
Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
~~~
## Programming Note: Variables
Declare a variable:
~~~ C
int button_state = HIGH;
~~~
`<type> <name> [= <initial value>];` (value optional)
It's a name, like a preprocessor `#define` , but the value can change
at *runtime*
## Part 4; Setup
~~~ C
2017-11-21 07:03:24 -05:00
void setup() {
2017-11-22 07:26:54 -05:00
Serial.begin(9600);
Serial.println("Let's Talk Science!");
dht.begin();
ccs.begin();
tsl.begin();
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
tsl.enableAutoRange(true);
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
2017-11-21 07:03:24 -05:00
}
2017-11-22 07:26:54 -05:00
~~~
## Part 4; Main Loop
~~~ C
loop () {
delay(500);
...
}
~~~
## Part 4a; Temperature / Humity Sensor Read
~~~ C
loop () {
...
float humidity = dht.readHumidity();
float temp = dht.readTemperature();
Serial.print(humidity);
Serial.print(" ");
Serial.print(temp);
Serial.print(" ");
...
}
~~~
## Part 4b; Gas Sensor Read
~~~ C
loop () {
...
ccs.readData();
int co2 = ccs.geteCO2();
int tvoc = ccs.getTVOC();
Serial.print(co2/100);
Serial.print(" ");
Serial.print(tvoc/10);
Serial.print(" ");
2017-11-21 07:03:24 -05:00
}
~~~
2017-11-22 07:26:54 -05:00
## Part 4c; Light Sensor Read
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
~~~ C
loop () {
...
sensors_event_t event;
tsl.getEvent(&event);
Serial.print(event.light/10);
...
}
~~~
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
## Part 4d; Ending the output
~~~ C
loop () {
...
Serial.println("");
}
~~~
## Complete Sensor Output
2017-11-21 07:03:24 -05:00
\begin{center}
2017-11-22 07:26:54 -05:00
\includegraphics[width=0.98\textwidth]{images/monitor-all.png}
2017-11-21 07:03:24 -05:00
\end{center}
2017-11-22 07:26:54 -05:00
## Arduino Serial Plotter
Why such a terse, boring output format?
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
Arduino has a feature where it will plot data in this specific format. You can see the plotted output by closing the Arduino Serial Monitor and Opening *Arduino Serial Plotter* (Tools$\rightarrow$Serial Plotter)
## Arduino Serial Plotter Output
2017-11-21 07:03:24 -05:00
\begin{center}
2017-11-22 07:26:54 -05:00
\includegraphics[width=0.98\textwidth]{images/plotter.png}
2017-11-21 07:03:24 -05:00
\end{center}
2017-11-22 07:26:54 -05:00
<!-- ## Programming Note: `for` Loop
2017-11-21 07:03:24 -05:00
~~~ C
for ( initializer ; condition; increment ) {
// This body will repeat while condition != 0
}
~~~
initializer
: Executed once at beginning of loop. Often used to declare a local
variable.
condition
: Loop will repeat while condition is true ($\neq0$)
increment
: Runs *after* each loop. Often used to increment variables.
\center{*All fields are optional*}
## Cylon Simulator: Part. 1; Pin Setup
~~~ C
int delay_ms;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
~~~
## Cylon Simulator: Part. 2
~~~ C
void loop () {
for (int i = 4; i < = 7; i++) {
delay_ms = analogRead(A0);
digitalWrite(i - 1, LOW);
digitalWrite(i, HIGH);
delay(delay_ms);
}
for (int i = 6; i >= 3; i--) {
delay_ms = analogRead(A0);
digitalWrite(i + 1, LOW);
digitalWrite(i, HIGH);
delay(delay_ms);
}
}
2017-11-22 07:26:54 -05:00
~~~ -->
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
<!-- ## Programming Note: `while` Loop
2017-11-21 07:03:24 -05:00
~~~ C
while ( statement ) {
// This body will repeat while condition is true
// True means statement != 0
}
~~~
initializer
: Executed once at beginning of loop. Often used to declare a local
variable.
condition
: Loop will repeat while condition is true ($\neq0$)
increment
: Runs *after* each loop. Often used to increment variables.
2017-11-22 07:26:54 -05:00
\center{*All fields are optional*} -->
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
<!-- ## Winner, Winner, Chicken Dinner
2017-11-21 07:03:24 -05:00
~~~ C
#define WINNER 5
void check_delay(int cur_led, int delay_ms) {
unsigned long start = millis();
while (millis() < start + delay_ms ) {
if (digitalRead(BUTTON) == LOW) {
if (cur_led == WINNER) {
do_winner();
} else {
while (digitalRead(BUTTON) == LOW) {
do_loser();
}
}
}
}
}
~~~
## More functions, pt. 1
~~~ C
void set_all_leds(int state) {
for (int i = 3; i < = 7; i++) {
digitalWrite(i, state);
}
}
void do_loser(void) {
buzz(500);
}
~~~
## More functions, pt. 2
~~~ C
void do_winner(void) {
set_all_leds(HIGH);
buzz(100);
delay(100);
buzz(100);
set_all_leds(LOW);
}
~~~
## Putting it Together
~~~ C
loop () {
for (int i = 4; i < = 7; i++) {
delay_ms = analogRead(A0);
digitalWrite(i - 1, LOW);
digitalWrite(i, HIGH);
check_delay(i, delay_ms);
}
for (int i = 6; i >= 3; i--) {
...
check_delay(i, delay_ms);
}
}
2017-11-22 07:26:54 -05:00
~~~ -->
# Undiscussed Issues
## Obtaining the kit
- Educators would need to order several different parts (SKUs).
- Vendors keep very little stock (~4 dozen).
- Educators may need to "google around" to find parts, most likely from abroad (US or China)
## Installing the Software
- School machines may prevent software installation
- School machines may not be conventional computers (iPads, Chromebooks)
## Troubleshooting the Build
2017-11-21 07:03:24 -05:00
2017-11-22 07:26:54 -05:00
- Breadboards aren't rugged.
- Sockets wear out quickly
- Parts may need to be wiggled
- Some parts may be DoA
- Most troubleshooting requires a Multimeter (and training on how to use it)
2017-11-21 07:03:24 -05:00
# Extra Credit
## Ohm's Law
Ohm's Law relates current to potential and resistance.
$$ V = IR $$
$$ I=\frac{V}{R} $$
$$ R = \frac{V}{I} $$
* V = Potential in Volts (\si{\volt})
* I = Current in Amperes (\si{\ampere})
* R = Resistance in Ohms (\si{\ohm})
## Ohm's Law: Example
The datasheet for an LED says that the maximum continuous current is
\SI{15}{\milli\ampere}. Your circuit operates at \SI{5}{\volt}\footnotemark[1]. How
big should your resistor be?
$$ \si{\ohm} = \frac{\SI{5}{\volt}}{\SI{0.015}{\ampere}} = 333.\overline{3}\si{\ohm} $$
How much current for our *cheet sheet* value?
$$ \si{\ampere} = \frac{\SI{5}{\volt}}{\SI{1}{\kilo\ohm}} = \SI{5}{\milli\ampere} $$
\footnotetext[1]{\tiny Actually, this calculation is inaccurate. LEDs
will have a *forward voltage drop* of between \SI{1.8}{\volt} and
\SI{3.3}{\volt} this should be subtracted from \si{\volt} above... but
it's not critical.}
## Current Limits, Arduino
- No single pin should source more that \SI{20}{\milli\ampere} (\SI{40}{\milli\ampere} is absolute max)
- Pins are ganged together in groups of 8, no group should source more
than \SI{150}{\milli\ampere} total
- The whole board cannot source more than \SI{200}{\milli\ampere} total
Practically speaking, this means that the Arduino cannot drive
speakers, most motors, or anything normally mains powered.
## So\ldots no Arduino smart blender?
You can control almost anything with an arduino, you just can't power
it with the Arduino. There are various devices that let you switch
highier powered devices:
- Transistors
- Relays
- Solid State Relays
- Triac
## HIGHs and LOWs
Many different logic levels are in common use: \SI{1.2}{\volt},
\SI{1.8}{\volt}, \SI{2.5}{\volt}, \SI{3.3}{\volt}, and
\SI{5}{\volt}. The voltage cited is the *nominal* Vcc of the system.
A HIGH signal is generally any voltage $\geq \frac{2}{3}V_{cc}$.
A LOW signal is generally any voltage $\leq \frac{1}{3}V_{cc}$.
## HIGHs and LOWs, pt. 2
In your travels, you're likely to see both \SI{5}{\volt} and
\SI{3.3}{\volt} sensors and peripherals.
Since $\SI{3.3}{\volt}\geq\frac{2}{3}V_cc$ your Arduino will accept
input from a \SI{3.3}{\volt} peripheral without issue.
If you drive an output to \SI{5}{\volt} while it's connected to a
\SI{3.3}{\volt} peripheral with an Arduino **it will blow up your
peripheral**.^[In the datasheet for the sensor, it'll have a
section called *Absolute Maximums* . Generally \SI{3.3}{\volt} parts
won't accept more that $\approx\SI{3.6}{\volt}$, but some will.]
## HIGHs and LOWs, pt. 3
Solutions:
- Level Shifter: A dedicated chip that translates between
voltages. Available as uni or bidirectional.
- Buy a 3.3V Arduino Compatible. Arduinos are available that operate
at the lower voltage.