Introduction to
Arduino Workshop
JAN RAY C. RULIDA
Welcome to this
workshop!
Before we beginquotes for
Inspiration
Learning is a treasure that will follow its owner
everywhere. ~Chinese Proverb
Mans mind, once stretched by a new idea, never
regains its original dimensions. ~Oliver Wendell Holmes
It gave a tremendous level of self-confidence, that
through exploration and learning one could
understand seemingly very complex things in ones
environment. Steve Jobs
What is electronics? Basic Electricity
An electric circuit is formed when a conductive path is created
to allow free electrons to continuously move. This continuous
movement of free electrons through the conductors of a circuit is
called a current, and it is often referred to in terms of "flow
The force motivating electrons to "flow" in a circuit is
called voltage.
Free electrons tend to move through conductors with some
degree of friction, or opposition to motion. This opposition to
motion is more properly called resistance.
What is electronics? Basic Electricity
What is electronics? Basic Electricity
Current
is usually measured in Amperes or amps (A)
Voltage
is usually measured in Volts (V)
Resistance
is usually measured in Ohms ()
Computer Programming
A computer program, or just a program, is a sequence of
instructions, written to perform a specified task with
a computer. (Wikipedia)
Computer programming, or just programming, is a
process of writing instructions for a computer for it to do a
certain task.
This task could be as simple as print a character or as
complex as do the laundry/labada or command a robot
army!
Computer Programming: Structure
A
basic computer program can be formed
by combining only seven control
statements:
A
sequence
types of selection (conditional), and
types of repetition (iterative)
Computer Programming
1.
Sequencecombine the liquid ingredients, and
next add the dry ones.
2.
Conditionalif the pineapples are fresh then
peel them, but if canned, skip this step.
3.
Iterativetry and try until you succeed!
Computer Programming: 1 and 0
A
computer only understands 1s and 0s (BITS),
HIGH or LOW, On or Off, True or False
Logic/Bitwise
Operations
NOT
AND
OR
XOR (Exclusive OR)
Bitwise Symbol
Logic Symbol
~
&
|
^
!
&&
||
Computer Programming: Logic
Operations (NOT)
The
logic NOT of an input becomes TRUE if that input is
FALSE, and vice versa.
INPUT
OUTPUT of !(INPUT)
False
True
False
True
True
False
True
False
Computer Programming: Logic
Operations (AND)
Logic AND operates according to this rule: if both inputs are
true, the resulting output is true, otherwise the output is false.
INPUT 1
INPUT 2
OUTPUT of (INPUT1
&& INPUT2)
False
False
False
False
True
False
True
False
False
True
True
True
Computer Programming: Logic
Operations (OR)
The logic OR of two inputs is TRUE if either or both of the inputs
is TRUE, otherwise it is false. In other words:
INPUT 1
INPUT 2
OUTPUT of (INPUT1
|| INPUT2)
False
False
False
False
True
True
True
False
True
True
True
True
Computer Programming: Basic
Arithmetic
Arithmetic Operation
Addition
Subtraction
Multiplication
Division
Modulo (Remainder)
Symbol
+
*
/
%
What is Arduino?
What is Arduino?
A Physical Piece of Hardware
A Programming Environment
What is Arduino?: A physical piece
of hardware
Arduino
senses the environment by
receiving inputs from many sensors, and
affects its surroundings by controlling lights,
motors, and other actuators. (From the Arduino website)
What is Arduino?
Arduino is an open-source electronics platform
based 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 physical
hardware, a software programming
environment, and a community or philosophy
What is Arduino?: A software
programming environment
You
can tell your Arduino what to do by
writing code in the Arduino programming
language and using the Arduino
development environment. (From the Arduino website)
program written for Arduino is called a
sketch.
Digital Input/Output Pins
Pins with ~ are PWM
Transmitter/Receiver
[Analog Output]
GND
Serial Connection
USB
Microcontroller ATmega328
Operating Voltage 5V
Input Voltage (recommended)7-12V
Input Voltage (limits)6-20V
Digital I/O Pins 14
(of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
7-12 v
3 v GND
5v
Analog Input Pins
Lets Begin!
Installation Drivers: Windows 8, 7,
Vista, XP
Download from http://www.arduino.cc the latest version of
the Arduino software for your Arduino board. The latest
version at the moment is Arduino 1.0.6. Choose the
Windows Installer.
Run the installer and just follow the prompts and choose the
defaults presented by the installer
After installation, connect your Arduino to the computer
and then start the Arduino application
Getting Started: Blink an LED!
Connect
your board via USB then Launch the
Arduino application.
From
the Tools->Board menu, select Arduino Uno
From
the Tools->Serial Port menu, select the new
serial port where your Arduino Uno is connected
Open
the sketch (program)
File->Examples->01.Basics->Blink. Click the toolbar
button to upload it to your board.
Getting Started: Blink an LED!
Congratulations! Youve
programmed your first
microcontroller!
Arduino Terminology:
Arduino Sketch!
comments
v
functions
Arduino Sketch!
variable
Arduino Analog I/O functions:
analogRead(pin)
Reads an analog value from 0
to 1023 on pins A0 to
A5. This means an input voltage between 0 to 5 volts on
pins A0 to A5 will mapped to integer values between 0 to
1023.
analogWrite(pin,
value)
Writes an analog value (PWM wave) on PWM pin.
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
Running without a computer: 9V battery
Running without a computer
The Arduino converts the 9V from the battery down to 5V
using a regulator on the board.
You can connect anything from 712 volts DC to the barrel
plug socket (2.1 mm / 5.5 mm diameter, center positive)
You can also stick cables directly into the Vin and GND
(Ground) pins to power the board from 712 volts great if
you dont have a barrel plug on your power source.
Dont attach a 5V power source directly to the +5V pin
though its a voltage output pin only, and you may fry your
onboard regulator. Use the USB connector instead.
LED Adventures!
A light-emitting
diode (LED) is a
semiconductor device
that emits visible light
when an electric current
passes through it.
Safety Check!!!
Always
disconnect or turn off your
power source before you change your
circuit to avoid shorts. They may shut
down your USB port, or worse.
LED Adventures!
Connect an LED as shown
on the left.
LED Adventures
Connecting an LED directly to 5V and GND will
usually fry it because of too much current
flowing 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
Add a RESISTOR!
A RESISTOR is a device having a designed resistance to the
passage of an electric current.
Resistor Color Codes!
How do we calculate the required R?
Using Ohms Law
Voltage in volts is
represented as V
Current in amps is
represented as I
Resistance in ohms
is represented as R
Add a RESISTOR!
Breadboard!!!
Breadboard!!!
Breadboard!!! LED + Resistor
Digital Input/Output:
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
Digital Input/Output: Buttons
Disconnect USB. Add a pushbutton, 10 k resistor (BrownBlack
OrangeGold) and wires as shown.
Digital Input/Output: Buttons
Change
the Blink code so it only blinks the LED while
pin 2 is LOW: Define a global integer (int) variable
pushbutton. Set it to 2 in your setup(). In your loop()
code, use if (digitalRead(button)==LOW) {...}. Dont
forget the curly braces and the double equal sign.
Digital Input/Output: Buttons
Change
the Blink code so it only blinks the LED while
pin 2 is LOW: Define a global integer (int) variable
pushbutton. Set it to 2 in your setup(). In your loop()
code, use if (digitalRead(button)==LOW) {...}. Dont
forget the curly braces and the double equal sign.
Reading Analog Values
Disconnect
USB. Remove the pushbutton and connect
a potentiometer and wires to analog input A0 as
shown in the next slide
Reading Analog Values: Potentiometer
Reading Analog Values: Light Dependent
Resistor (LDR) or Photocell
Reading Analog Values
Load
File->Examples->03. Analog->AnalogInput. It
uses analogRead(...) to read the voltage on A0, and
turns the LED on and off with a delay determined by
that voltage the further right you turn the knob, the
slower the LED will blink.
analogRead()
returns values from 0 (0V) to 1023 (5V).
Debugging with Serial
To see the actual numbers, open
File->Examples->01.Basics->AnalogReadSerial.
Upload
it, then click on the magnifier toolbar button in
the top right to open the Serial Monitor window
Debugging with Serial
The
code uses Serial.begin(9600) to open a serial
connection back to your computer in setup(), and
Serial.println(...) to output (print) numbers to that
serial connection, which end up in the Serial Monitor
window on your screen. Its also possible to send data
back to the Arduino that way, using Serial.read(...).
PWM: Making LEDs Faaaade
Disconnect
USB. Move the yellow wire from pin
13 to pin 11. Pin 11 has a tilde (~) on the board,
which means it can output analog values as
shown in the figure on the next slide
PWM: Making LEDs Faaaade
PWM: Making LEDs Faaaade
Change
your loop() to control the LED with
analogWrite(...). Analog values for output go
from 0 to 255, not 1023, so divide the value from
analogRead(...) by 4 before writing it to the LED
pin.
Controlling and Moving with Servos!
Disconnect
USB, and add a servo to your setup:
Connect its black or dark brown lead to GND, its
red lead to 5V, and its orange, yellow or white
lead (the signal lead) to pin 9, by sticking
jumper wires into the servo connector like the
figure in the next slide.
Controlling and Moving with Servos!
Controlling and Moving with Servos!
Load
the sample sketch
File->Examples->Servo->Knob (its further
down in the list).
Run the code, and you can control the
angular turning position of the servo by
turning the potentiometer!!!
Arduino Shields!!!
Shields
are PCBs that stack on top of the
Arduino and connect to all Arduino pins to
add all kinds of hardware features. There
are shields to play MP3 files, for WiFi,
Bluetooth, Ethernet, Zigbee, MIDI, GPS, to
log data, drive big motors, etc.
Character LCD
Character LCD
Disconnect
USB. Open up
the FileExamplesLiquidCrystalHelloWorld
example sketch
Upload the sketch to your Arduino Board.
Thank You!
Make your own projects!