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 Inventors Kit for the SparkFun RedBoard
IORE
FRE
SET
RESET
7-15V
SCL
SCA
AREF
GND
1312
~11
~10
~9 8
7~6
~5 4~3 2
10
TXRX13
3.3V
5VGN
DGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOG IN
DIGITAL (PWM~)
ON
ISP
TXRX
ARDUINO LANGUAGE DEVELOPMENT PLATFORM
Version 3.2
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 Educators. 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
Welcome to the SparkFun Inventors Guide
Table of Contents
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
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. Dont worry, youll learn about all these later.
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
.
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
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. Its 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)
user
Windows
Mac OS X
Linux: 32 bit, 64 bit
N
W
S
E
NW
SW
SE
NE
arduino.cc/en/main/software
Choose the appropriate Operating System installation package for your computer.
Download Click on your appropriate computer operating system next to the + sign.
Windows
Mac OS X
source
Linux: 32 bit, 64 bit
1
Page 4
// Connect your RedBoard to your Computer
Use the USB cable provided in the SIK kit to connect the RedBoard to one of your computers USB inputs.
// Install Arduino DriversDepending on your computers operating system, you will need to follow specic instructions. Please go to www.sparkfun.com/FTDI for specic instructions on how to install the FTDI drivers onto your RedBoard.
23
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
1 2 3 5 6
7
8
9
4
Open the Arduino IDE software on your computer. Poke around and get to know the interface. We arent 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
// The three most important commands for this guide are seen below:
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
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
// Select your board: Arduino 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 UNO are interchangeable but you wont find the RedBoard listed in the Arduino Software. Select Arduino UNO instead.
Page 8
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 browsers Downloads folder. Right click the zipped folder and choose unzip.
Copy the SIK Guide Code folder into Arduinos folder named examples.
Copy the SIK Guide Code folder into Arduinos folder named examples.
WHATS 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 browsers 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
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
Page 11
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
(P2N2222AG)
x2
Transistor
P2N2
222A
A18
FRONT
BACK
x1
Photo Resistor
Page 12
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
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
// 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
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
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
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
Hows 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
How It Works:
ASSEMBLE WRITE UPLOAD
Peel sticker o 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.3V5V
GNDGNDVIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGITAL (PWM~)ON
ISP
TX
RX
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 cant hurt you, so dont 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
.
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
330Resistor
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 dierent 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 rst time inventor!
Components like resistors need to have their legs bent into 90 angles in order to correctly t 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
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 t
he s
hort
leg,
m
arke
d w
ith
at
sid
e, g
oes
into
th
e ne
gati
ve p
ositi
on (-
).
330
Res
isto
r: T
he c
olor
ban
ding
sh
ould
rea
d or
ange
-or-
ange
-bro
wn-
gold
. The
com
po-
nent
legs
can
go
in e
ithe
r ho
le.
Jum
per
Wir
e: A
ll ju
mpe
r w
ires
w
ork
the
sam
e. T
hey
are
used
to
conn
ect
two
poin
ts t
oget
her.
This
gu
ide
will
sho
w t
he w
ires
wit
h di
er
ent
colo
red
insu
lati
ons
for
clar
ity,
but
usi
ng
di
eren
t co
mbi
nati
ons
of c
olor
s is
co
mpl
etel
y ac
cept
able
.
Fla
t E
dg
e
Sho
rt L
eg
Page 20
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
ireGN
D
Jum
per W
ire5V5V
+5
V
on t
he R
edB
oard
con
nect
s to
the
row
mar
ked
+
on t
he b
read
boar
d.
Pin
13
on
the
RedB
oard
con
nect
s to
soc
ket
e2
on
the
brea
dboa
rd.
GN
D
on t
he R
edB
oard
sho
uld
be c
onne
cted
to
the
row
mar
ked
-
on t
he b
read
boar
d.
Resi
stor
s ar
e pl
aced
in b
read
boar
d so
cket
s on
ly. T
he
- s
ymbo
l rep
rese
nts
any
sock
et in
its
verti
cal
colu
mn
on t
he P
ower
bus
.
Brea
dboa
rd: T
he w
hite
bac
kgro
und
repr
esen
ts a
con
necti
on to
a
brea
dboa
rd s
ocke
t spe
cie
d by
a
lett
er-n
umbe
r coo
rdin
ate
such
as
e2. T
hese
coo
rdin
ates
are
mer
ely
sugg
esti
ons
that
alig
n w
ith
the
grap
hic
imag
e.
RedB
oard
: The
red
back
grou
nd
repr
esen
ts a
con
necti
on to
one
of
the
RedB
oard
hea
der p
ins.
Com
pone
nts
like
LED
s ar
e in
sert
ed in
to t
he b
read
boar
d so
cket
s c2
(lon
g le
g) c
3(sh
ort
leg)
. Ste
ps
high
light
ed w
ith
a ye
llow
war
ning
tri
angl
e re
pres
ent
a po
lari
zed
com
pone
nt. P
ay s
peci
al a
tten
tion
to
the
com
pone
nts
mar
king
s in
dica
ting
how
to
plac
e it
on
the
brea
dboa
rd.
Page 21
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 #15Circuit #16
Circuit #1
/* Blink
Turns on an LED on for one second, then off 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 off delay(1000); // wait for a second}
// Circuit #1
Page 22
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
Circuit 2 Arduino Code:1
Troubleshooting:
LED Not Lighting Up?LEDs will only work in one direction. Try taking it out and twisting it 180 degrees (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 veried 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 nd 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 nd 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
Circuit 2PA
RTS: Wire
19X
CIRCUIT #5
IC
1X
330Resistor
8X
LED
8X
Circuit 2
In this circuit youll work with a potentiometer. A potentiometer is also known as a variable resistor. When its 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, youll learn how to use a potentiometer to control the brightness of an LED.
Potentiometer
PART
S: Wire
6X
CIRCUIT #2 2
LED
1X
330Resistor
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
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
Com
pone
nt:
Imag
e Re
fere
nce:
Pote
ntio
met
er
e6Ju
mpe
r Wire
e8Ju
mpe
r Wire
Jum
per W
ireGN
D
Jum
per W
ire5V
Pin
13j2
0
Jum
per W
ireGN
D
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 o
, or a
s the
y're
kno
wn
to th
e Red
Boar
d,
"HIG
H" (
5 vo
lts) a
nd "L
OW
" (0
volts
).
e dig
ital p
ins o
n an
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
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 havent accidentally connected thewiper, 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 twisting 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 veried and uploaded the code to your board or see the troubleshooting tips below.
A variable is a stored value youve 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
Circuit 2PA
RTS:
p.10
IC
1X
330Resistor
8X
LED
8X
You know whats even more fun than a blinking LED? Changing colors with one LED. RGB, or red-green-blue, LEDs have three dierent color-emit-ting diodes that can be combined to create all sorts of colors. In this circuit, youll 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
330Resistor
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
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
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
ireGN
D
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
Many electronics such as videogame consoles use RGB LEDs to have the versatility to show dierent colors in the same area. Often times the dient colors represent dierent 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, its sometimes easy to misplace one. Double check each pin is where it should be.
Seeing Rede 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 veried 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 < 768; 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, youll 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
330Resistor
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
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
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
GND
Pin
4e8
Pin
5e1
1
Pin
6e14
Pin
7e17
Pin
8e2
0
Pin
9e2
3 +
Page 35
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 veried 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);
Page 37
Circuit 2PA
RTS: Wire
19X
IC
1X
330Resistor
8X
LED
8X
Circuit 2
Up until now, weve focused solely on outputs. Now were going to go to the other end of spectrum and play around with inputs. In this circuit, well 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
330Resistor
1X
10KResistor
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
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
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
ireGN
D
Jum
per W
ire5V
+
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. Give it a 90 degree twist and see if it starts working.
Underwhelmed No worries, these circuits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.
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 veried 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.
Page 41
Circuit 2
So youve already played with a potentiometer, which varies resistance based on the twisting of a knob. In this circuit, youll be using a photo resistor, which changes resistance based on how much light the sensor receives. Since the RedBoard cant 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
330Resistor
1X
Photo Resistor
1X
10KResistor
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
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
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
GND
(gro
und)
(-)
Pin
A0
Page 43
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 Darkis is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist.
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 its 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 veried 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.
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
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 25C (about room temperature). In this circuit, youll learn how to integrate the temperature sensor with your RedBoard, and use the Arduino IDEs 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 youre building the circuit be careful not to mix up the transistor and the temperature sensor, theyre almost identical. Look for TMP on the body of the temperature sensor.
SIGNAL+V
GND
SIGNALGND
+V
Page 45
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
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
ireGN
D
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
+VSIGN
ALGN
D
-+
V OUT
Page 47
Building climate control systems use a temperature sensor to monitor and maintain their settings.
Circuit 2 Arduino Code:7
Troubleshooting:
Nothing Seems to Happenis 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 Displayedis happens because the serial monitor is receiving data at a dierent 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 veried 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.
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
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 specic position. For example, a pulse of 1.5 milliseconds will move the servo 90 degrees. In this circuit, youll 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
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
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
ireGN
D
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!
To
use a
libr
ary
in a
sket
ch, s
elect
it fr
om S
ketc
h >
Impo
rt L
ibra
ry.
Afte
r im
porti
ng th
e lib
rary
into
you
r cod
e, yo
u w
ill h
ave a
cces
s to
a num
ber o
f pre
-writ
ten
com
man
ds an
d fu
nctio
ns. M
ore i
nfor
mat
ion
on h
ow to
use
the s
tand
ard
libra
ry fu
nctio
ns
can
be ac
cesse
d at
: htt
p://
ardu
ino.
cc/e
n/R
efer
ence
/Lib
rari
es.
Expa
nd y
our h
oriz
ons
usin
g Li
brar
ies:
File
Edi
tS
ketc
hTo
ols
Hel
p
EE
PR
OM
Eth
erne
tFi
rmat
aLi
quid
Cry
stal
SD
Ser
voS
oftw
areS
eria
lS
PI
Ste
pper
Wire
Ver
ify /
Com
pile
Sho
w S
ketc
h Fo
lder
Add
File
...Im
port
Libr
ary
Page 51
Circuit 2 Arduino Code:8
Troubleshooting:
Servo Not Twisting Even with colored wires it is still shockingly easy to plug a servo in backward. is might be the case.
Still Not WorkingA mistake we made a time or two was simply forgetting to connect the power (red and brown wires) to +5 volts and ground.
Fits and StartsIf the servo begins moving then twitches, and there's a ashing light on your RedBoard, the power supply you are using is not quite up to the challenge. Using a wall adapter instead of USB should solve this problem.
You should see your servo motor move to various locations at several speeds. If the motor doesn't move, check your connections and make sure you have veried and uploaded the code, or see the troubleshooting tips below.
Code to Note:
Real World Application:
Robotic arms you might see in an assembly line or sci- movie probably have servos in them.
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 8
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.
#include is a special "preprocessor" command that inserts a library (or any other le) into your sketch. You can type this command yourself, or choose an installed library from the "sketch / import library" menu.
#include
e servos in this kit don't spin all the way around, but they can be commanded to move to a specic position. We use the servo library's write() command to move a servo to a specied number of degrees(0 to 180). Remember that the servo requires time to move, so give it a short delay() if necessary.
servo1.write(180);
e servo library adds new commands that let you control a servo. To prepare the Arduino to control a servo, you must rst create a Servo "object" for each servo (here we've named it "servo1"), and then "attach" it to a digital pin (here we're using pin 9).
Servo servo1;
servo1.attach(9);
Page 52
PART
S: IC
1X
330Resistor
8X
LED
8X
In this circuit, we will use a ex sensor to measure, well, ex! A ex sensor uses carbon on a strip of plastic to act like a variable resistor, but instead of changing the resistance by turning a knob, you change it by exing (bending) the component. We use a "voltage divider" again to detect this change in resistance. e sensor bends in one direction and the more it bends, the higher the resistance gets; it has a range from about 10K ohm to 35K ohm. In this circuit we will use the amount of bend of the ex sensor to control the position of a servo.
Flex Sensor
PART
S:CIRCUIT #9 9
Potentiometer
1X
Servo
1X
Flex Sensor
1X
10KResistor
1X
Wire
11X
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.
RedBoard
Resistor (10K ohm)
Flex Sensor
(Brown-Black-Orange)
GND
SIG
V+
W
R
B
5 volt
(Ground)GND
PIN 9 PIN A0
Page 53
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.
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
Circ
uit 9
: Fle
x Se
nsor
Page 54
It ha
ppen
s to
ever
yone
- yo
u w
rite a
sket
ch w
hich
succ
essfu
lly co
mpi
les an
d up
load
s, bu
t you
can'
t gu
re o
ut w
hy it
's no
t doi
ng w
hat y
ou w
ant i
t to.
Lar
ger c
ompu
ters
have
scre
ens,
keyb
oard
s, an
d m
ice th
at y
ou ca
n us
e to
debu
g yo
ur co
de, b
ut ti
ny
com
pute
rs lik
e the
Red
Boar
d ha
ve n
o su
ch th
ings
.
e k
ey to
visi
bilit
y in
to a
micr
ocon
trolle
r is o
utpu
t.
is ca
n be
alm
ost a
nyth
ing,
in
cludi
ng L
EDs a
nd b
uzze
rs, b
ut o
ne o
f the
mos
t use
ful t
ools
is th
e ser
ial m
onito
r. U
sing
Seri
al.p
rint
() an
d pr
intln
(), y
ou ca
n ea
sily
outp
ut h
uman
-read
able
text
and
data
from
the R
edBo
ard
to a
win
dow
bac
k on
the h
ost c
ompu
ter.
is
is gr
eat f
or
your
sket
ch's
nal
outp
ut, b
ut it
's als
o in
cred
ibly
use
ful f
or d
ebug
ging
.
Debu
ggin
g yo
ur s
ketc
hes
usin
g th
e Se
rial M
onito
r:Co
mpo
nent
:Im
age
Refe
renc
e:
i20
i24
Serv
oe1
e3e2
e1Ju
mpe
r Wire
i19
Jum
per W
ire
h24
+Ju
mpe
r Wire
h24
+Ju
mpe
r Wire
h24
+Ju
mpe
r Wire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
Jum
per W
ire
e2Ju
mpe
r Wire
e3Ju
mpe
r Wire
Flex
Sen
sor
h19
h20
10K
Res
isto
r
j20
A0
b1+
a2+
a3Pi
n 9
5V5V+
GND
And
if yo
u ru
n th
e cod
e aga
in, y
ou'll
see t
he
outp
ut y
ou w
ante
d:fo
r (x
= 1
; x
< 9
; x+
+){
Se
rial
.pri
nt(x
);}
1234
5678
You
want
ed 1
to 8
, but
the l
oop
is ac
tuall
y givi
ng yo
u 0
to 7
. Who
ops!
Now
you
just
need
to
x the
loop
.
0123
4567
Let's
Top Related