a (very) short course on arduino_handout
TRANSCRIPT
-
8/9/2019 A (Very) Short Course on Arduino_handout
1/62
Introduction to
Arduino WorkshopJAN RAY C. RULIDA
-
8/9/2019 A (Very) Short Course on Arduino_handout
2/62
Welcome to this
workshop!
-
8/9/2019 A (Very) Short Course on Arduino_handout
3/62
Before we beginquotes forInspiration
Learning is a treasure that will follow its ownereverywhere. ~Chinese Proverb
Mans mind, once stretched by a new idea, neverregains its original dimensions. ~Oliver Wendell Holmes
It gave a tremendous level of self-confidence, thatthrough exploration and learning one couldunderstand seemingly very complex things in onesenvironment. Steve Jobs
-
8/9/2019 A (Very) Short Course on Arduino_handout
4/62
What is electronics? Basic Electricity
An electric circuit is formed when a conductive pathto allow free electrons to continuously move. This co
movement of free electrons through the conductors
called a current, and it is often referred to in terms of
The force motivating electrons to "flow" in a circuit is
called voltage.
Free electrons tend to move through conductors wit
degree of friction, or opposition to motion. This oppo
motion is more properly calledresistance.
-
8/9/2019 A (Very) Short Course on Arduino_handout
5/62
What is electronics? Basic Electricity
-
8/9/2019 A (Very) Short Course on Arduino_handout
6/62
What is electronics? Basic Electricity
Current is usually measured in Amperes or ampVoltage is usually measured in Volts (V)
Resistance is usually measured in Ohms ()
-
8/9/2019 A (Very) Short Course on Arduino_handout
7/62
Computer Programming
A computer program, or just a program, is a seque
instructions, written to perform a specified task witha computer. (Wikipedia)
Computer programming, or just programming, is a
process of writing instructions for a computer for it t
certain task.
This task could be as simple as print a character or
complex as do the laundry/labada or command a
army!
-
8/9/2019 A (Very) Short Course on Arduino_handout
8/62
Computer Programming: Structure
A basic computer program can be form
by combining only seven controlstatements:
A sequence
3 types of selection (conditional), and3 types of repetition (iterative)
-
8/9/2019 A (Very) Short Course on Arduino_handout
9/62
Computer Programming
1. Sequencecombine the liquid ingredientnext add the dry ones.
2. Conditionalif the pineapples are fresh thpeel them, but if canned, skip this step.
3. Iterativetry and try until you succeed!
-
8/9/2019 A (Very) Short Course on Arduino_handout
10/62
Computer Programming: 1 and 0
A computer only understands 1s and 0s (BITS),HIGH or LOW, On or Off, True or False
Logic/BitwiseOperations
Bitwise Symbol Logic Sym
NOT ~ !
AND & &&
OR | ||
XOR (Exclusive OR) ^
-
8/9/2019 A (Very) Short Course on Arduino_handout
11/62
Computer Programming: LogicOperations (NOT)
The logic NOT of an input becomes TRUE if thaFALSE, and vice versa.
INPUT OUTPUT of !(INPUT)
False True
False True
True False
True False
-
8/9/2019 A (Very) Short Course on Arduino_handout
12/62
Computer Programming: LogicOperations (AND)
Logic AND operates according to this rule: if both intrue, the resulting output is true, otherwise the outpu
INPUT 1 INPUT 2 OUTPUT of&& INP
False False Fals
False True Fals
True False Fals
True True Tru
-
8/9/2019 A (Very) Short Course on Arduino_handout
13/62
Computer Programming: LogicOperations (OR)
The logic OR of two inputs is TRUE if either or both ofis TRUE, otherwise it is false. In other words:
INPUT 1 INPUT 2 OUTPUT of|| INP
False False Fals
False True Tru
True False Tru
True True Tru
-
8/9/2019 A (Very) Short Course on Arduino_handout
14/62
Computer Programming: BasicArithmetic
Arithmetic Operation Symbol
Addition +
Subtraction -
Multiplication *Division /
Modulo (Remainder) %
-
8/9/2019 A (Very) Short Course on Arduino_handout
15/62
What is Arduino?
-
8/9/2019 A (Very) Short Course on Arduino_handout
16/62
A Physical Piece of HardwareA Programming Enviro
What is Arduino?
-
8/9/2019 A (Very) Short Course on Arduino_handout
17/62
What is Arduino?: A physical pieceof hardware
Arduino senses the environment byreceiving inputs from many sensors, andaffects its surroundings by controlling lightsmotors, and other actuators. (From the Arduino website)
-
8/9/2019 A (Very) Short Course on Arduino_handout
18/62
Arduino is an open-source electronics platformbased on easy-to-use hardware and software.
It's intended for anyone making interactive
projects. (From the Arduino website).
It can actually mean three things:A physicalhardware, a software programming
environment, and a community or philosophy
What is Arduino?
-
8/9/2019 A (Very) Short Course on Arduino_handout
19/62
What is Arduino?: A softwareprogramming environment
You can tell your Arduino what to do bywriting code in the Arduino programminglanguage and using the Arduinodevelopment environment. (From the Arduino website)
A program written for Arduino is called asketch.
Digital Input/Output Pins
-
8/9/2019 A (Very) Short Course on Arduino_handout
20/62
USB
7-12 v
3 v GND
5 v Analog Input Pins
gPins with ~ are PWM
[Analog Output]GND
Transmitter/Receive
Serial Connection
Microco
Operati
Input Vo
Input Vo
Digital I
(of whic
Analog
DC Cur
DC Cur
-
8/9/2019 A (Very) Short Course on Arduino_handout
21/62
Lets Begin!
-
8/9/2019 A (Very) Short Course on Arduino_handout
22/62
Installation Drivers: Windows 8, 7,Vista, XP Download from http://www.arduino.cc the latest v
the Arduino software for your Arduino board. The laversion at the moment is Arduino 1.0.6. Choose theWindows Installer.
Run the installer and just follow the prompts and ch
defaults presented by the installer
After installation, connect your Arduino to the com
and then start the Arduino application
http://www.arduino.cc/http://www.arduino.cc/ -
8/9/2019 A (Very) Short Course on Arduino_handout
23/62
Getting Started: Blink an LED!
Connect your board via USB then Launch th
Arduino application.From the Tools->Board menu, select Arduino
From the Tools->Serial Port menu, select the serial port where your Arduino Uno is connec
Open the sketch (program)
File->Examples->01.Basics->Blink. Click the button to upload it to your board.
-
8/9/2019 A (Very) Short Course on Arduino_handout
24/62
Getting Started: Blink an LED!
Congratulations! Youveprogrammed your firstmicrocontroller!
-
8/9/2019 A (Very) Short Course on Arduino_handout
25/62
Arduino Terminology:
v
-
8/9/2019 A (Very) Short Course on Arduino_handout
26/62
v
Arduino Sketch!
comments
functions
-
8/9/2019 A (Very) Short Course on Arduino_handout
27/62
v
Arduino Sketch!
variable
-
8/9/2019 A (Very) Short Course on Arduino_handout
28/62
Arduino Analog I/O functions:
analogRead(pin)Reads an analog value from 0 to 1023 on pins A0 toA5. This means an input voltage between 0 to 5 volts onpins A0 to A5 will mapped to integer values between 0 to1023.
analogWrite(pin, value)
Writes an analog value (PWM wave) on PWM pin.
-
8/9/2019 A (Very) Short Course on Arduino_handout
29/62
Arduino Digital I/O functions:
pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
digitalRead(pin)
Reads HIGH or LOW from a pin
digitalWrite(pin, value)
Writes HIGH or LOW to a pin
Electronic stuff
Output pins can provide 40 mA of current
Writing HIGH to an input pin installs a 20K pullup
-
8/9/2019 A (Very) Short Course on Arduino_handout
30/62
Running without a computer: 9V batte
-
8/9/2019 A (Very) Short Course on Arduino_handout
31/62
Running without a computer
The Arduino converts the 9V from the battery down
using a regulator on the board. You can connect anything from 712 volts DC to the
plug socket (2.1 mm / 5.5 mm diameter, center posi
You can also stick cables directly into the Vin and G(Ground) pins to power the board from 712 volts
you dont have a barrel plug on your power source
Dont attach a 5V power source directly to the +5Vthough its a voltage output pin only, and you maonboard regulator. Use the USB connector instead.
-
8/9/2019 A (Very) Short Course on Arduino_handout
32/62
LED Adventures!
A light-emittingdiode (LED) is asemiconductor device
that emits visible light
when an electric current
passes through it.
-
8/9/2019 A (Very) Short Course on Arduino_handout
33/62
Safety Check!!!
Always disconnect or turn off yourpower source before you changecircuit to avoid shorts. They may sh
down your USB port, or worse.
-
8/9/2019 A (Very) Short Course on Arduino_handout
34/62
LED Adventures!
Connect an LED as son the left.
-
8/9/2019 A (Very) Short Course on Arduino_handout
35/62
LED Adventures
Connecting an LED directly to 5V and GND will
usually fry it because of too much currentflowing through it.
It survived only because the Arduino cant
provide more than 40 mA (milliamps) of current
on each pin So what do we do to prevent the LED from
frying??? o___0
-
8/9/2019 A (Very) Short Course on Arduino_handout
36/62
Add a RESISTOR!
A RESISTOR is a device having a designed resistance
passage of an electric current.
-
8/9/2019 A (Very) Short Course on Arduino_handout
37/62
Resistor Color Codes!
d l l h i d ?
-
8/9/2019 A (Very) Short Course on Arduino_handout
38/62
How do we calculate the required R?
Using Ohms Law
Voltage i
represent
Current in
represent Resistanc
is represe
Add RESISTOR!
-
8/9/2019 A (Very) Short Course on Arduino_handout
39/62
Add a RESISTOR!
B db d!!!
-
8/9/2019 A (Very) Short Course on Arduino_handout
40/62
Breadboard!!!
+
B db d!!!
-
8/9/2019 A (Very) Short Course on Arduino_handout
41/62
Breadboard!!!
B db d!!! LED + R i t
-
8/9/2019 A (Very) Short Course on Arduino_handout
42/62
Breadboard!!! LED + Resistor
Digital Input/Output:
-
8/9/2019 A (Very) Short Course on Arduino_handout
43/62
Digital Input/Output:
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
Digital Input/Output: Buttons
-
8/9/2019 A (Very) Short Course on Arduino_handout
44/62
Digital Input/Output: Buttons
Disconnect USB. Add a pushbutton, 10 k resistor (BrownOrangeGold) and wires as shown.
Digital Input/Output: Buttons
-
8/9/2019 A (Very) Short Course on Arduino_handout
45/62
Digital Input/Output: Buttons
Change the Blinkcode so it only blinks the Lpin 2 is LOW: Define a global integer (int) var
pushbutton. Set it to 2 in your setup(). In yourcode, use if (digitalRead(button)==LOW) {...}forget the curly braces and the double equa
Digital Input/Output: Buttons
-
8/9/2019 A (Very) Short Course on Arduino_handout
46/62
Digital Input/Output: Buttons
Change the Blinkcode so it only blinks the Lpin 2 is LOW: Define a global integer (int) var
pushbutton. Set it to 2 in your setup(). In yourcode, use if (digitalRead(button)==LOW) {...}forget the curly braces and the double equa
Reading Analog Values
-
8/9/2019 A (Very) Short Course on Arduino_handout
47/62
Reading Analog Values
Disconnect USB. Remove the pushbutton ana potentiometer and wires to analog input Ashown in the next slide
Reading Analog Values: Potentiometer
-
8/9/2019 A (Very) Short Course on Arduino_handout
48/62
Reading Analog Values: Potentiometer
Reading Analog Values: Light Dependen
-
8/9/2019 A (Very) Short Course on Arduino_handout
49/62
Resistor (LDR) or Photocell
Reading Analog Values
-
8/9/2019 A (Very) Short Course on Arduino_handout
50/62
Reading Analog Values
Load File->Examples->03. Analog->AnalogInuses analogRead(...) to read the voltage on turns the LED on and off with a delay determthat voltagethe further right you turn the slower the LED will blink.
analogRead() returns values from 0 (0V) to 1
Debugging with Serial
-
8/9/2019 A (Very) Short Course on Arduino_handout
51/62
Debugging with Serial
To see the actual numbers, openFile->Examples->01.Basics->AnalogReadSeri
Upload it, then click on the magnifier toolbathe top right to open the Serial Monitor wind
Debugging with Serial
-
8/9/2019 A (Very) Short Course on Arduino_handout
52/62
Debugging with Serial
The code uses Serial.begin(9600) to open a connection back to your computer in setupSerial.println(...) to output (print) numbers tserial connection, which end up in the Serialwindow on your screen. Its also possible to sback to the Arduino that way, using Serial.re
PWM: Making LEDs Faaaade
-
8/9/2019 A (Very) Short Course on Arduino_handout
53/62
PWM: Making LEDs Faaaade
Disconnect USB. Move the yellow wire f
13 to pin 11. Pin 11 has a tilde (~) on thewhich means it can output analog valushown in the figure on the next slide
PWM: Making LEDs Faaaade
-
8/9/2019 A (Very) Short Course on Arduino_handout
54/62
PWM: Making LEDs Faaaade
PWM: Making LEDs Faaaade
-
8/9/2019 A (Very) Short Course on Arduino_handout
55/62
PWM: Making LEDs Faaaade
Change your loop() to control the LED w
analogWrite(...). Analog values for outpfrom 0 to 255, not 1023, so divide the vaanalogRead(...) by 4 before writing it topin.
Controlling and Moving with Servos
-
8/9/2019 A (Very) Short Course on Arduino_handout
56/62
Controlling and Moving with Servos
Disconnect USB, and add a servo to yo
Connect its black or dark brown lead tored lead to 5V, and its orange, yellow olead (the signal lead) to pin 9, by stic
jumper wires into the servo connector li
figure in the next slide.
Controlling and Moving with Servos
-
8/9/2019 A (Very) Short Course on Arduino_handout
57/62
Controlling and Moving with Servos
Controlling and Moving with Servos
-
8/9/2019 A (Very) Short Course on Arduino_handout
58/62
g g
Load the sample sketch
File->Examples->Servo->Knob (its fdown in the list).
Run the code, and you can contro
angular turning position of the servoturning the potentiometer!!!
Arduino Shields!!!
-
8/9/2019 A (Very) Short Course on Arduino_handout
59/62
Shields are PCBs that stack on top o
Arduino and connect to all Arduinoadd all kinds of hardware features.
are shields to play MP3 files, for WiFi
Bluetooth, Ethernet, Zigbee, MIDI, Glog data, drive big motors, etc.
Character LCD
-
8/9/2019 A (Very) Short Course on Arduino_handout
60/62
Character LCD
-
8/9/2019 A (Very) Short Course on Arduino_handout
61/62
Disconnect USB. Open up
the FileExamplesLiquidCrystalHelloexample sketch
Upload the sketch to your Arduino Board
Thank You!
-
8/9/2019 A (Very) Short Course on Arduino_handout
62/62
Make your own proje