SIK GUIDE · 6 Pins (ARef, Ground, Digital, Rx, Tx) - These various pins can be used for inputs,...
Transcript of SIK GUIDE · 6 Pins (ARef, Ground, Digital, Rx, Tx) - These various pins can be used for inputs,...
-
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
SIK GUIDEYour guide to the SparkFun Inventor’s Kit for the SparkFun RedBoard
IORE
FRE
SET
RESET
7-15
V
SCL
SCA
AREF
GND
1312
~11
~10
~9 8
7~6
~5 4~3 2
10
TXRX
13
3.3V
5VGN
DGN
DVI
N
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)
ON
ISP
TXRX
ARDUINO LANGUAGE DEVELOPMENT PLATFORM
Version 3.3
SIK 3.3 Pages 1-8.pdf 8/5/14 11:48 PM
-
�e SparkFun Inventor's Guide is your map for navigating the waters of beginning embedded electronics. �is booklet contains all the information you will need to explore the 16 circuits of the SparkFun Inventor's Kit for SparkFun RedBoard. At the center of this manual is one core philosophy - that anyone can (and should) play around with electronics. When you're done with this guide, you'll have the know-how to start creating your own projects and experiments. Now enough talking - let's get inventing!
www.sparkfun.com/SIK
Welcome to the SparkFun Inventor’s Guide
Table of Contents
C
M
Y
CM
MY
CY
CMY
K
Inside-cover-and-inside-back-page fixed.pdf 1 12/15/16 3:42 PM
-
What is the RedBoard platform? 2
Download Arduino Software (IDE) 4
Install Drivers 5
Select your board: Arduino Uno 8
Download “SIK Guide Code” 9
The World Runs on Circuits 10
Inventory of Parts 12
14
16
18
25
29
33
37
41
45
49
53
Section 2: Getting Started with Circuits
Section 1: Getting Started
RedBoard
Breadboard
Circuit #1 - Your First Circuit: Blinking a LED
Circuit #3 - RGB LED
Circuit #4 - Multiple LEDs
Circuit #5 - Push Buttons
Circuit #6 - Photo Resistor
Circuit #7 - Temperature Sensor
Circuit #8 - A Single Servo
Circuit #9 - Flex Sensor
57Circuit #10 - Soft Potentiometer
61Circuit #11 - Piezo Buzzer
65Circuit #12 - Spinning a Motor
69Circuit #13 - Relay
73Circuit #14 - Shift Register
77Circuit #15 - LCD
81Circuit #16 - Simon Says
Circuit #2 - Potentiometer
Page 1
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 3 12/15/16 11:18 AM
-
We live in a unique time where we have access to resources that allow us to create our own solutions and inventions. �e DIY revolution is composed of hobbyists, tinkerers and inventors who would rather craft their own projects than let someone do it for them.
www.sparkfun.com
The DIY Revolution
What is the RedBoard platform?
FPOFPO
�e RedBoard in your hand (or on your desk) is your development platform. At its roots, the RedBoard is essentially a small portable computer. It is capable of taking inputs (such as the push of a button or a reading from a light sensor) and interpreting that information to control various outputs (like a blinking LED light or an electric motor).
�at's where the term "physical computing" is born - this board is capable of taking the world of electronics and relating it to the physical world in a real and tangible way. Trust us - this will all make more sense soon.
A Computer for the Physical World
RedBoard
// SparkFun RedBoard
�e SparkFun RedBoard is one of a multitude of development boards based on the ATmega328. It has 14 digital input/output pins (6 of which can be PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ISP header, and a reset button. Don’t worry, you’ll learn about all these later.
RedBoard
Page 2
IOREF
RESET
RESET
7-15V
SCLSDA
AREFGND
1312
~11~10
~98
7~6~5
4~3
210
TXRX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POW
ERAN
ALOG IN
DIGITAL (PW
M~
)
ON
ISP
TX
RX
LE
AR
N. S
HA
RE
. HA
CK
.
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 4 12/15/16 11:18 AM
-
cb
a
d
e
f
g
h
c
b
a
f
e
d
h
g
Power-Lacing High Tops
Old Toy Email Notifer
Bug Zapper Counter
Re-Programmed Traffic Light
Auto-Plant Watering
Camera Time-lapse operation
Quadcopter
Auto-Coffee Maker
RedBoard
Page 3
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 5 12/15/16 11:18 AM
-
In order to get your RedBoard up and running, you'll need to download the newest version of the Arduino software �rst from www.arduino.cc (it's free!). �is software, known as the Arduino IDE, will allow you to program the board to do exactly what you want. It’s like a word processor for writing programs. With an internet-capable computer, open up your favorite browser and type in the following URL into the address bar:
Access the Internet
Download the Arduino IDE (Integrated Development Environment)
Windows
Mac OS X
Linux: 32 bit, 64 bit
arduino.cc/en/main/software < case sensitive >
Choose the appropriate Operating System installation package for your computer.
Download Select the installer option appropriate for the operating system you are using.
Windows
Mac OS X
source
Linux: 32 bit, 64 bit
1
Page 4
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 6 12/15/16 11:18 AM
-
// Connect your RedBoard to your Computer
Use the USB cable provided in the SIK kit to connect the RedBoard to one of your computer’s USB inputs.
// Install Arduino DriversDepending on your computer’s operating system, you will need to follow speci�c instructions. Please go to www.sparkfun.com/FTDI for speci�c instructions on how to install the FTDI drivers onto your RedBoard.
2
3
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Page 5
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 7 12/15/16 11:18 AM
-
1 2 3 5 6
7
8
9
9
10
4
Open the Arduino IDE software on your computer. Poke around and get to know the interface. We aren’t going to code right away, this is just an introduction. �is step is to set your IDE to identify your RedBoard.
// Open the Arduino IDE:
Page 6
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 8 12/15/16 11:18 AM
-
// The three most important commands for this guide are these:
GUI (Graphical User Interface)
Verify: Compiles and approves your code. It will catch errors in syntax (like missing semi-colons or parenthesis). // See Diagram Below1
Upload: Sends your code to the RedBoard. When you click it, you should see the lights on your board blink rapidly. // See Diagram Below2
New: This buttons opens up a new code window tab.3
Open: This button will let you open up an existing sketch. // See Diagram Below4
Save: This saves the currently active sketch.5
Serial Monitor: This will open a window that displays any serial information your RedBoard is transmitting. It is very useful for debugging.6
Code Area: This is the area where you compose the code for your sketch. 8
Connection Area: This shows the board and serial port currently selected.10
Message Area: This is where the IDE tells you if there were any errors in your code.9
Sketch Name: This shows the name of the sketch you are currently working on.7
Verify
Upload
Open
Page 7
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 1-8.pdf 9 12/15/16 11:18 AM
-
// Select your board: Arduino/Genuino Uno
Select the serial device of the RedBoard from the Tools | Serial Port menu. �is is likely to be com3 or higher (COM1 and COM2 are usually reserved for hardware
serial ports). To �nd out, you can disconnect your RedBoard and re-open the menu; the entry that disappears should be the RedBoard. Reconnect the board and select that serial port.
Select the serial device of the RedBoard from the Tools > Serial Port menu. On the
Mac, this should be something with /dev/tty.usbmodem or /dev/tty.usbserial in it.
http://www.arduino.cc/playground/Learning/Linux
// S
elec
t you
r Ser
ial D
evic
e
4
Note:Your SparkFun RedBoard and the Arduino/Genuino UNO are interchangeable but you won’t find the RedBoard listed in the Arduino Software. Select “Arduino UNO” instead.
Page 8
Serial ports/dev/cu/Bluetooth-Incoming-Port/dev/cu.usbserialDNO18JWS
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Page 8 fix.pdf 1 12/15/16 12:36 PM
-
Type in the following URL to download the code:
Download Arduino Code (For use with the circuits in this guide)
sparkfun.com/sikcode
5
Unzip the �le “SIK Guide Code”. It should be located in your browser’s “Downloads” folder. Right click the zipped folder and choose “unzip”.
Copy the “SIK Guide Code” folder into Arduino’s folder named “examples”.
Copy the “SIK Guide Code” folder into Arduino’s folder named “examples”.
WHAT’S NEXT? Read on to learn more about getting started with circuits. �en you can start on your �rst circuit on page 17!
Unzip the �le “SIK Guide Code”. It should be loacted in your browser’s “Downloads” folder. Right click the zipped folder and choose “unzip”.
Find “Arduino” in your applications folder. Right click(ctrl + click) on “Arduino”. Select “Show Package Contents”.
http://www.arduino.cc/playground/Learning/Linux
// C
opy
“SIK
Gui
de C
ode”
into
“Ex
ampl
es”
libra
ry in
Ard
uino
fold
er
ProgramsStart arduino examples
Contents
Resources
Java
examples
Page 9
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 2 12/15/16 11:18 AM
-
Everywhere you look, you'll �nd circuits. �e cell phone in your pocket, the computer that controls your car's emissions system, your video game console - all these things are chock full of circuits. In this guide, you'll experiment with some simple circuits and learn the gist of the world of embedded electronics.
The World Runs on Circuits:
Getting Started with Circuits
A circuit is basically an electrical loop with a starting point and an ending point - with any number of components in between. Circuits can include resistors, diodes, inductors, sensors of all sizes and shapes, motors, and any other handful of hundreds of thousands of components.
Circuits are usually divided into three categories - analog circuits, digital circuits, or mixed-signal circuits. In this guide, you will explore all three sets of circuits.
What is an Electrical Circuit?
// Simple and Complex Circuits
In this guide, you will be primarily exploring simple circuits - but that doesn't mean you can't do amazing things with simple tools! When you've �nished the SIK, your knowledge of circuits will enable you to explore amazing projects and unleash the power of your imagination.
a b c d e f g h i123456789101112131415161718192021222324252627282930
a b c d e f g h i
123456789101112131415161718192021222324252627282930
Page 10
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 3 12/15/16 11:18 AM
-
Page 11
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 4 12/15/16 11:18 AM
-
Inventory of Parts
* ACTUAL SIZE
(1N4148)Diode
x2
x1
Piezo Buzzer
Various ColorsJumper Wire
x30
Push Button
x4x1
DC Motor
x1
DC Motor
x1
Potentiometer
(Light Emitting Diode)
x1x5x5x5x5
LED (5mm) +-
330Ω Resistor
x25 * ACTUAL SIZE
10KΩ Resistor
x25 * ACTUAL SIZE
(TMP36)
x1
Temp. Sensor
FRONT
BACK
(BC337)
x2
Transistor
BC33
7 40-E
35
FRONT
BACK
BC33740-E35
x1
Photo Resistor
Page 12
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 5 12/15/16 11:18 AM
-
Standard Solderless Breadboard
a b c d e f g h i123456789101112131415161718192021222324252627282930
a b c d e f g h i
123456789101112131415161718192021222324252627282930
Standard Solderless (Color may vary) Breadboard
a b c d e f g h i123456789101112131415161718192021222324252627282930
a b c d e f g h i
123456789101112131415161718192021222324252627282930
SparkFun RedBoardFlex Sensor
x1
Soft Potentiometer
x1
Servo
x1
Relay
x1
x1
x1
LCD
x1
(IC)Integrated Circuit
x1
IOREF
RESET
RESET
7-15V
SCLSDA
AREFGND
1312
~11~10
~98
7~6~5
4~3
210
TXRX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POW
ERAN
ALOG IN
DIGITAL (PW
M~
)
ON
ISP
TX
RX
LE
AR
N. S
HA
RE
. HA
CK
.
Page 13
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 6 12/15/16 11:18 AM
-
IOREF
RESET
RESET
7-15V
SCLSDA
AREFGND
1312
~11~10
~98
7~6~5
4~3
210
TXRX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POW
ERAN
ALOG IN
DIGITAL (PW
M~
)
ON
ISP
TX
RX
LE
AR
N. S
HA
RE
. HA
CK
.
12
8
6
9
7
3 4 5
10
Page 14
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 7 12/15/16 11:18 AM
-
// Pins Diagram
SparkFun RedBoard
RFU - This pin is reserved for future use.11
Power In (Barrel Jack) - Can be used with either a 9V or 12V wall-wart or battery.1
Power In (USB Port) - Provides power and communicates with your board when plugged into your computer via USB.2
LED (RX: Receiving) - This shows when the FTDI chip is receiving data bits from the microcontroller. This happens when the microcontroller is sending data bits back to the computer.3
LED (TX: Transmitting) - This shows when the FTDI chip is transmitting data bits to the microcontroller. This happens when the microcontroller is receiving this data from the computer.4
LED (Pin 13: Troubleshooting) - This LED is incorporated into your sketch to show if your program is running properly.5
Pins (ARef, Ground, Digital, Rx, Tx) - These various pins can be used for inputs, outputs, power, and ground. // See Diagram Below 6
LED (Indicates RedBoard is ON) - This is a simple power indicator LED.7
Reset Button - This is a way to manually reset your RedBoard, which makes your code restart.8
Pins (Analog In, Power In, Ground, Power Out, Reset) - These various pins can be used for inputs, outputs, power, and ground. // See Diagram 10
ICSP Pins (Uploading Code without Bootloader) - This is for "In-Circuit Serial Programming," used if you want to bypass the bootloader.9
Power Out
Reset
IOREF
RFU
Power Out
Ground
Ground
Power In
Analog
Analog
Analog
Analog
Analog
Analog
Ground
ARef
SDA
SCL
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
TX - Out
RX - In
10
11
6
= PWM/Analog out compatible (i.e. )
The header pins are one of the most important parts for putting our example circuits together. Take a moment and locate the input/output ports of your RedBoard.
RFU
Page 15
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 8 12/15/16 11:18 AM
-
a b c d e f g h i123456789101112131415161718192021222324252627282930
a b c d e f g h i
123456789101112131415161718192021222324252627282930
This line divides the board in half, restricting electricity to one half or the other.
1
2
Page 16
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 10-18.pdf 9 12/15/16 11:18 AM
-
Power:
Each + sign runs power anywhere in the vertical column.
Ground:
Each - sign runs to ground anywhere in the vertical column.
Horizontal Rows:
Each of these rows numbered 1-30 are comprised of five horizontal sockets. Components placed in the same row will be connected in a circuit when power is running.
Vertical Connection (+ Power and - Ground) - Power bus // See Diagram Below1
Horizontal Connection (a-e & f-j) // See Diagram Below)2
How’s it all connected?
View of the inside
f g h ia b c d e123456789101112131415161718192021222324252627282930
a b c d e f g h i
123456789101112131415161718192021222324252627282930
Breadboard
Above the breadboard
CONNECTED!
LED
Making a Connection:
Inside the breadboard
Page 17
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 1 12/15/16 11:16 AM
-
How It Works:
ASSEMBLE WRITE UPLOAD
Peel sticker off back of breadboard and stick into place.
Make sure the text on the RedBoard and breadboard are facing up so you can read them.
a b c d e f g h i123456789101112131415161718192021222324252627282930
a b c d e f g h i
123456789101112131415161718192021222324252627282930
Screw the RedBoard down and into place.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Connect the USB cable.
CIRCUIT #1 - Your First Circuit
Your RedBoard runs on 5V. �is is the power that will be supplied from your computer via USB and will be the driving force behind any components you use in your circuits. By plugging your RedBoard into your computer, you are supplying it with just the right voltage it needs to thrive! 5V can’t hurt you, so don’t be afraid to touch anything in your circuit. You can also power the RedBoard through the barrel jack. �e on-board voltage regulator can handle anything from 7 to 15VDC.
Page 18
IOREF
RESET
RESET
7-15V
SCLSDA
AREFGND
1312
~11~10
~98
7~6~5
4~3
210
TXRX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POW
ERAN
ALOG IN
DIGITAL (PW
M~
)
ON
ISP
TX
RX
LE
AR
N. S
HA
RE
. HA
CK
.
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 2 12/15/16 11:16 AM
-
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
PART
S: LED
1X
Wire
3X
330ΩResistor
1X This section lists the parts you will need to complete the circuit.
Circuit 2
LEDs (light-emitting diodes) are small, powerful lights that are used in many di�erent applications. To start o� the SIK, we will work on blinking an LED. �at's right - it's as simple as turning a light on and o�. It might not seem like much, but establishing this important baseline will give you a solid foundation as we work toward more complex experiments.
Blinking an LED 1
Each circuit begins with a brief description of the what you are putting together and the expected result.
This is a schematic of your circuit.
This is an illustration of how the completed circuit should look. It is not necessary to use the black holder for the RedBoard and breadboard, but we recommend it for the first time inventor!
Components like resistors need to have their legs bent into 90° angles in order to correctly fit the breadboard sockets. You can also cut the legs shorter to make them easier to work with on the breadboard.
LED(Light-Emitting Diode)
Resistor (330 ohm)(Orange-Orange-Brown)
RedBoard
GND(Ground)
PIN 13
Page 19
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 3 12/15/16 11:16 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Circ
uit 1
: Blin
king
an
LED
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
LED:
Mak
e su
re th
e sh
ort l
eg,
mar
ked
with
flat
side
, goe
s int
o th
e ne
gativ
e po
sitio
n (-)
. 33
0Ω R
esis
tor:
The
colo
r ban
ding
sh
ould
read
ora
nge-
or-
ange
-bro
wn-
gold
. The
com
po-
nent
legs
can
go in
eith
er h
ole.
Jum
per W
ire: A
ll ju
mpe
r wire
s w
ork
the
sam
e. T
hey
are
used
to
conn
ect t
wo
poin
ts to
geth
er. T
his
guid
e w
ill sh
ow th
e w
ires w
ith d
iffer
ent
colo
red
insu
latio
ns fo
r cla
rity,
but
usi
ng
diffe
rent
com
bina
tions
of c
olor
s is
com
plet
ely
acce
ptab
le.
Fla
t E
dg
e
Sho
rt L
eg
Page 20
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 4 12/15/16 11:17 AM
-
Com
pone
nt:
Imag
e Re
fere
nce:
LED
(5m
m)
+-
+-
c2c3
Jum
per W
irePi
n 13
e2
330Ω
Res
isto
ra3
GN
Da3
Jum
per W
ireG
ND
Jum
per W
ire5V5V
+“5
V” o
n th
e Re
dBoa
rd c
onne
cts t
o th
e ro
w m
arke
d “+
” on
the
brea
dboa
rd.
“Pin
13”
on
the
RedB
oard
con
nect
s to
sock
et “e
2” o
n th
e br
eadb
oard
.
“GN
D”
on th
e Re
dBoa
rd sh
ould
be
conn
ecte
d to
the
row
mar
ked
“-”
on th
e br
eadb
oard
.
Resi
stor
s are
pla
ced
in b
read
boar
d so
cket
s onl
y. T
he “
-” sy
mbo
l rep
rese
nts a
ny so
cket
in it
s ve
rtic
al c
olum
n on
the
brea
dboa
rd's
pow
er b
us.
Brea
dboa
rd: T
he w
hite
bac
kgro
und
repr
esen
ts a
conn
ectio
n to
a
brea
dboa
rd so
cket
spec
ified
by
a le
tter-n
umbe
r coo
rdin
ate
such
as
e2. T
hese
coor
dina
tes a
re m
erel
y su
gges
tions
that
alig
n w
ith th
e gr
aphi
c im
age.
RedB
oard
: The
red
back
grou
nd
repr
esen
ts a
conn
ectio
n to
one
of
the
RedB
oard
hea
der p
ins.
Com
pone
nts l
ike
LEDs
are
inse
rted
into
the
brea
dboa
rd so
cket
s c2(
long
leg)
c3(
shor
t leg
). St
eps
high
light
ed w
ith a
yel
low
war
ning
tria
ngle
repr
esen
t a p
olar
ized
com
pone
nt. P
ay sp
ecia
l att
entio
n to
th
e co
mpo
nent
’s m
arki
ngs i
ndic
ating
how
to p
lace
it o
n th
e br
eadb
oard
.
Page 21
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 5 12/15/16 11:17 AM
-
Open Up the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open the code for Circuit 1 by accessing the “SIK Guide Code” you downloaded and placed into your “Examples” folder earlier.
Open Your First Sketch:
File Edit Sketch Tools Help
1.Basics2.Digital3.Analog4.Communication5.Control6.Sensors7.Displays8.StringsArduinoISPSIK Guide Code
EEPROMEthernetFirmataLiquid CrystalSDServoSoftwareSerialSPIStepperWire
Page SetupPrint
NewOpen...SketchbookExamplesCloseSaveSave As...UploadUpload Using Progammer
Circuit #1Circuit #2Circuit #3Circuit #4Circuit #5Circuit #6Circuit #7Circuit #8Circuit #9Circuit #10Circuit #11Circuit #12Circuit #13Circuit #14Circuit #15
Circuit #1
/* Blink
Turns on an LED on for one second, then o� for one second, repeatedly. This example code is in the public domain.
*/
void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); }
void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED o� delay(1000); // wait for a second}
// Circuit #1
Page 22
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 6 12/15/16 11:17 AM
-
Verify
Upload
// The result of a completed circuit with correct code after verified and uploaded.
�is compiles your code. �e IDE changes it from text into instructions the computer can understand.
�is sends the instructions via the USB cable to the computer chip on the RedBoard. �e RedBoard will then begin running your code automatically.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Page 23
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 7 12/15/16 11:17 AM
-
Circuit 2 Arduino Code:1
Troubleshooting:
LED Not Lighting Up?LEDs will only work in one direction. Try taking it out, turning it 180 degrees and reinserting it (no need to worry, installing it backward does no permanent harm).
Program Not Uploading �is happens sometimes, the most likely cause is a confused serial port, you can change this in tools>serial port>
Still No Success?A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can: [email protected]
You should see your LED blink on and o�. If it isn't, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshooting tips below.
Before you can use one of the RedBoard's pins, you need to tell the RedBoard whether it is an INPUT or OUTPUT. We use a built-in "function" called pinMode() to do this.
When you're using a pin as an OUTPUT, you can command it to be HIGH (output 5 volts), or LOW (output 0 volts).
digitalWrite(13, HIGH);
pinMode(13, OUTPUT);
Code to Note:
Real World Application:
Almost all modern �at screen televisions and monitors have LED indicator lights to show they are on or o�.
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 1
What you Should See:
This is where you will find the Arduino code for each circuit.
Remember to Verify and Upload your code.
See if your circuit is complete and working in this section.
Begin to understand how the Arduino code works. See below.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
This is a section dedicated to the most common mistakes made while assembling the circuit.
Here you will find examples of the circuit you just completed in the real world. Many of the theories in these circuits are used in things you use everyday!
Page 24
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 8 12/15/16 11:17 AM
-
Circuit 2PA
RTS: Wire
19X
CIRCUIT #5
IC
1X
330ΩResistor
8X
LED
8X
Circuit 2
In this circuit you’ll work with a potentiometer. A potentiometer is also known as a variable resistor. When it’s connected with 5 volts across its two outer pins, the middle pin outputs a voltage between 0 and 5, depending on the position of the knob on the potentiometer. A potentiometer is a perfect demonstration of a variable voltage divider circuit. �e voltage is divided proportionate to the resistance between the middle pin and the ground pin. In this circuit, you’ll learn how to use a potentiometer to control the brightness of an LED.
Potentiometer
PART
S: Wire
6X
CIRCUIT #2 2
LED
1X
330ΩResistor
1X
Potentiometer
1X
p.10
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
LED(Light-Emitting Diode)
Resistor (330 ohm)(Orange-Orange-Brown)
RedBoard
GND(Ground)
RedBoard
Potentiometer
PIN 13
5 volt
PIN A0
Page 25
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 17-25.pdf 9 12/15/16 11:17 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Circ
uit 2
: Pot
entio
met
er
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Page 26
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 1 12/15/16 11:14 AM
-
Com
pone
nt:
Imag
e Re
fere
nce:
Pote
ntio
met
er
e6Ju
mpe
r Wire
e8Ju
mpe
r Wire
Jum
per W
ireG
ND
Jum
per W
ire5V
Pin
13j2
0
Jum
per W
ireG
ND
Jum
per W
ire5V5V
+
+-
+-
h20
h21
LED
(5m
m)
330Ω
Res
isto
rj2
1+
Jum
per W
ireA0
e7
+
a6 a7 a8If
you
look
clos
ely at
you
r Red
Boar
d, y
ou'll
see s
ome p
ins l
abele
d "D
IGIT
AL",
and
som
e lab
eled
"AN
ALO
G".
Wha
t's th
e di�
eren
ce?
Man
y of
the d
evice
s you
'll in
terfa
ce to
, suc
h as
LED
s and
pus
hbut
tons
, hav
e on
ly tw
o po
ssibl
e sta
tes:
on an
d of
f, or
as th
ey're
kno
wn
to th
e Red
Boar
d,
"HIG
H" (
5 vo
lts) a
nd "L
OW
" (0
volts
). T
he d
igita
l pin
s on
a Red
Boar
d ar
e gr
eat a
t get
ting
thes
e sig
nals
to an
d fro
m th
e out
side w
orld
, and
can
even
do
trick
s lik
e sim
ulat
ed d
imm
ing
(by
blin
king
on
and
o� re
ally
fast)
, and
seria
l co
mm
unica
tions
(tra
nsfe
rrin
g da
ta to
anot
her d
evice
by
enco
ding
it as
pat
tern
s of
HIG
H an
d LO
W).
But t
here
are a
lso a
lot o
f thi
ngs o
ut th
ere t
hat a
ren'
t jus
t "on
" or "
o�".
Tem
pera
ture
leve
ls, co
ntro
l kno
bs, e
tc. a
ll ha
ve a
cont
inuo
us ra
nge o
f valu
es
betw
een
HIG
H an
d LO
W. F
or th
ese s
ituat
ions
, the
Red
Boar
d o�
ers s
ix an
alog
inpu
ts th
at tr
ansla
te an
inpu
t vol
tage
into
a nu
mbe
r tha
t ran
ges f
rom
0 (0
vol
ts)
to 1
023
(5 v
olts)
. �e a
nalo
g pi
ns ar
e per
fect
for m
easu
ring
all th
ose "
real
wor
ld" v
alues
, and
allo
w y
ou to
inte
rface
the R
edBo
ard
to al
l kin
ds o
f thi
ngs.
Digi
tal v
ersu
s An
alog
:
DIGI
TAL
0 vo
lts 0
5 vo
lts
1023
toor
ANAL
OG
HIGH
on 5 vo
lts
LOW
off
0 vo
lts
Page 27
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 2 12/15/16 11:14 AM
-
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Most traditional volume knobs employ a potentiometer.
Circuit 2 Arduino Code:2
Troubleshooting:
Sporadically Working �is is most likely due to a slightly dodgy connection with the potentiometer's pins. �is can usually be conquered by holding the potentiometer down.
Not WorkingMake sure you haven’t accidentally connected the wiper, the resistive element in the potentiometer, to digital pin 0 rather than analog pin 0. (the row of pins beneath the power pins).
LED Not Lighting Up?LEDs will only work in one direction. Try taking it out and turning it 180 degrees (no need to worry, installing it backward does no permanent harm).
You should see the LED blink faster or slower in accordance with your potentiometer. If it isn't working, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshooting tips below.
A “variable” is a stored value you’ve given a name to. You must introduce, or "declare" variables before you use them; here we're declaring a variable called sensorValue, of type "int" (integer). Don't forget that variable names are case-sensitive!
int sensorValue;
Code to Note:
Real World Application:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 2
What you Should See:
�e Arduino is very very fast, capable of running thousands of lines of code each second. To slow it down so that we can see what it's doing, we'll often insert delays into the code. delay() counts in milliseconds; there are 1000 ms in one second.
delay(sensorValue);
We use the analogRead() function to read the value on an analog pin. analogRead() takes one parameter, the analog pin you want to use ("sensorPin"), and returns a number ("sensorValue") between 0 (0 volts) and 1023 (5 volts).
sensorValue = analogRead(sensorPin);
Page 28
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 3 12/15/16 11:14 AM
-
Circuit 2PA
RTS:
p.10
IC
1X
330ΩResistor
8X
LED
8X
You know what’s even more fun than a blinking LED? Changing colors with one LED. RGB, or red-green-blue, LEDs have three di�erent color-emit-ting diodes that can be combined to create all sorts of colors. In this circuit, you’ll learn how to use an RGB LED to create unique color combinations. Depending on how bright each diode is, nearly any color is possible!
RGB LED
PART
S:CIRCUIT #3 3
Potentiometer
1X
TransistorP2N2222AG
1X
Wire
6X
330ΩResistor
3X
LED
1X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
red
commongreen
blue
GND(Ground)
RED
GREEN
BLUE
RedBoard
PIN 11
PIN 10
PIN 9
Resistors (330 ohm)(Orange-Orange-Brown)
LED(Light-Emitting Diode)
Page 29
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 4 12/15/16 11:14 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Circ
uit 3
: RGB
LED
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
* The
long
est l
ead
is th
e co
mm
on(g
nd).
Page 30
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 5 12/15/16 11:14 AM
-
Com
pone
nt:
Imag
e Re
fere
nce:
e7e11
5V33
0Ω R
esis
tor
g4e4 e7
e115V
330Ω
Res
isto
rg6
e6 e7e11
5V33
0Ω R
esis
tor
g7e7
RGB
LED
(5m
m)
Jum
per W
ireG
ND
Jum
per W
ire5V5V
+
Jum
per W
irePi
n 9
h4
Jum
per W
irePi
n 10
h6
Jum
per W
irePi
n 11
h7
e5Ju
mpe
r Wire
We'v
e se
en th
at th
e Ar
duin
o ca
n re
ad a
nalo
g vo
ltage
s (vo
ltage
s bet
wee
n 0
and
5 vo
lts) u
sing
the
anal
ogR
ead(
) fun
ctio
n. Is
ther
e a
way
for t
he R
edBo
ard
to
outp
ut a
nalo
g vo
ltage
s as w
ell?
�e
answ
er is
no.
.. an
d ye
s. �
e R
edBo
ard
does
not
hav
e a
true
ana
log
volta
ge
outp
ut. B
ut, b
ecau
se th
e R
edBo
ard
is so
fast,
it c
an fa
ke it
usin
g so
met
hing
ca
lled
PW
M ("
Pul
se-W
idth
Mod
ulat
ion"
). �
e pi
ns o
n th
e R
edBo
ard
with
“~
” ne
xt to
them
are
PW
M/A
nalo
g ou
t com
patib
le.
�e
Red
Boar
d is
so fa
st th
at it
can
blin
k a
pin
on a
nd o
� al
mos
t 100
0 tim
es
per s
econ
d. P
WM
goe
s one
step
furt
her b
y va
ryin
g th
e am
ount
of t
ime
that
th
e bl
inki
ng p
in sp
ends
HIG
H v
s. th
e tim
e it
spen
ds L
OW
. If i
t spe
nds m
ost
of it
s tim
e H
IGH
, a L
ED c
onne
cted
to th
at p
in w
ill a
ppea
r brig
ht. I
f it
spen
ds m
ost o
f its
time
LOW
, the
LED
will
look
dim
. Bec
ause
the
pin
is bl
inki
ng m
uch
faste
r tha
n yo
ur e
ye c
an d
etec
t, th
e R
edBo
ard
crea
tes t
he
illus
ion
of a
"tr
ue"
anal
og o
utpu
t.
The
shoc
king
trut
h be
hind
ana
logW
rite(
):
90%90
%
50%
50%
0.5V
2.5V
4.5V
LOW
(0 v
olts
)
HIG
H (5
vol
ts)
LOW
(0 v
olts
)
HIG
H (5
vol
ts)
LOW
(0 v
olts
)
HIG
H (5
vol
ts)
10%
10%
a4a5
a6a7
Page 31
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 6 12/15/16 11:14 AM
-
Many electronics such as videogame consoles use RGB LEDs to have the versatility to show di�erent colors in the same area. Often times the di�ent colors represent di�erent states of working condition.
Circuit 2 Arduino Code:3
Troubleshooting:
LED Remains Dark or Shows Incorrect ColorWith the four pins of the LED so close together, it’s sometimes easy to misplace one. Double check each pin is where it should be.
Seeing Red�e red diode within the RGB LED may be a bit brighter than the other two. To make your colors more balanced, use a higher Ohm resistor. Or adjust in code.
analogWrite(RED_PIN, redIntensity);
to
analogWrite(RED_PIN, redIntensity/3);
You should see your LED turn on, but this time in new, crazy colors! If it isn't, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 3
What you Should See:
A for() loop is used to step a number across a range, and repeatedly runs code within the brackets {}. Here the variable "x" starts a 0, ends at 767, and increases by one each time ("x++").
for (x = 0; x < 767; x++){}
�e RedBoard is very very fast, capable of running thousands of lines of code each second. To slow it down so that we can see what it's doing, we'll often insert delays into the code. delay() counts in milliseconds; there are 1000 ms in one second.
delay(sensorValue);
"If / else" statements are used to make choices in your programs. �e statement within the parenthesis () is evaluated; if it's true, the code within the �rst brackets {} will run. If it's not true, the code within the second brackets {} will run.
if (x
-
So you have gotten one LED to blink on and o� – fantastic! Now it's time to up the stakes a little bit – by connecting EIGHT LEDS AT ONCE. We'll also give our RedBoard a little test by creating various lighting sequences. �is circuit is a great setup to start practicing writing your own programs and getting a feel for the way RedBoard works.
Along with controlling the LEDs, you’ll learn about a couple programming tricks that keep your code neat and tidy:
for() loops - used when you want to run a piece of code several times
arrays[ ] - used to make managing variables easier by grouping them together
Multiple LEDs
PART
S: LED
8X
Wire
10X
330ΩResistor
8X
CIRCUIT #4 4
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Resistors (330 ohm)(Orange-Orange-Brown)
LEDs(Light-Emitting Diodes)
RedBoard
PIN 2
PIN 3
PIN 4
PIN 5
GND (Ground)
Resistors (330 ohm)(Orange-Orange-Brown)
LEDs(Light-Emitting Diodes)
RedBoard
PIN 6
PIN 7
PIN 8
PIN 9
GND (Ground)
Page 33
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 8 12/15/16 11:14 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Circ
uit 4
: Mul
tiple
LED
s
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Page 34
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 28-36.pdf 9 12/15/16 11:14 AM
-
Com
pone
nt:
Imag
e Re
fere
nce:
Com
pone
nt:
Imag
e Re
fere
nce:
330Ω
Res
isto
ra1
8G
ND
330Ω
Res
isto
r
330Ω
Res
isto
r
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire5V
Jum
per W
ire
LED
(5m
m)
+-
+-
c2c3
e2Pi
n 2
330Ω
Res
isto
ra1
5
330Ω
Res
isto
ra1
2
330Ω
Res
isto
ra9
330Ω
Res
isto
r
330Ω
Res
isto
ra6a3
LED
(5m
m)
+-
+-
c23
c24
LED
(5m
m)
+-
+-
c20
c21
LED
(5m
m)
+-
+-
c17
c18
LED
(5m
m)
+-
+-
c14
c15
LED
(5m
m)
+-
+-
c11
c12
LED
(5m
m)
+-
+-
c8c9
LED
(5m
m)
+-
+-
c5c6
a18
a24
a21
Pin
3
5V
e5
GN
D
Pin
4e8
Pin
5e1
1
Pin
6e14
Pin
7e17
Pin
8e2
0
Pin
9e2
3 +
Page 35
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 1 12/15/16 11:12 AM
-
Page 36
Circuit 2 Arduino Code:4
Troubleshooting:
Some LEDs Fail to Light It is easy to insert an LED backwards. Check the LEDs that aren't working and ensure they the right way around.
Operating out of sequenceWith eight wires it's easy to cross a couple. Double check that the �rst LED is plugged into pin 2 and each pin there after.
Starting AfreshIts easy to accidentally misplace a wire without noticing. Pulling everything out and starting with a fresh slate is often easier than trying to track down the problem.
�is is similar to circuit number one, but instead of one LED, you should see all the LEDs blink. If they aren't, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshooting tips below.
Code to Note:
Real World Application:
Scrolling marquee displays are generally used to spread short segments of important information. �ey are built out of many LEDs.
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 4
What you Should See:
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
When you have to manage a lot of variables, an "array" is a handy way to group them together. Here we're creating an array of integers, called ledPins, with eight elements.
int ledPins[] = {2,3,4,5,6,7,8,9};
Computers like to do the same things each time they run. But sometimes you want to do things randomly, such as simulating the roll of a dice. �e random() function is a great way to do this. See http://arduino.cc/en/reference/random for more information.
index = random(8);
You refer to the elements in an array by their position. �e �rst element is at position 0, the second is at position 1, etc. You refer to an element using "ledPins[x]" where x is the position. Here we're making digital pin 2 HIGH, since the array element at position 0 is "2".
digitalWrite(ledPins[0], HIGH);
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 2 12/15/16 11:12 AM
-
Page 37
Circuit 2PA
RTS: Wire
19X
IC
1X
330ΩResistor
8X
LED
8X
Circuit 2
Up until now, we’ve focused solely on outputs. Now we’re going to go to the other end of spectrum and play around with inputs. In this circuit, we’ll be looking at one of the most common and simple inputs – a push button. �e way a push button works with RedBoard is that when the button is pushed, the voltage goes LOW. �e RedBoard reads this and reacts accordingly. In this circuit, you will also use a pull-up resistor, which keeps the voltage HIGH when you're not pressing the button.
Push Buttons
PART
S: Wire
7X
CIRCUIT #5 5
Push Button
2X
LED
1X
330ΩResistor
1X
10KΩResistor
2X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Resistors (330 ohm)(Orange-Orange-Brown)
GND(Ground)
Resistors (10K ohm)(Brown-Black-Orange)
LED(Light-Emitting Diode)
RedBoard
Buttons
PIN 13
PIN 2PIN 3
5 volt
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 3 12/15/16 11:12 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Page 38
Circ
uit 5
: Pus
h Bu
ttons
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 4 12/15/16 11:12 AM
-
Page 39
Com
pone
nt:
Imag
e Re
fere
nce:
LED
(5m
m)
+-
+-
h20
h21
Push
But
ton
d4g4
d6g6
Push
But
ton
d9g9
d11
g11
Jum
per W
irePi
n 2
h6
Jum
per W
irePi
n 3
h11
Jum
per W
irePi
n 13
j20
i4Ju
mpe
r Wire
i9Ju
mpe
r Wire
10KΩ
Res
isto
ra1
5i6
+
10KΩ
Res
isto
ri1
1+
330Ω
Res
isto
rj2
1+
One
of t
he th
ings
that
mak
es th
e Red
Boar
d so
use
ful i
s tha
t it c
an m
ake c
ompl
ex d
ecisi
ons
base
d on
the i
nput
it's
getti
ng. F
or ex
ampl
e, yo
u co
uld
mak
e a th
erm
osta
t tha
t tur
ns o
n a
heat
er if
it g
ets t
oo co
ld, a
fan
if it
gets
too
hot,
wat
ers y
our p
lants
if th
ey g
et to
o dr
y, et
c.
In o
rder
to m
ake s
uch
decis
ions
, the
Ard
uino
envi
ronm
ent p
rovi
des a
set o
f log
ic op
erat
ions
th
at le
t you
bui
ld co
mpl
ex "i
f" st
atem
ents.
�ey
inclu
de:
You
can
com
bine
thes
e fun
ctio
ns to
bui
ld co
mpl
ex if
() sta
tem
ents.
For e
xam
ple:
if ((
mod
e ==
hea
t) &
& ((
tem
pera
ture
< th
resh
old)
|| (o
verr
ide
== tr
ue))
){ di
gita
lWri
te(H
EAT
ER, H
IGH
);} ...
will
turn
on
a hea
ter i
f you
're in
hea
ting
mod
e AN
D th
e tem
pera
ture
is lo
w, O
R if
you
tu
rn o
n a m
anua
l ove
rrid
e. U
sing
thes
e log
ic op
erat
ors,
you
can
prog
ram
you
r Red
Boar
d to
m
ake i
ntell
igen
t dec
ision
s and
take
cont
rol o
f the
wor
ld ar
ound
it!
How
to u
se lo
gic
like
a Vu
lcan
:
==
EQUI
VALE
NCE
A ==
B is
true
if A
and
B a
re th
e SA
ME.
!=DI
FFER
ENCE
A !=
B is
true
if A
and
B a
re N
OT T
HE S
AME.
&&
AND
A &
& B
is tr
ue if
BOT
H A
and
B ar
e TR
UE.
||OR
A ||
B is
true
if A
or B
or B
OTH
are
TRUE
.
!NO
T!A
is T
RUE
if A
is F
ALSE
. !A
is F
ALSE
if A
is T
RUE.
Jum
per W
ireG
ND
Jum
per W
ire5V
+
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 5 12/15/16 11:12 AM
-
Page 40
�e buttons we used here are similar to the buttons in most video game controllers.
Circuit 2 Arduino Code:5
Troubleshooting:
Light Not Turning On �e pushbutton is square, and because of this it is easy to put it in the wrong way. Reinsert it turned 90 degrees in the breadboard and see if it starts working.
Light Not Behaving as Expected with Button PushDouble check that your resistors are inserted properly in the breadboard. If your button is left �oating (not pulled HIGH to 5V), you may see some erratic behavior of the LEDs.
You should see the LED turn on if you press either button, and o� if you press both buttons. (See the code to �nd out why!) If it isn't working, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 5
What You Should See:
�e digital pins can be used as inputs as well as outputs. Before you do either, you need to tell the RedBoard which direction you're going.
pinMode(button2Pin, INPUT);
Because we've connected the button to GND, it will read LOW when it's being pressed. Here we're using the "equivalence" operator ("==") to see if the button is being pressed.
if (button1State == LOW)
To read a digital input, you use the digitalRead() function. It will return HIGH if there's 5V present at the pin, or LOW if there's 0V present at the pin.
button1State = digitalRead(button1Pin);
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 6 12/15/16 11:12 AM
-
Page 41
Circuit 2
So you’ve already played with a potentiometer, which varies resistance based on the twisting of a knob. In this circuit, you’ll be using a photo resistor, which changes resistance based on how much light the sensor receives. Since the RedBoard can’t directly interpret resistance (rather, it reads voltage), we use a voltage divider to use our photo resistor. �is voltage divider will output a high voltage when it is getting a lot of light and a low voltage when it is not.
Photo Resistor
PART
S: Wire
6X
CIRCUIT #6 6
LED
1X
330ΩResistor
1X
Photo Resistor
1X
10KΩResistor
1X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
PIN 9
PIN A0
Resistor (330 ohm)(Orange-Orange-Brown)
GND (Ground)
Resistor (10K ohm)(Brown-Black-Orange)
LED(Light-Emitting Diode)
Photocell(Light Sensitive Resistor)
RedBoard
5 volt
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 7 12/15/16 11:12 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Page 42
Circ
uit 6
: Ph
oto
Resi
stor
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 8 12/15/16 11:12 AM
-
Page41
Com
pone
nt:
Imag
e Re
fere
nce:
+-
+-
h20
h21
LED
(5m
m)
Phot
o Re
sist
or
j1Ju
mpe
r Wire
j6+
Jum
per W
ire
Jum
per W
ireGN
D
Jum
per W
ire5V5V
+
330Ω
Res
isto
r (se
nsor
)j2
1+
10KΩ
Res
isto
ri1
i5
Jum
per W
ireA0
j5
f5f6
Jum
per W
irePi
n 9
j20
Man
y of
the
sens
ors y
ou'll
use
(pot
entio
met
ers,
phot
ores
istor
s, et
c.) a
re re
sisto
rs
in d
isgui
se. �
eir r
esist
ance
cha
nges
in p
ropo
rtio
n to
wha
teve
r the
y're
sens
ing
(ligh
t lev
el, t
empe
ratu
re, s
ound
, etc
.).
�e
Red
Boar
d's a
nalo
g in
put p
ins m
easu
re v
olta
ge, n
ot re
sista
nce.
But
we
can
easil
y us
e re
sistiv
e se
nsor
s with
the
Red
Boar
d by
incl
udin
g th
em a
s par
t of a
"v
olta
ge d
ivid
er".
A vo
ltage
div
ider
con
sists
of tw
o re
sisto
rs. �
e "t
op"
resis
tor i
s the
sens
or y
ou'll
be
usin
g. �
e "b
otto
m"
one
is a
norm
al, �
xed
resis
tor.
Whe
n yo
u co
nnec
t the
to
p re
sisto
r to
5 vo
lts, a
nd th
e bo
ttom
resis
tor t
o gr
ound
. �e
volta
ge a
t the
m
iddl
e w
ill b
e pr
opor
tiona
l to
the
botto
m re
sisto
r rel
ativ
e to
the
tota
l res
istan
ce
(top
resis
tor +
bot
tom
resis
tor)
. Whe
n on
e of
the
resis
tors
cha
nges
(as i
t will
w
hen
your
sens
or se
nses
thin
gs),
the
outp
ut v
olta
ge w
ill c
hang
e as
wel
l!
Alth
ough
the
sens
or's
resis
tanc
e w
ill v
ary,
the
resis
tive
sens
ors (
�ex
sens
or li
ght
sens
or, s
oftp
ot, a
nd tr
impo
t) in
the S
IK a
re a
roun
d 10
K o
hms.
We u
suall
y w
ant
the
�xed
resis
tor t
o be
clo
se to
this
valu
e, so
usin
g a
10K
resis
tor i
s a g
reat
cho
ice
for t
he �
xed
"bot
tom
" re
sisto
r. Pl
ease
not
e th
e �x
ed re
sisto
r isn
't ne
cess
arily
the
botto
m re
sisto
r. W
e do
that
with
the
phot
odio
de o
nly
so th
at m
ore
light
= m
ore
volta
ge, b
ut it
cou
ld b
e �i
pped
and
we'd
get
the
oppo
site
resp
onse
.
Mea
surin
g re
sist
ive
sens
ors:
PIN
3
5 vo
lts
GN
D(g
roun
d) (-
)
Pin
A0
Page 43
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 35-43.pdf 9 12/15/16 11:12 AM
-
A street lamp uses a light sensor to detect when to turn the lights on at night.
Circuit 2 Arduino Code:6
Troubleshooting:
LED Remains DarkTis is a mistake we continue to make time and time
again, if only they could make an LED that worked both ways. Pull it out and rotate it 180 degrees.
It Isn't Responding to Changes in LightGiven that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check it’s in the right place.
Still Not Quite WorkingYou may be in a room which is either too bright or dark. Try turning the lights on or o� to see if this helps. Or if you have a �ashlight near by give that a try.
You should see the LED grow brighter or dimmer in accordance with how much light your photoresistor is reading. If it isn't working, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 6
What You Should See:
When we read an analog signal using analogRead(), it will be a number from 0 to 1023. But when we want to drive a PWM pin using analogWrite(), it wants a number from 0 to 255. We can "squeeze" the larger range into the smaller range using the map() function.
lightLevel = map(lightLevel, 0, 1023, 0, 255);
Because map() could still return numbers outside the "to" range, we'll also use a function called constrain() that will "clip" numbers into a range. If the number is outside the range, it will make it the largest or smallest number. If it is within the range, it will stay the same.
lightLevel = constrain(lightLevel, 0, 255);
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
See http://arduino.cc/en/reference/map for more info.
See http://arduino.cc/en/reference/constrain for more info.
Parameters map(value, fromLow, fromHigh, toLow, toHigh)
Parameters constrain(x, a, b) x: the number to constrain, all data typesa: the lower end of the range, all data typesb: the upper end of the range, all data types
value: the number to mapfromLow: the lower bound of the value's current rangefromHigh: the upper bound of the value's current rangetoLow: the lower bound of the value's target rangetoHigh: the upper bound of the value's target range
Page 44
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 1 12/15/16 11:12 AM
-
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
Circuit 2
A temperature sensor is exactly what it sounds like – a sensor used to measure ambient temperature. �is particular sensor has three pins – a positive, a ground, and a signal. �is is a linear temperature sensor. A change in temperature of one degree centigrade is equal to a change of 10 millivolts at the sensor output. �e TMP36 sensor has a nominal 750 mV at 25°C (about room temperature). In this circuit, you’ll learn how to integrate the temperature sensor with your RedBoard, and use the Arduino IDE’s serial monitor to display the temperature.
Temperature Sensor
CIRCUIT #7 7
p.44
GND(Ground)
RedBoard
TMP36(Precision Temperature Sensor)
5 volt
GND3
VCC1
VOUT 2 PIN A0
PART
S: Wire
5X
Temp. Sensor
1X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
FRONT
BACK
When you’re building the circuit be careful not to mix up the transistor and the temperature sensor, they’re almost identical. Look for “TMP” on the body of the temperature sensor.
SIGNAL+V
GND
SIGNALGND
+V
Page 45
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 2 12/15/16 11:12 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Circ
uit 7
: Tem
pera
ture
Sen
sor
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Page 46
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 3 12/15/16 11:12 AM
-
Tem
pera
ture
Sen
sor
f5f7
f6
Com
pone
nt:
Imag
e Re
fere
nce:
j5Ju
mpe
r Wire
j7Ju
mpe
r Wire
Jum
per W
ireG
ND
Jum
per W
ire5V5V
+
Jum
per W
ireA0
j6
+
�is
circ
uit u
ses t
he A
rdui
no ID
E's s
eria
l mon
itor
. To
open
this,
�rs
t upl
oad
the
prog
ram
then
clic
k th
e bu
tton
whi
ch lo
oks l
ike
a m
agni
fyin
g gl
ass i
n a
squa
re. I
n or
der f
or th
e se
rial m
onito
r to
oper
ate
corr
ectly
it m
ust b
e se
t to
the
sam
e ba
ud
rate
(spe
ed in
bits
per
seco
nd) a
s the
cod
e yo
u're
runn
ing.
�is
code
runs
at 9
600
baud
; if t
he b
aud
rate
setti
ng is
not
960
0, c
hang
e it
to 9
600.
Open
ing
your
ser
ial m
onito
r:
1
2
3
+VSIG
NAL
GN
D
-+
VO
UT
Page 47
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 4 12/15/16 11:12 AM
-
Building climate control systems use a temperature sensor to monitor and maintain their settings.
Circuit 2 Arduino Code:7
Troubleshooting:
Nothing Seems to Happen�is program has no outward indication it is working. To see the results you must open the Arduino IDE's serial monitor (instructions on previous page).
Gibberish is Displayed�is happens because the serial monitor is receiving data at a di�erent speed than expected. To �x this, click the pull-down box that reads "*** baud" and change it to "9600 baud".
Temperature Value is Unchanging Try pinching the sensor with your �ngers to heat it up or pressing a bag of ice against it to cool it down.
You should be able to read the temperature your temperature sensor is detecting on the serial monitor in the Arduino IDE. If it isn't working, make sure you have assembled the circuit correctly and veri�ed and uploaded the code to your board or see the troubleshoot-ing tips below.
Code to Note:
Real World Application:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 7
What You Should See:
Before using the serial monitor, you must call Serial.begin() to initialize it. 9600 is the "baud rate", or communications speed. When two devices are communicating with each other, both must be set to the same speed.
Serial.begin(9600);
Serial.print() will print everything on the same line. Serial.println() will move to the next line. By using both of these commands together, you can create easy-to-read printouts of text and data.
Serial.println(degreesF);
�e Serial.print() command is very smart. It can print out almost anything you can throw at it, including variables of all types, quoted text (AKA "strings"), etc.
See http://arduino.cc/en/serial/print for more info.
Serial.print(degreesC);
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 22.75 deg F: 72.96voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 22.75 deg F: 72.96voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 22.75 deg F: 72.96voltage: 0.73 deg C: 22.75 deg F: 72.96voltage: 0.73 deg C: 23.24 deg F: 73.84voltage: 0.73 deg C: 22.75 deg F: 72.96voltage: 0.73 deg C: 23.24 deg F: 73.84
Page 48
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 5 12/15/16 11:12 AM
-
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
IOREFRESET
RESET
7-15V
SCLSDAAREFGND1312~11~10~98
7~6~54~3
21
0
TXRX
13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TXRX
LEARN. SHARE. HACK.
Circuit 2
Servos are ideal for embedded electronics applications because they do one thing very well that motors cannot – they can move to a position accurately. By varying the pulse width of the output voltage to a servo, you can move a servo to a speci�c position. For example, a pulse of 1.5 milliseconds will move the servo 90 degrees. In this circuit, you’ll learn how to use PWM (pulse width modulation) to control and rotate a servo.
A Single Servo
PART
S: Wire
8X
CIRCUIT #8 8
Servo
1X
RedBoard
No junction dot means no connection
GND
SIG
V+
W
R
B
5 volt
GND(Ground)
PIN 9
Page 49
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 6 12/15/16 11:12 AM
-
IOR
EF
RES
ET
RESET
7-15
V
SC
LS
DA
AR
EFG
ND 13 12
~11
~10 ~
9 8 7~
6~
5 4~
3 2 1 0
TXRX
13
3.3V
5V GN
D
GN
D
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX RX
LEARN. SHARE. HACK.
Circ
uit 8
: A S
ingl
e Se
rvo
ab
cd
ef
gh
i1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ab
cd
ef
gh
i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Page 50
C
M
Y
CM
MY
CY
CMY
K
SIK 3.3 Pages 44-52.pdf 7 12/15/16 11:12 AM
-
Com
pone
nt:
Imag
e Re
fere
nce:
Serv
oe5
e7e6
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
e6 e7e5
5V
Jum
per W
irePi
n 9
a7
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ireG
ND
b5
+
a6+
�e A
rdui
no d
evelo
pmen
t env
ironm
ent g
ives
you
a ve
ry u
sefu
l set
of b
uilt-
in co
mm
ands
for
doin
g ba
sic in
put a
nd o
utpu
t, m
akin
g de
cisio
ns u
sing
logi
c, so
lvin
g m
ath
prob
lems,
etc.
But t
he re
al po
wer
of A
rdui
no is
the h
uge c
omm
unity
usin
g it
and
their
will
ingn
ess t
o sh
are
their
wor
k.
Libr
aries
are c
ollec
tions
of n
ew co
mm
ands
that
hav
e bee
n pa
ckag
ed to
geth
er to
mak
e it e
asy
to in
clude
them
in y
our s
ketc
hes.
Ardu
ino
com
es w
ith a
hand
ful o
f use
ful l
ibra
ries,
such
as
the s
ervo
libr
ary
used
in th
is ex
ampl
e, th
at ca
n be
use
d to
inte
rface
to m
ore a
dvan
ced
devi
ces (
LCD
disp
lays,
stepp
er m
otor
s, et
hern
et p
orts,
etc.)
See h
ttp:
//ar
duin
o.cc
/en/
refe
renc
e/lib
rari
es fo
r a li
st of
the s
tand
ard
libra
ries a
nd
info
rmat
ion
on u
sing
them
.
But a
nyon
e can
crea
te a
libra
ry, a
nd if
you
wan
t to
use a
new
sens
or o
r out
put d
evice
, ch
ance
s are
that
som
eone
out
ther
e has
alre
ady
writ
ten
one t
hat i
nter
face
s tha
t dev
ice to
the
RedB
oard
. Man
y of
Spa
rkFu
n's p
rodu
cts c
ome w
ith A
rdui
no li
brar
ies, a
nd y
ou ca
n �n
d ev
en m
ore u
sing
Goo
gle a
nd th
e Ard
uino
Play
grou
nd at
htt
p://
ardu
ino.
cc/p
layg
roun
d/.
Whe
n YO
U g
et th
e Red
Boar
d w
orki
ng w
ith a
new
dev
ice, c
onsid
er m
akin
g a l
ibra
ry fo
r it
and
shar
ing
it w
ith th
e wor
ld!