0% found this document useful (0 votes)
439 views105 pages

Sik Guide: Your Guide To The Sparkfun Inventor'S Kit For The Sparkfun Redboard

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
439 views105 pages

Sik Guide: Your Guide To The Sparkfun Inventor'S Kit For The Sparkfun Redboard

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 105

7 -

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG SDASCL
XT
A3 AREF
A4 XR13
GND
IN
13
12
~11
~10
~9
ISP LDIGITA 8
~6
7
ON
)(PWM~ 4
~5

~3
RX 1 2
TX
0

SIK GUIDE
Your guide to the SparkFun Inventor’s Kit for the SparkFun RedBoard
X
TX 7

~6

DIGITAL ~5 4

(PWM
ARDUINO

LANGUAGE
V

DEVELOPMENT

PLATFORM

Version 3.0
RE F T
Table of Contents

Welcome to the SparkFun Inventor’s Guide


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 15 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
Section 1: Getting Started

What is the RedBoard platform? 1

Download Arduino Software (IDE) 3

Install Drivers 4

Identify Your Hardware 7

Download “SIK Guide Code” 8

Section 2: Getting Started with Circuits

The World Runs on Circuits 9

Inventory of Parts 11

RedBoard 13

Breadboard 15

Circuit #1 - Your First Circuit: Blinking a LED 17

Circuit #2 - Potentiometer 24

Circuit #3 - RGB LED 28

Circuit #4 - Multiple LEDs 32

Circuit #5 - Push Buttons 36

Circuit #6 - Photo Resistor 40

Circuit #7 - Temperature Sensor 44

Circuit #8 - A Single Servo 48

Circuit #9 - Flex Sensor 52

Circuit #10 - Soft Potentiometer 56

Circuit #11 - Piezo Element 60

Circuit #12 - Spinning a Motor 64

Circuit #13 - Relay 68

Circuit #14 - Shift Register 72

Circuit #15 - LCD 76


What is the RedBoard platform?

The DIY Revolution


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

A Computer for the Physical World


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.

RedBoard

// SparkFun RedBoard
RESET

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
7-15V FPOO
outputs), 6 analog inputs, a 16 MHz crystal oscillator, a SCL SDA

AREF

USB connection, a power jack, an ISP header, and a reset GND

button. Don’t worry, you’ll learn about all these later.


3
1

IOREF 13
RESET 12
3.3V ~11
5V ~10
POWE

GND ~9
VIN
R

GND 8
DIGIT
AL

7
~6
A0
~5
ANALOG

(PW
M~)

A1
X
R
X
T

4
A2
~3
A3
2
A4
TX 1
IN

A5
RX 0
P
S
I
N
O
c
b

d
h

a Bug Zapper Counter d Camera Time-lapse operation g Auto-Coffee Maker


b Old Toy Email Notifer e Auto-Plant Watering h Quadcopter
c Power-Lacing High Tops f Re-Programmed Traffic Light
Download the Arduino IDE (Integrated Development Environment)

Access the Internet


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
N NE

W
E internet-capable computer, open up your favorite browser and
SW
S type in the following URL into the address bar:

arduino.cc/en/main/software

1 DownloadWindows
computer
Clickonyour appropriate

operating system next to the “ + ” sign.

Mac OSWindowsX
Mac OS X
Linux:
Linux: 3232 bit,bit,64bit64 bit
source

user

•••••••••

Choose the appropriate Operating System installation package for your computer.
// 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.

7 -

15V

IOREF
3. RESET
5V 3V
GND
VIN POWER RESET
GND
A0
A1
A2
A3 XT SDASCL

A4 AREF
A5 ANALOG XR13 GND

2
IN
13
12
~11
~10
ISP
~9
LDIGITA 8
7
ON
)(PWM~ 4 ~6
~5

~3
RX TX
1 2
0

3 // Install Arduino Drivers


Depending on your computer’s operating system, you will need to follow speci c
instructions. Please go to https://learn.sparkfun.com/tutorials/how-to-install-ftdi-
drivers for speci c instructions on how to install the FTDI drivers onto your RedBoard.
// Open the Arduino IDE:
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.

1 2 3 4 5 6

9
GUI (Graphical User Interface)

1 Verify: Compiles and approves your code. It will catch errors in syntax (like missing semi-colons or parenthesis). // See Diagram Below

2 Upload: Sends your code to the RedBoard. When you click it, you should see the lights on your board blink rapidly. // See Diagram Below

3 New: This buttons opens up a new code window tab.

4 Open: This button will let you open up an existing sketch. // See Diagram Below

5 Save: This saves the currently active sketch.

6 Serial Monitor: This will open a window that displays any serial information your RedBoard is transmitting. It is very useful for debugging.

7 Sketch Name: This shows the name of the sketch you are currently working on.

8 Code Area: This is the area where you compose the code for your sketch.

9 Message Area: This is where the IDE tells you if there were any errors in your code.

// The three most important commands for this guide are seen below:

Open

Verify

Upload
// Select your board: Arduino Uno

4 File Edit Sketch Tools Help


Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor

Board Arduino Uno


Serial Port Arduino Duemilanove w/ ATmega328]
Arduino Diecimila or Duemilanove w/ ATmega168
Programmer Arduino Nano w/ ATmega328
Burn Bootloader
Arduino Nano w/ ATmega168
Arduino Mega 2560 or Mega
ADK Arduino Mega
(ATmega1280) Arduino Mini
Arduino Mini w/ATmega168
Note: Arduino Ethernet
Arduino Fio
Your SparkFun RedBoard and the Arduino BT w/ ATmega328
Arduino BT w/ATmega168
Arduino UNO are interchangeable LilyPad Arduino w/ ATmega328
LilyPad Arduino w/ ATmega168
but you won’t find the RedBoard Arduino Pro or Pro Mini (5V, 16 MHz)
w/ATmega328 Arduino Pro or Pro Mini (5V, 16
listed in the Arduino Software. MHz) w/ATmega168 Arduino Pro or Pro Mini (3.3V,
8 MHz) w/ATmega328 Arduino Pro or Pro Mini
Select “Arduino UNO” instead. (3.3V, 8 MHz) w/ATmega168 Arduino NG or older
w/ ATmega168 Arduino NG or older w/ ATmega8

Tools Help
Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor

Board
Serial Port com 1
com 12
Select the serial device of the RedBoard from the Programmer
Tools | Serial Port menu. is is likely to be com3 or Burn Bootloader
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
Device

disappears should be the RedBoard. Reconnect the


board and select that serial port.
// Select your Serial

Tools Help
Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor

Board
Serial Port /dev/tty.usbmodem262471
/dev/cu.usbmodem262471
Select the serial device of the RedBoard from the Tools Programmer /dev/tty.Bluetooth-Modem
Burn Bootloader /dev/cu.Bluetooth-Modem
> Serial Port menu. On the Mac, this should
/dev/tty.FireFly-7256-SPP
be something with /dev/tty.usbmodem or /dev/cu.FireFly-7256-SPP
/dev/tty.usbserial in it. /dev/tty.tiPhone-WirelessiAP-1
/dev/cu.tiPhone-WirelessiAP-1
/dev/tty.Bluetooth-PDA-Sync
/dev/cu.Bluetooth-PDA-Sync

http://www.arduino.cc/playground/Learning/Linux
Download Arduino Code (For use with the circuits in this guide)

5
Type in the following URL to download the code:

sparkfun.com/sikcode
library in Arduino folder

Start Programs arduino examples

Unzip the le “SIK Guide Code”. It


should be located in your browser’s
Copy the “SIK Guide Code” folder into Arduino’s
“Downloads” folder. Right click the folder named “examples”.
zipped folder and choose “unzip”.

Contents
Copy “SIK Guide Code” into “Examples”

Resources
Find “Arduino” in your
applications folder. Right click(ctrl
Java
+ click) on “Arduino”. Select
Unzip the le “SIK Guide Code”. It “Show Package Contents”.
should be loacted in your browser’s examples
“Downloads” folder. Right click the Arduino
Open
zipped folder and choose “unzip”. Copy the “SIK Guide Code” folder into
Show Package Contents
Move to Trash Arduino’s folder named “examples”.

http://www.arduino.cc/playground/Learning/Linux
//

WHAT’S NEXT? Read on to learn more about getting started with circuits. en you can start on your rst circuit on
page 17!
Getting Started with Circuits

What is an Electrical Circuit?


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.

The World Runs on Circuits:


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.

abcde f g h i
// Simple and Complex Circuits 1 1
2 2
3 3
In this guide, you will be primarily exploring 4 4
5 5
simple circuits - but that doesn't mean you can't do 6 6
7 7
amazing things with simple tools! When you've 8 8
9 9
nished the SIK, your knowledge of circuits will 10 10
11 11
enable you to explore amazing projects and unleash 12 12
13 13
the power of your imagination. 14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
abcde f g h i
Inventory of Parts

Jumper Wire LED (5mm) -


+
Various Colors (Light Emitting Diode)

x30 x10 x10 x1

330 Resistor 10K


Resistor

* ACTUAL SIZE * ACTUAL SIZE


x25 x25

Potentiometer Diode
(1N4148)

* ACTUAL SIZE
x1 x2

Photo Resistor Piezo Element

x1

Temp. Sensor Transistor


(TMP36) (P2N2222AG)
P2N2222AA18

FRONT FRONT

BACK BACK
x1 x2

DC Motor Push Button

x1 x2
Flex Sensor SparkFun RedBoard

RESET
x1 7-15V

SCL
SDA
Soft Potentiometer AREF
GND
13
IOREF

12
RESET
~11
3.3V

~10
5V
~9

POWE
GND

DIGITAL
VIN
8

R
GND
7
~6

3
1
X
R
X
T

(PWM~
A0 ~5
A1
ANAL
4

)
OG
A4
A2 ~3
x1 A3 2
TX 1
IN

A5 RX 0
ISP
Servo N
O

x1

Breadboard
Standard Solderless (Color may vary)

x1
abcde f g h i
1 1

Relay Integrated Circuit 2


3
2
3
(IC) 4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
x1 x1 16 16
17 17
18 18
19 19

LCD 20
21
20
21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
abcde f g h i

x1 x1
RE
SE
T
2
1
8

7-15V

SCL
SDA
AREF
4 3 5
GND
13
IOREF
12
RESET
~11
3
1
X
R
X
T

3.3V
~10
5V
~9
GND
POW

10 8 6
ER

VIN
DIGITAL

GND
7
~6
(PWM~

A0 ~5
A1 4
ANAL

)
OG

A4
A2 ~3
A3 7 2
ON

TX 1
9
0
IN

A5 RX
ISP
SparkFun RedBoard

1 Power In (Barrel Jack) - Can be used with either a 9V or 12V wall-wart or battery.

2 Power In (USB Port) - Provides power and communicates with your board when plugged into your computer via USB.

3 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.

LED (TX: Transmitting) - This shows when the FTDI chip is transmitting data bits to the microcontroller. This
4 happens when the microcontroller is receiving this data from the computer.

5 LED (Pin 13: Troubleshooting) - This LED is incorporated into your sketch to show if your program is running properly.

6 Pins (ARef, Ground, Digital, Rx, Tx) - These various pins can be used for inputs, outputs, power, and ground. // See Diagram Below

7 LED (Indicates RedBoard is ON) - This is a simple power indicator LED.

8 Reset Button - This is a way to manually reset your RedBoard, which makes your code restart.

9 ICSP Pins (Uploading Code without Bootloader) - This is for "In-Circuit Serial Programming," used if you want to bypass the bootloader.

10 Pins (Analog In, Power In, Ground, Power Out, Reset) - These various pins can be used for inputs, outputs, power, and ground. // See Diagram

11 RFU - This pin is reserved for future use.

// Pins Diagram

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.

SCL
SDA
ARef
Ground
11 RFU
Digital
IOREF
Digital
Reset
Digital
Power Out
Digital
Power Out
Digital
Ground
Digital 6
Ground
10 Power In Digital
Digital
Analog Digital
Analog Digital
Analog Digital
Analog Digital
Analog TX - Out
Analog RX - In

= PWM/Analog out compatible (i.e. )


1

abcde f g h i
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
abcde f g h i

This line divides the board in half, restricting electricity to one half or the other.
Breadboard
1 Vertical Connection (+ Power and - Ground) - Power bus // See Diagram Below
Making a Connection:

2 Horizontal Connection (a-e & f-j) // See Diagram Below) Above the breadboard

LED

How’s it all connected?


CONNECTED!

abcde f gh i
1

1
Power:
2

3
Each + sign runs power anywhere
4

4
in the vertical column.
5

Ground:
6

8
8
Each - sign runs to ground anywhere Inside the breadboard

in the vertical column.


9

10

10

11

11

12

12
Horizontal Rows:
13

Each of these rows numbered 1-30 are


13

14

14

15
comprised of five horizontal sockets.
15

16
Components placed in the same row will be
16

17
connected in a circuit when power is running.
17

18

18

19

19

20
20

21
21

22
22

23
23

24
24

25
25

26
26

27
27

28
28

29
29

30 30

abcde f gh i
View of the inside
CIRCUIT #1 - Your First Circuit

How It Works:

ASSEMBLE WRITE UPLOAD

Make sure the text on the RedBoard and


breadboard are facing up so you can read them.
a bc de f
g h i
1 1

2 2
T
E
S
E
R

3 3

5 5
T
E
S
E
R

4 4

6 6

7-15V 7 7

7-15V 8 8

9 9

SCL
SCL 10 10
SDA 11 11

SDA
AREF 12 12
AREF

GND 13 13
GND
13 14 14
IOREF
13

13

IOREF 12 15 15
RESET 12
3
1

RESET ~11 16 16
3. 3 V ~11
17 17
X
X
R
R
X
T
X
T

3. 3 V ~10

Connect the USB cable.


5V 5V ~10 18 18
GN D ~9
P O WE R

A0 DIGITAL ~5
GN D ~9 19 19
GN D 8
GN D 8 20 20
VIN 7

VIN ~6 7 21 21
~6 22 22
(PWM~

A 1A 0 ~5 4 23 23
A3 2 26 26
)

A 2 A1 ~3 4 24 24
INA NA L
OG

A5 RX 0 28 28
A2 ~3 25 25
P
S
I

12
N
O

A 4 A3 TX

A 5 A4 RX T X 0
1 27 27
IN

N
O

29 29
30 30
P
S
I

a bc de f g h i

Screw the RedBoard down and into place.

7-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND TRESE

A0
A1
A2 SCL
A5 ANALOG XT SDA
13 AREF

A4 A3
XR GND
IN
12 13
~11
~10
~9
8
ISP LDIGITA
7
~6
)(PWM~4

ON
~3 ~5
TX 2
RX 1
0

Peel sticker off back of


breadboard and stick into place.

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.
PIN 13 RedBoard Blinking an LED
1
LED LEDs (light-emitting diodes) are small, powerful lights
(Light-Emitting Diode) 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
Resistor (330 ohm) toward more complex experiments.
(Orange-Orange-Brown)

Each circuit begins with a brief description


GND of the what you are putting together and
(Ground) the expected result.

This is a schematic of your circuit.

LED 330 Wire


PARTS:

Resistor
X 1 X 1 X 3 This section lists the parts you
will need to complete the circuit.

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A5
A2
ANALOG
SCL
A4 A3 XT
XR AREF
IN GND
13
12 13
~11
~10
~9
ISP LDIGITA 8
7
~6
)(PWM~ 4
ON ~5

~3
TX
1 2
RX
0

This is an illustration of how the


completed circuit should look. It is not
Components like resistors need to
necessary to use the black holder for
have their legs bent into 90° angles in
the RedBoard and breadboard, but we
order to correctly fit the breadboard
recommend it for the first time sockets. You can also cut the legs
inventor! shorter to make them easier to work
with on the breadboard.
Circuit 1: Blinking an LED

7-15V

IOREF

RESET
3.3V
5V
GND

POW
ER
VIN
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: Components like LEDs are inserted into the breadboard sockets c2(long leg) c3(short leg). Steps
highlighted with a yellow warning triangle represent a polarized component. Pay special attention to
+ c2 c3 the component’s markings indicating how to place it on the breadboard.
LED (5mm) -
-
Resistors are placed in breadboard sockets only. The “-” symbol represents any socket in its vertical
330 Resistor a3 a3 column on the Power bus.

Jumper Wire GND “GND” on the RedBoard should be connected to the row marked “-” on the breadboard.

Jumper Wire 5V + “5V” on the RedBoard connects to the row marked “+” on the breadboard.

Jumper Wire Pin 13 e2 “Pin 13” on the RedBoard connects to socket “e2” on the breadboard.

RedBoard: The red background Breadboard: The white background


represents a connection to one of represents a connection to a
the RedBoard header pins. breadboard socket specified by a
letter-number coordinate such as
e2. These coordinates are merely
suggestions that align with the
graphic image.
Open Your First Sketch:
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.

File Edit Sketch Tools Help


New
Open...
Sketchbook
Examples 1.Basics
Close 2.Digital
Save 3.Analog
Save As... 4.Communication
Upload 5.Control
Upload Using Progammer 6.Sensors
7.Displays
Page Setup 8.Strings
Print ArduinoISP
SIK Guide Code Circuit #1
Circuit #2
EEPROM Circuit #3
Ethernet Circuit #4
Firmata Circuit #5
Liquid Crystal Circuit #6
SD Circuit #7
Servo Circuit #8
SoftwareSerial Circuit #9
SPI Circuit #10
Stepper Circuit #11
Wire Circuit #12
Circuit #13
Circuit #14
Circuit #15

// Circuit #1

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


is compiles your code. e IDE changes it from text into instructions the computer
Verify
can understand.

is sends the instructions via the USB cable to the computer chip on the RedBoard. e
Upload
RedBoard will then begin running your code automatically.

// The result of a completed circuit with correct code after verified and uploaded.

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A3 XT SCL
A4 XR
SDA
A5 ANALOG 13

IN
GND
12 13
~11
~10
ISP ~9
LDIGITA 8
7
ON ~6
)(PWM~ ~5
~3
4
RX
TX
1 2
0
This is where you will find the
1 Circuit2 Arduino codeArduinoforeachcircuitCode:.

Open Arduino IDE // File > Examples > SIK Guide > Circuit # 1
Code to Note: Remember to Verify and
Upload your code.
Begin to understand how the
Arduino code works. See below.

Before you can use one of the RedBoard's pins, you need to tell the
pinMode(13, OUTPUT); RedBoard whether it is an INPUT or OUTPUT. We use a
built-in "function" called pinMode() to do this.

digitalWrite(13, HIGH); When you're using a pin as an OUTPUT, you can command it to be
HIGH (output 5 volts), or LOW (output 0 volts).

See if your circuit is complete


What you Should See: and working in this section.

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
7
or see the troubleshooting tips below. -

15V

IOREF
3. RESET
5V 3V
GND
VIN POWER RESET
GND
A0
A1
A2
A5 ANALOG

A4 A3

IN

ISP

This is a section dedicated to the most


common mistakes made while
assembling the circuit.

Troubleshooting: Real World Application:

LED Not Lighting Up? Almost all modern at screen televisions and monitors
LEDs will only work in one direction. Try taking it out and have LED indicator lights to show they are on or o .
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]
2
CIRCUIT #2

Potentiometer
PIN 13 RedBoard
In this circuit you’ll work with a potentiometer.
5 volt A potentiometer is also known as a variable resistor.
LED When it’s connected with 5 volts across its two outer
(Light-Emitting Diode) 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
Potentiometer PIN A0 demonstration of a variable voltage divider circuit.
RedBoard e voltage is divided proportionate to the resistance
Resistor (330 ohm) between the middle pin and the ground pin. In this
(Orange-Orange-Brown)
circuit, you’ll learn how to use a potentiometer to
control the brightness of an LED.

GND
(Ground)

PotentiometerIC LED 330 Wire


PARTS:

Resistor
X 1 X 18 X 18 X196

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG XR
SCL
A4 A3 XT SDA
AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
7
~6
)(PWM~ 4
ON
~3 ~5
TX
1 2
RX
0

p.2410
Circuit 2: Potentiometer

7-15V

IOREF

RESET

3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: Digital versus Analog:
a6

Potentiometer a7
a8
If you look closely at your RedBoard, you'll see some pins labeled
"DIGITAL", and some labeled "ANALOG". What's the erence?di
LED (5mm) + h20 h21
-
- Many of the devices you'll interface to, such as LEDs and pushbuttons,
have only two possible states: on and ,o or as they're known to the
330 Resistor j21 RedBoard, "HIGH" (5 volts) and "LOW" (0 volts). e digital pins on an
RedBoard are great at getting these signals to and from the outside
6 world, and can even do tricks like simulated dimming (by blinking on
Jumper Wire e and o really fast), and serial communications (transferring data to
another device by encoding it as patterns of HIGH and LOW).

Jumper Wire A0 8e7 LOW HIGH


+

inV3
DIGITAL off or on
Jumper Wire e
Jumper Wire P51 j20 0 volts 5 volts

But there are also a lot of things out there that aren't just "on" or ""o.
Jumper Wire GND5V + Temperature levels, control knobs, etc. all have a continuous range of values
Jumper Wire GND between HIGH and LOW. For these situations, the RedBoard erso six analog
inputs that translate an input voltage into a number that ranges from 0 (0 volts)
to 1023 (5 volts). e analog pins are perfect for measuring all those "real world"
values, and allow you to interface the RedBoard to all kinds of things.

0 volts 5 volts
ANALOG to
0 1023
2 Circuit
Arduino Code:

Open Arduino IDE // File > Examples > SIK Guide > Circuit # 2
Code to Note:

A “variable” is a stored value you’ve given a name to. You must


int sensorValue; 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!

We use the analogRead() function to read the value on an analog

sensorValue = analogRead(sensorPin); 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).

e Arduino is very very fast, capable of running thousands of lines of code

delay(sensorValue); 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.

What you Should See:


7
-

15V
You should see the LED blink faster
or slower in accordance with your IOREF
3. RESET
5V 3V
potentiometer. If it isn't working, GND
POWER

VIN GND
make sure you have assembled the
RESET

A0
A1
A2
circuit correctly and veri ed and A5
A4 A3
ANALOG

XT
SCL
SDA
XR
AREF
uploaded the code to your board or IN
13
13
12
~11
see the troubleshooting tips below. ~10
~9
ISP LDIGITA 8
~6
7
)(PWM~ 4
ON
~3 ~5
TX
1 2
RX
0

Troubleshooting: Real World Application:

Sporadically Working Most traditional volume knobs employ a potentiometer.


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 Working
Make 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
twisting it 180 degrees (no need to worry, installing it
backward does no permanent harm).
CIRCUIT #3

PIN 11
RGB LED 3
PIN 10 RedBoard You know what’s even more fun than a blinking
LED? Changing colors with one LED. RGB, or
PIN 9 red-green-blue, LEDs have three di erent color-
emit-ting diodes that can be combined to create all
Resistors (330 ohm) sorts of colors. In this circuit, you’ll learn how to
(Orange-Orange-Brown) use an RGB LED to create unique color
combinations. Depending on how bright each diode
is, nearly any color is possible!

LED
GREE
BLUE

RED

(Light-Emitting Diode)
N

GND
(Ground)

LEDPotentiometerIC330LE
PARTS:

D 330Wire
Resistor
X 1 X 1 X 3 X 1X6 X 8

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
SCL
A4 A3 XT
XR AREF
IN GND
13
12 13
~11
~10
~9
ISP LDIGITA 8
7
)(PWM~ 4 ~6
ON ~5

~3
TX
1 2
RX
0

r ed

blu e

common
green

p.2810
Circuit 3: RGB LED

7-15V

IOREF

RESET

3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: The shocking truth behind analogWrite():
a4 a5a6 a7
RGB LED (5mm) We've seen that the Arduino can read analog voltages (voltages between 0
and 5 volts) using the analogRead() function. Is there a way for the
RedBoard to output analog voltages as well?
330 Resistor 5V e4 g4
e answer is no... and yes. e RedBoard does not have a true analog voltage
5V g6
output. But, because the RedBoard is so fast, it can fake it using something
330 Resistor e6
called PWM ("Pulse-Width Modulation"). e pins on the RedBoard with
“~” next to them are PWM/Analog out compatible.
330 Resistor e7 g7
e RedBoard is so fast that it can blink a pin on and o almost 1000 times
per second. PWM goes one step further by varying the amount of time
Jumper Wire Pin 9 5h4 that the blinking pin spends HIGH vs. the time it spends LOW. If it
spends most of its time HIGH, a LED connected to that pin will appear
bright. If it spends most of its time LOW, the LED will look dim. Because
the pin is blinking much faster than your eye can detect, the RedBoard
Jumper Wire e creates the illusion of a "true" analog output.
Jumper Wire Pin 10 h6

HIGH (5 volts)
Jumper Wire Pin 11 h7 90% 0.5V
LOW (0 volts)
10%

Jumper Wire 5V +
HIGH (5 volts)
Jumper Wire GND
50%
LOW (0 volts) 2.5V
50%

10%
HI GH (5 vol ts )

LOW (0 volts) 4.5V


90%
Circuit 2 Arduino Code:

3
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 3

A for() loop is used to step a number across a range, and repeatedly


for (x = 0; x < 768; x++)
runs code within the brackets {}. Here the variable "x" starts a 0,
{}
ends at 767, and increases by one each time ("x++").

if (x <= 255) "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
else {} will run. If it's not true, the code within the second brackets {} will run.
{}

e RedBoard is very very fast, capable of running thousands of lines of

delay(sensorValue); 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.

What you Should See:


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 7
-
uploaded the code to your board or 15V

see the troubleshooting tips below.


IOREF
. RESET

3
5V 3V

GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
XT
SCL
A4 A3
XR AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
~6 7
ON )(PWM~ ~5
~3 4
TX
1 2
RX

Troubleshooting: Real World Application:

LED Remains Dark or Shows Incorrect Color Many electronics such as


With the four pins of the LED so close together, it’s videogame consoles use RGB
sometimes easy to misplace one. Double check each LEDs to have the versatility
pin is where it should be. to show di erent colors in
the same area. Often times
Seeing Red the di ent colors represent
e red diode within the RGB LED may be a bit brighter di erent states of working
than the other two. To make your colors more balanced, condition.
use a higher Ohm resistor. Or adjust in code.

analogWrite(RED_PIN, redIntensity);
to
analogWrite(RED_PIN, redIntensity/3);
CIRCUIT #4

PIN 2
PIN 3

RedBoard Multiple LEDs 4


PIN 4
PIN 5
So you have gotten one LED to blink on and o –
LEDs
(Light-Emitting Diodes) fantastic! Now it's time to up the stakes a little bit – by
connecting EIGHT LEDS AT ONCE. We'll also give
Resistors (330 ohm)
our RedBoard a little test by creating various lighting
(Orange-Orange-Brown)
sequences. is circuit is a great setup to start practicing
writing your own programs and getting a feel for the
GND (Ground)
way RedBoard works.
PIN 6

PIN 7

RedBoard Along with controlling the LEDs, you’ll learn about a


PIN 8

couple programming tricks that keep your code neat


PIN 9 and tidy:
LEDs
(Light-Emitting Diodes) for() loops - used when you want to run a piece of
Resistors (330 ohm) code several times
(Orange-Orange-Brown)

arrays[ ] - used to make managing variables easier by


GND (Ground) grouping them together

LED 330 Wire


PARTS:

Resistor
X 8 X 8 X 10

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
SCL
A4 A3

13
AREF
IN GND
12 13
~11
~10
~9
ISP LDIGITA 8
~6 7
)(PWM~ 4
ON
~3 ~5
TX
1 2
RX
0

p.32
Circuit 4: Multiple LEDs

7-15V

IOREF

RESET

3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

f gh i 25

26

2 27

3 28

4
29

5
30

6
f gh i
7
8

0
Component: Image Reference: Component: Image Reference:

LED (5mm) + c2 c3 a18


-
+ - 330 Resistor GND

LED (5mm) + c5 c6 330 Resistor a21


-
-

LED (5mm) + c8 c9 330 Resistor a24


-
-

LED (5mm) + c11 c12 Jumper Wire Pin 2 e2


-
-

LED (5mm) + c14 c15 Jumper Wire Pin 3 e5


-
-

LED (5mm) + c17 c18 Jumper Wire Pin 4 e8


-
-

LED (5mm) + c20 c21 Jumper Wire Pin 5 e11


-
-

LED (5mm) + c23 c24 Jumper Wire Pin 6 e14


-
-

330 Resistor a3 Jumper Wire Pin 7 e17

330 Resistor a6 Jumper Wire Pin 8 e20

330 Resistor a9 Jumper Wire Pin 9 e23

330 Resistor a12 Jumper Wire 5V +

330 Resistor a15 Jumper Wire GND


4
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 4
Arduino Code:

When you have to manage a lot of variables, an "array" is

int ledPins[] = {2,3,4,5,6,7,8,9}; a handy way to group them together. Here we're creating

an array of integers, called ledPins, with eight elements.

You refer to the elements in an array by their position.


e rst element is at position 0, the second is at position

digitalWrite(ledPins[0], HIGH); 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".

Computers like to do the same things each time they run. But sometimes
index = random(8); 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.

What you Should See:


is is similar to circuit number one, but 7
-

15V
instead of one LED, you should see all the
LEDs blink. If they aren't, make sure you IOREF
3. RESET
5V 3V

have assembled the circuit correctly and VIN


POWER

GND
GND

RESET

veri ed and uploaded the code to your board A1


A0

A2
A5 SCL
or see the troubleshooting tips below.
ANALOG

A4 A3 XT
XR AREF
IN
13 13
12
~11
~10
~9
ISP LDIGITA 8
)(PWM~4 ~6 7
ON
~3 ~5
TX
1 2
RX
0

Troubleshooting: Real World Application:

Some LEDs Fail to Light Scrolling marquee displays are generally used to spread
It is easy to insert an LED backwards. Check the LEDs short segments of important information. ey are built
that aren't working and ensure they the right way out of many LEDs.
around.

Operating out of sequence


With 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 Afresh
Its 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.
5
CIRCUIT #5

Push Buttons
5 volt
Up until now, we’ve focused solely on outputs.
Now we’re going to go to the other end of spectrum
Resistors (10K ohm) and play around with inputs. In this circuit, we’ll be
(Brown-Black-Orange) looking at one of the most common and simple
PIN 13 RedBoard inputs – a push button. e way a push button works
LED
PIN 3
PIN 2 with RedBoard is that when the button is pushed,
(Light-Emitting Diode)
the voltage goes LOW. e RedBoard reads this and
Buttons
reacts accordingly. In this circuit, you will also use
a pull-up resistor, which keeps the voltage HIGH
Resistors (330 ohm)
(Orange-Orange-Brown) when you're not pressing the button.

GND
(Ground)

PushIC Button LED 10K330 330Wire Wire


PARTS:

Resistor Resistor
X 21 X 18 X 28 X 1 X 7

7 -

1
5
V
IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
SCL
A4 A3 XT
XR AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
~6 7
)(PWM~ 4
ON ~5

~3
1
TX 2
RX
0

p.3610
Circuit 5: Push Buttons

7-15V

IOREF

RESET

3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: How to use logic like a Vulcan:
d4 g4
Push Button One of the things that makes the RedBoard so useful is that it can make complex decisions
d6 g6
based on the input it's getting. For example, you could make a thermostat that turns on a
d9 g9 heater if it gets too cold, a fan if it gets too hot, waters your plants if they get too dry, etc.
Push Button
d11 g11
In order to make such decisions, the Arduino environment provides a set of logic
operations that let you build complex "if" statements. ey include:
LED (5mm) - + h20 h21
-
4 == EQUIVALENCE A == B is true if A and B are the SAME.
10K Resistor i6 +
!= DIFFERENCE A != B is true if A and B are NOT THE SAME.
10K Resistor i11 +
&& AND A && B is true if BOTH A and B are TRUE.

330 Resistor j21


|| OR A || B is true if A or B or BOTH are TRUE.

Jumper Wire 9i !A is TRUE if A is FALSE.


! NOT !A is FALSE if A is TRUE.

Jumper Wire i You can combine these functions to build complex if() statements.
Jumper Wire Pin 2 h6
For example:

Pin 3 if ((mode == heat) && ((temperature < threshold) || (override == true)))


Jumper Wire h11
{
digitalWrite(HEATER, HIGH);
}
Jumper Wire Pin 13 j20
...will turn on a heater if you're in heating mode AND the temperature is low, OR if
you turn on a manual override. Using these logic operators, you can program your
Jumper Wire 5V + RedBoard to make intelligent decisions and take control of the world around it!

Jumper Wire GND


Circuit 2 Arduino Code:

5
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 5

e digital pins can be used as inputs as well as outputs.


pinMode(button2Pin, INPUT); Before you do either, you need to tell the RedBoard
which direction you're going.

To read a digital input, you use the digitalRead()


button1State = digitalRead(button1Pin); function. It will return HIGH if there's 5V present at the
pin, or LOW if there's 0V present at the pin.

Because we've connected the button to GND, it will read LOW when
if (button1State == LOW) it's being pressed. Here we're using the "equivalence" operator ("==")
to see if the button is being pressed.

What You Should See:

You should see the LED turn on if 7


-

15V
you press either button, and o if
you press both buttons. (See the IOREF
3. RESET

code to nd out why!) If it isn't GND


5V 3V

VIN POWER RESET


working, make sure you have A0 GND
A1

assembled the circuit correctly and A5


A4 A3
A2
ANALOG

XT
SCL
13
SDA

veri ed and uploaded the code to


AREF

IN GND
XR

12 13
your board or see the ~11
~10
~9
8
troubleshooting tips below. ISP LDIGITA

~6
7
)(PWM~ 4
ON
~3 ~5
TX
1 2
RX
0

Troubleshooting: Real World Application:

Light Not Turning On e buttons we used here are similar to the buttons in
e pushbutton is square, and because of this it is easy to most video game controllers.
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.
CIRCUIT #6

Photo Resistor
6
5 volt So you’ve already played with a potentiometer, which
varies resistance based on the twisting of a knob. In
PIN 9 this circuit, you’ll be using a photo resistor, which

Photocell changes resistance based on how much light the


LED (Light Sensitive Resistor) sensor receives. Since the RedBoard can’t directly

(Light-Emitting Diode) interpret resistance (rather, it reads voltage), we use a


voltage divider to use our photo resistor. is voltage
PIN A0 RedBoard
divider will output a high voltage when it is getting a
Resistor (330 ohm) Resistor (10K ohm) lot of light and a low voltage when it is not.
(Orange-Orange-Brown) (Brown-Black-Orange)

GND
(Ground)

Photo Resistor LED 330 Wire 10K


PARTS:

Resistor Resistor
X 1 X 1 X 1 X 6 X 1

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
XT
SCL
A4 A3
AREF
IN GND
12 13

ISP LDIGITA

~6 7
XR13
)(PWM~ 4
ON
~3 ~5 ~10~11
TX
1 2
RX
0 ~9
8

p.40
Circuit 6 : Photo Resistor

7-15V

IOREF

RESET
3.3V

5V
GND

POW
ER
VIN
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: Measuring resistive sensors:

Photo Resistor f5 f6
Many of the sensors you'll use (potentiometers, photoresistors, etc.) are
resistors in disguise. eir resistance changes in proportion to whatever they're
LED (5mm) + h20 h21 sensing (light level, temperature, sound, etc.).
-
- e RedBoard's analog input pins measure voltage, not resistance. But we
330 Resistor (sensor) j21 can easily use resistive sensors with the RedBoard by including them as
part of a "voltage divider".
5 volts

1
6
10K Resistor i1 i5 PINin A03
Jumper Wire j

Jumper Wire A0 j5

GND
(ground) (-)

Jumper Wire j + A voltage divider consists of two resistors. e "top" resistor is the sensor you'll be
Jumper Wire Pin 9 j20 using. e "bottom" one is a normal, xed resistor. When you connect the top resistor
to 5 volts, and the bottom resistor to ground. e voltage at the middle will be
proportional to the bottom resistor relative to the total resistance (top resistor +
bottom resistor). When one of the resistors changes (as it will when your sensor
senses things), the output voltage will change as well!
Jumper Wire 5V +
Jumper Wire GND Although the sensor's resistance will vary, the resistive sensors (ex sensor light
sensor, softpot, and trimpot) in the SIK are around 10K ohms. We usually want
the xed resistor to be close to this value, so using a 10K resistor is a great choice
for the xed "bottom" resistor. Please note the xed resistor isn't necessarily the
bottom resistor. We do that with the photodiode only so that more
light = more voltage, but it could be ipped and we'd get the opposite response.
Circuit 2 Arduino Code:

6
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 6

lightLevel = map(lightLevel, 0, 1023, 0, 255); When we read an analog signal using analogRead(), it will be a
Parameters number from 0 to 1023. But when we want to drive a PWM pin
map(value, fromLow, fromHigh, toLow, toHigh) using analogWrite(), it wants a number from 0 to
value: the number to map 255. We can "squeeze" the larger range into the smaller
fromLow: the lower bound of the value's current range
range using the map() function.
fromHigh: the upper bound of the value's current range
toLow: the lower bound of the value's target range See http://arduino.cc/en/reference/map for more info.
toHigh: the upper bound of the value's target range

lightLevel = constrain(lightLevel, 0, 255); Because map() could still return numbers outside the
Parameters "to" range, we'll also use a function called constrain()
constrain(x, a, b) that will "clip" numbers into a range. If the number is
x:the number to constrain, all data types outside the range, it will make it the largest or smallest
a:the lower end of the range, all data types number. If it is within the range, it will stay the same.
b: the upper end of the range, all data types
See http://arduino.cc/en/reference/constrain for more info.

What You Should See:

You should see the LED grow brighter


7
or dimmer in accordance with how
-

15V

much light your photoresistor is reading.


IOREF

If it isn't working, make sure you have 5V


3. RESET
3V
GND
POWER

assembled the circuit correctly and veri VINGND RESET

A0
A1
ed and uploaded the code to your board A5
A2
ANALOG
SDASCL
AREF
A4 A3 XT
XR GND
or see the troubleshooting tips below. IN
13 13
12
~11
~10
~9
ISP LDIGITA 8
7
~6
)(PWM~4

ON
~3 ~5
TX 2
RX 1
0

Troubleshooting: Real World Application:

LED Remains Dark A street lamp uses a light sensor to detect when to turn
is is a mistake we continue to make time and time the lights on at night.
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 Light


Given 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 Working


You 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.
7
CIRCUIT #7

Temperature Sensor
5 volt
A temperature sensor is exactly what it sounds like – a
TMP36 sensor used to measure ambient temperature. is
(Precision Temperature Sensor) particular sensor has three pins – a positive, a ground,
and a signal. is is a linear temperature sensor. A change
1 VCC in temperature of one degree centigrade is equal to a
2 change of 10 millivolts at the sensor output. e TMP36
VOUT PIN A0
3 sensor has a nominal 750 mV at 25°C (about room
GND RedBoard 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.

GND
(Ground) 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.

Temp. Sensor Wire


PARTS:

X 1 X 5 GND
SIGNAL
+V

FRONT

+V
SIGNAL

GND

BACK

7
-

1
5
V
IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A5 A2
ANALOG
SCL
A4 A3 XT SDA
XR AREF
IN GND
13
12 13
~11
~10
~9
ISP LDIGITA 8
7
~6
)(PWM~ 4
ON ~5

~3
TX
1 2
RX
0

p.44
Circuit 7: Temperature Sensor

abcde f g h i
1 1
2 2
3 3
4 4

RESE
5 5
6 6

T
7 7
7-15V 8 8
9 9
10 10
SCL
11 11
SDA
12 12
AREF
13 13
GND
14 14
13
15 15
IOREF
12
16 16
RESET
~11
17 17
3.3V
~10
5V 18 18
~9
3
1
X
R
X
T
POWE

GND 19 19
8
DIGITA

VIN
R

GND 20 20
7 21 21
L

~6 22 22
ANALOG

~5
(PWM~

23 23
A1 4 24 24
)

A4
A2 ~3 25 25
A3 2 26 26
TX 1 27 27
RX 0 28 28
IN

A5
ISP

29 29
N
O

30 30
abcde f g h i
0
Component: Image Reference: Opening your serial monitor:

Temperature Sensor

Jumper Wire

Jumper Wire

Jumper Wire

Jumper Wire

Jumper Wire
0
7
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 7
Arduino Code:

Before using the serial monitor, you must call Serial.begin() to


Serial.begin(9600); 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.

e Serial.print() command is very smart. It can print out almost


Serial.print(degreesC); 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() will print everything on the same line. Serial.println() will


Serial.println(degreesF); move to the next line. By using both of these commands
together, you can create easy-to-read printouts of text and data.

What You Should See:


You should be able to read the
temperature your temperature
sensor is detecting on the serial
voltage: 0.73 deg C: 23.24 deg F: 73.84
monitor in the Arduino IDE. If it voltage: 0.73 deg C: 23.24 deg F:-73.84 7

15V
isn't working, make sure you have voltage: 0.73 deg C: 23.24 deg F: 73.84
assembled the circuit correctly voltage:
voltage :
0.73 0.73
deg C:
deg C: 3.
22.75 deg F: 72.96
23.24RESET deg F: 7 3.84

IOREF

and veri ed and uploaded the code voltage: 0.73 degGNDC:

5V
3V
23.24
deg F: 73.84
voltage: 0.73 degPOWERC:
23.24 deg F: 73.84
to your board or see the voltage:A2 0.73 A1
VIN
deg C:
GND
22.75 deg F: 72
RESET

troubleshoot-ing tips below. voltage:


A5 ANALOG
A0

0.73
deg C: 23.24 deg F: 73
A3 XT AREF

voltage:
A4 0.73 deg C: 22.75 deg F: 72.96 XR GND
IN 13 13
12
voltage: 0.73 deg C: 22.75 deg F: 72.96 ~11
~10
voltage: 0.73 deg C: 23.24 deg F: 73.84 ISP
8
~9

voltage: 0.73 deg C: 22.75 deg F: 7 2.96


LDIGITA
7

)(PWM~ 4 ~6
ON ~5

voltage: 0.73 deg C: 23.24 deg~3F: 73.84


TX 2
RX 1
0

Troubleshooting: Real World Application:

Nothing Seems to Happen Building climate control systems use a temperature sensor
is program has no outward indication it is working. To to monitor and maintain their settings.
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.
CIRCUIT #8

8
ircuit 2

A Single Servo
Servos are ideal for embedded electronics applications
No junction dot means no connection because they do one thing very well that motors cannot –
5 volt 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
SIG PIN 9
milliseconds will move the servo 90 degrees. In this circuit,
you’ll learn how to use PWM (pulse width modulation)

W
R
RedBoard to control and rotate a servo.
V+ B

GND

GND
(Ground)

Servo Wire
PARTS:

X 1 X 8

7 -

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A5
A2
ANALOG
SCL
A4 A3 XT
SDA
XR
AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
~6 7
)(PWM~ 4
ON ~5

~3
TX
1 2
RX
0

p.48
Circuit 8: A Single Servo

7-15V

IOREF

RESET
3.3V
5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: Expand your horizons using Libraries:

Servo e5 e6 e7 e Arduino development environment gives you a very useful set of built-in
commands for doing basic input and output, making decisions using logic, solving
math problems, etc. But the real power of Arduino is the huge community using it
and their willingness to share their work.
Jumper Wire e5
Libraries are collections of new commands that have been packaged together to make
it easy to include them in your sketches. Arduino comes with a handful of useful
libraries, such as the servo library used in this example, that can be used to interface
Jumper Wire e6
to more advanced devices (LCD displays, stepper motors, ethernet ports, etc.)
See http: //arduino.cc/en/reference/libraries for a list of the standard
Jumper Wire e7 libraries and information on using them.
But anyone can create a library, and if you want to use a new sensor or output
device, chances are that someone out there has already written one that interfaces
Jumper Wire Pin 9 a7 that device to the RedBoard. Many of SparkFun's products come with Arduino
libraries, and you can nd even more using Google and the Arduino Playground at
http://arduino.cc/playground/. When YOU get the RedBoard working with a new
device, consider making a library for it and sharing it with the world!
Jumper Wire b5
To use a library in a sketch, select it from Sketch > Import Library.

Jumper Wire a6 + File Edit Sketch Tools Help

Verify / Compile

Jumper Wire 5V + Show Sketch Folder


Add File...
Import Library EEPROM
Jumper Wire GND Ethernet
Firmata
LiquidCrystal
SD
Servo
SoftwareSerial
SPI
Stepper
Wire

After importing the library into your code, you will have access to a number of pre-written
commands and functions. More information on how to use the standard library functions
can be accessed at: http://arduino.cc/en/Reference/Libraries.
8
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 8
Arduino Code:

#include is a special "preprocessor" command that inserts a library (or any


#include <Servo.h> other le) into your sketch. You can type this command yourself, or
choose an installed library from the "sketch / import library" menu.

Servo servo1; 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
servo1.attach(9); 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).

e servos in this kit don't spin all the way around, but they can be commanded
servo1.write(180); to move to a speci c position. We use the servo library's write() command to
move a servo to a speci ed number of degrees(0 to 180). Remember that the
servo requires time to move, so give it a short delay() if necessary.

What You Should See:


LITA
7
ON ~6
)(PWM~ ~5
You should see your servo motor move ~3 4
to various locations at several speeds. If RX TX
1 2
0
the motor doesn't move, check your
connections and make sure you have
veri ed and uploaded the code, or see
the troubleshooting tips below.

Troubleshooting: Real World Application:

Servo Not Twisting Robotic arms you might see in an assembly line or sci-
Even with colored wires it is still shockingly easy to plug a movie probably have servos in them.
servo in backward. is might be the case.

Still Not Working


A 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 Starts


If 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.
CIRCUIT #9

Flex Sensor
9
In this circuit, we will use a ex sensor to measure,
5 volt 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
Resistor (10K ohm) change it by exing (bending) the component. We
(Brown-Black-Orange) use a "voltage divider" again to detect this change in
SIG W PIN 9 PIN A0 resistance. e sensor bends in one direction and the

V+ R

more it bends, the higher the resistance gets; it has a


RedBoard
B

GND
range from about 10K ohm to 35K ohm. In this
Flex Sensor
circuit we will use the amount of bend of the ex
sensor to control the position of a servo.
GND
(Ground)

PotentiometerIC ServoLED 330 10K Wire


Flex Sensor
PARTS:

ResistorResistor
X X 1 1 X 8 X1 X 8X1 X 11

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND
A0
A1
A2
A5 ANALOG

A4 A3 XT

RX
IN GND
12 13

ISP

ON )(PWM~
~3
TX
1 2
RX
0

p. 5210
Circuit 9: Flex Sensor

7-15V

IOREF

RESET

3.3V

5V
GND

POW
ER
VIN
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: Debugging your sketches using the Serial Monitor:

Servo e1 e2 e3
It happens to everyone - you write a sketch which successfully compiles and
uploads, but you can't gure out why it's not doing what you want it to. Larger
Jumper Wire e1 computers have screens, keyboards, and mice that you can use to debug your
code, but tiny computers like the RedBoard have no such things.

Jumper Wire e2 e key to visibility into a microcontroller is output. is can be almost anything,
including LEDs and buzzers, but one of the most useful tools is the serial monitor.
Using Serial.print() and println(), you can easily output human-readable text and
Jumper Wire e3
data from the RedBoard to a window back on the host computer. is is great for
your sketch's nal output, but it's also incredibly useful for debugging.
Flex Sensor h19 h20

19

i
Circuit 2 Arduino Code:

9
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 9

Because the ex sensor / resistor combination won't give us a


servoposition = map(flexposition, 600, 900, 0, 180); full 0 to 5 volt range, we're using the map() function as a
map(value, fromLow, fromHigh, toLow, toHigh) handy way to reduce that range. Here we've told it to only
expect values from 600 to 900, rather than 0 to 1023.

Because map() could still return numbers outside the


servoposition = constrain(servoposition, 0, 180); "to" range, we'll also use a function called constrain()
constrain(x, a, b) 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.

What You Should See:

You should see the servo motor move IOREF


3. RESET
5V 3V

in accordance with how much you are POWER

VIN GND
GND

exing the ex sensor. If it isn't working, A5


A2
ANALOG
A1
A0

make sure you have assembled the A4 A3

IN
XT

RX
13
circuit correctly and veri ed and 12

uploaded the code to your board or see ISP

the troubleshooting tips below. ON

TX 2
RX 1
0

Troubleshooting: Real World Application:

Servo Not Twisting Controller accessories for video game consoles like
Even with colored wires it is still shockingly easy to plug a Nintendo’s “Power Glove” use ex-sensing technology. It
servo in backwards. is might be the case. was the rst video game controller attempting to mimic
hand movement on a screen in real time.
Servo Not Moving as Expected
e sensor is only designed to work in one direction. Try
exing it the other way (where the striped side faces
out on a convex curve).

Servo Doesn’t Move very Far


You need to modify the range of values in the call to the
map() function.
CIRCUIT #10

Soft Potentiometer 10
RedBoard
PIN 11
In this circuit, we are going to use yet another kind
of variable resistor – this time, a soft potentiometer
PIN 10
5 volt (or soft pot). is is a thin and exible strip that can
PIN 9 detect where pressure is being applied. By pressing
Resistors (330 ohm) down on various parts of the strip, you can vary the
RedBoard Soft Pot (Orange-Orange-Brown) resistance from 100 to 10K ohms. You can use this
PIN A0 ability to track movement on the soft pot, or simply
as a button. In this circuit, we’ll get the soft pot up
Resistor (10K ohm)
(Brown-Black-Orange) LED and running to control an RGB LED.
BLUE

GREE
RED

(Light-Emitting Diode)
N

GND
(Ground)

ICLED 330Soft PotentiometerLED Wire330 330 10K


PARTS:

Resistor Resistor Resistor


X 1 X 1 X 138 X 9 X 8 X 3 X 1

7-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2 SCL
A5 ANALOG

A4 A3
XR GND
IN
13 13
12
~11
~10
~9
ISP 8
~6 7
ON ~5
~3 4
RX 2

p.5610
Circuit 10: Soft Potentiometer

abcde f g h i
1 1
2 2
3 3
4 4

RESE
5 5
6 6

T
7 7
7-15V 8 8
9 9
10 10
SCL
11 11
SDA
12 12
AREF
13 13
GND
14 14
13
15 15
IOREF
12 16 16
RESET
~11 17 17
3.3V
~10 18
5V
~9
3
1
X
R
X
T

19
POWE

GND
8
DIGITA

VIN
R

GND 20
7 21 21
L

~6 22 22
ANALOG

~5
(PWM~

23 23
A1 4 24 24
)

A4
A2 ~3 25 25
A3 2 26 26
TX 1 27 27
RX 0 28 28
IN

A5
ISP

29 29
N
O

30 30
abcde f g h i
0
Component: Image Reference: Component: Image Reference:

a4 a5 a6 a7
RGB LED (5mm)
Jumper Wire 5V +
Soft Potentiometer 5V h18 h19 h20 Jumper Wire GND

330 Resistor e4 g4
80
2
330 Resistor e6 g6

330 Resistor e7 g7

10K Resistor i19

Jumper Wire Pin 9 5h4

Jumper Wire e
Jumper Wire Pin 10 h6

Jumper Wire Pin 11 1h7

Jumper Wire j +
Jumper Wire A0 j19

Jumper Wire j
Circuit 2 Arduino Code:

10
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 10

These big, scary functions take a


redValue = constrain(map(RGBposition, 0, 341, 255, 0), 0, 255) single Value (RGBposition) and
calculate the three RGB values
+ constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255); necessary to create a rainbow of
color. The functions create three
"peaks" for the red, green, and blue
greenValue = constrain(map(RGBposition, 0, 341, 0, 255), 0, 255) values, which overlap to mix and
create new colors. See the code for
- constrain(map(RGBposition, 341, 682, 0,255), 0, 255); more information! Even if you're not
100% clear how it works, you can
copy and paste this (or any) function
blueValue = constrain(map(RGBposition, 341, 682, 0, 255), 0, 255) into your own code and use it
yourself. If you want to know more
- constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255); about creating your own functions -
take a look at circuit #11.

What You Should See:

You should see the RGB LED change


colors in accordance with how you
interact with the soft potentiometer.
7
If it isn't working, make sure you -

15V

have assembled the circuit correctly


and veri ed and uploaded the code to
IOREF
your board, or see the 5V
3
3V
. RESET

troubleshooting tips below. GND


POWER

VIN GND RESET

A0
A1

A5 A2
ANALOG

A4 A3 SDA
IN 13
13
~11 12
~10
ISP ~9
8
7
ON ~6
~5
4
TX
RX
0

Troubleshooting: Real World Application:

LED Remains Dark or Shows Incorrect Color e knobs found on many objects, like a radio
With the four pins of the LED so close together, it’s for instance, are using similar concepts to the
sometimes easy to misplace one. Try double one you just completed for this circuit.
checking each pin is where it should be.

Bizarre Results
e most likely cause of this is if you’re pressing the
potentiometer in more than one position. is is normal
and can actually be used to create some neat results.
CIRCUIT #11

Buzzer
11
In this circuit, we'll again bridge the gap between the
Piezo Buzzer digital world and the analog world. We'll be using a
buzzer that makes a small "click" when you apply
voltage to it (try it!). By itself that isn't terribly
exciting, but if you turn the voltage on and o
hundreds of times a second, the buzzer will produce a
RedBoard tone. And if you string a bunch of tones together,
PIN 9 you've got music! is circuit and sketch will play a
classic tune. We'll never let you down!
GND
(Ground)

Piezo Element Wire


PARTS:

X 1 X 3

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A5 A2
ANALOG
SCL
A4 A3 XT
SDA
XR
AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
7
~6
)(PWM~ 4
ON
~3 ~5
TX
1 2
RX
0

If the buzzer doesn't easily fit

into the holes on the breadboard,


try rotating it slightly.

p.60
Circuit 11: Piezo Elements

7-15V

IOREF
RESET
3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Component: Image Reference: Creating your own functions:

Piezo Element f9 f7 Arduino contains a wealth of built-in functions that are useful for all kinds of things.
+ - (See http://arduino.cc/en/reference for a list). But you can also easily create your
own functions. First, we need to declare a function. Here's a simple example named
Jumper Wire i7
"add," which adds two numbers together and returns the result. Let's break it down.

Jumper Wire Pin 9 j9


int add(int parameter1, int parameter2)
{
int x;
Jumper Wire GND
x = parameter1 + parameter2;

return(x);
}

Your functions can take in values ("parameters"), and return a value, as this one does.

If you'll be passing parameters to your function, put them (and their types) in
the parentheses after the function name. If your function is not using any
parameters, just use an empty parenthesis () after the name.

If your function is returning a value from your function, put the type of the
return value in front of the function name. en in your function, when you're
ready to return the value, put in a return(value) statement. If you won't be
returning a value, put "void" in front of the function name (similar to the
declaration for the setup() and loop() functions).

When you write your own functions, you make your code neater and easier to
re-use. See http://arduino.cc/en/reference/functiondeclaration for more
infomation about functions.
Circuit 2 Arduino Code:

11
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 11

Up until now we've been working solely with numerical


char notes[] = "cdfda ag cdfdg gf "; data, but the Arduino can also work with text. Characters
(single, printable, letters, numbers and other symbols) have
char names[] = {'c','d','e','f','g','a','b','C'}; their own type, called "char". When you have an array of
characters, it can be de ned between double-quotes (also
called a "string"), OR as a list of single-quoted characters.

One of Arduino's many useful built-in commands is the tone()


function. is function drives an output pin at a certain
frequency, making it perfect for driving buzzers and speakers. If
tone(pin, frequency, duration); you give it a duration (in milliseconds), it will play the tone then
stop. If you don't give it a duration, it will keep playing the tone
forever (but you can stop it with another function, noTone() ).

What You Should See:


7 -

15V

You should see - well, nothing!


But you should be able to hear IOREF
3. RESET
5V 3V
a song. If it isn't working, GND
POWER

VIN GND
make sure you have assembled A1
A0
RESET

A2
the circuit correctly and veri ed A5
A4
ANALOG

A3 XT AREF
SCL

XR GND

and uploaded the code to your IN


13

12
13

~11
board or see the ~9
~10

ISP LDIGITA 8
troubleshooting tips below. )(PWM~ 4 ~6
7
ON ~5

~3
RX
TX
1 2
0

Troubleshooting: Real World Application:

No Sound Many modern megaphones have settings that use a


Given the size and shape of the piezo element it is loud ampli ed buzzer. ey are usually very loud and
easy to miss the right holes on the breadboard. Try quite good at getting people’s attention.
double checking its placement.

Can't ink While the Melody is Playing


Just pull up the piezo element whilst you think,
upload your program then plug it back in.

Feeling Let Down and Deserted


e code is written so you can easily add your own songs.
CIRCUIT #12

12
ircuit 2

Spinning a Motor
5 volt
Remember before when you played around with a servo
motor? Now we are going to tackle spinning a motor.
Diode is requires the use of a transistor, which can switch a
(1N4148) DC Motor larger amount of current than the RedBoard can. When
using a transistor, you just need to make sure its
maximum specs are high enough for your use. e
transistor we are using for this circuit is rated at 40V max
RedBoard and 200 milliamps max – perfect for our toy motor!
Transistor When the motor is spinning and suddenly turned o , the
PIN 9 magnetic eld inside it collapses, generating a voltage
(P2N2222AG)
Resistor (330 ohm) spike. is can damage the transistor. To prevent this, we
(Orange-Orange-Brown) use a " yback diode", which diverts the voltage spike
GND around the transistor.
(Ground) When you’re building the circuit be careful not
to mix up the transistor and the temperature
sensor, they’re almost identical. Look for
“P2N2222A” on the body of the transistor.

Transistor Diode DC Motor Wire 330


PARTS:

P2N2222AG 1N4148 Resistor


X 1 X 1 X 1 X 6 X 1
P2N2222A

EMITTER
BASE
COLLECTOR

FRONT

COLLECTOR
BASE
EMITTER

BACK
7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
SCL
A4 A3 XT
XR AREF
IN
13
GND
12 13
~11
~10
~9
ISP LDIGITA 8
~6 7
)(PWM~ 4
ON
~3 ~5
1
TX 2
RX
0

p.64
Circuit 12 : Spinning a Motor

abcde f g h i
1 1
2 2
3 3
4 4

RESET
5 5
6 6
7 7
8 8
7-15V
9 9
10 10
SCL 11 11
SDA 12 12
AREF 13 13
GND 14 14
13 15 15
IOREF
12 16 16
RESET
~11 17 17
3.3V
~10 18 18
5V
~9 19 19
3
1
X
R
X
T

GND
POW

8
DIGITA
ER

VIN
GND
20 20
7 21 21
L

~6 22 22
ANALOG

~5 23 23
(PWM

A1 4 24 24
~)

A4
A2 ~3 25 25
A3 2 26 26
TX 1 27 27
RX 0 28 28
IN

A5
ISP

29 29
N
O

30 30
abcde f g h i
0
Component: Image Reference: Putting it all together:
EMITTER

P2N2222A
BASE a1 a2 a3
Transistor P2N2222AG COLLECTOR E B C
At this point you're probably starting to get your own ideas for circuits that do
fun things, or help solve a real problem. Excellent! Here are some tips on
Diode 1N4148 programming in general.
GNDb7 a3b11

Most of the sketches you write will be a loop with some or all of these steps:
DC Motor
e7 e11 1. Perform some sort of input
2. Make some calculations or decisions
330 Resistor 3. Perform some sort of output
e2 g2 4. Repeat! (Or not!)

Jumper Wire e1 We've already shown you how to use a bunch of erentdi input sensors and output
devices (and we still have a few more to go). Feel free to make use of the examples
in your own sketches - this is the whole idea behind the "Open Source" movement.
Jumper Wire
Pin 9 j2
It's usually pretty easy to pull pieces of erentdi sketches together, just open them in
two windows, and copy and paste between them. is is one of the reasons we've been
Jumper Wire a7 + promoting "good programming habits". ings like using constants for pin numbers,
and breaking your sketch into functions, make it much easier to re-use your code in
new sketches. For example, if you pull in two pieces of code that use the same pin,
Jumper Wire e3 d11
you can easily change one of the constants to a new pin. (Don't forget that not all of
the pins support analogWrite(); the compatible pins are marked on your board.)

Jumper Wire 5V + If you need help, there are internet forums where you can ask questions. Try
Arduino's forum at arduino.cc/forum, and SparkFun's at forum.sparkfun.com.
When you're ready to move to more advanced topics, take a look at Arduino's
Jumper Wire GND tutorials page at arduino.cc/en/tutorial. Many of SparkFun's more advanced
products were programmed with Arduino, (allowing you to easily modify them), or
have Arduino examples for them. See our product pages for info.

Finally, when you create something really cool, consider sharing it with the
world so that others can learn from your genius. Be sure to let us know on
https://www.sparkfun.com/project_calls so we can put it on our home page!
12
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 12
Arduino Code:

e RedBoard's serial port can be used to receive as well as send data.


Because data could arrive at any time, the RedBoard stores, or
while (Serial.available() > 0) "bu ers" data coming into the port until you're ready to use it. e
Serial.available() command returns the number of characters that the
port has received, but haven't been used by your sketch yet. Zero
means no data has arrived.

If the port has data waiting for you, there are a number of ways for
you to use it. Since we're typing numbers into the port, we can
speed = Serial.parseInt(); use the handy Serial.parseInt() command to extract, or "parse"
integer numbers from the characters it's received. If you type "1"
"0" "0" to the port, this function will return the number 100.

What You Should See:


VIN WER

A0

A1
A2

e DC Motor should spin if you have A5 ET


ANALOG SDASCL
XT
A4 A3 AREF
XR13

assembled the circuit’s components


IN
13
12
~11
~10

correctly, and also veri ed/uploaded the ISP LDIGITA7


8
~9

correct code. If your circuit is not working


ON
)(PWM~ 4 ~6
~5

RX
~3
check the troubleshooting section below. 1 2
TX
0

Troubleshooting: Real World Application:

Motor Not Spinning Radio Controlled(RC) cars use Direct Current(DC)


If you sourced your own transistor, double check with motors to turn the wheels for propulsion.
the data sheet that the pinout is compatible with a
P2N2222AG (many are reversed).

Still No Luck
If you sourced your own motor, double check that it will
work with 5 volts and that it does not draw too much
power.

Still Not Working


Sometimes the RedBoard will disconnect from the
computer. Try un-plugging and then re-plugging it into
your USB port.
Relays
CIRCUIT #13

5 volt
1
3
Resistor (330 ohm)
(Orange-Orange-Brown)

Diode
(1N4148)

SPDT Relay
RedBoard Transistor
PIN 2
(P2N2222AG)
In this circuit, we are going to use some of the lessons we
Resistor (330 ohm) learned in circuit 12 to control a relay. A relay is basically
(Orange-Orange-Brown)
an electrically controlled mechanical switch. Inside that
GND
(Ground) harmless looking plastic box is an electromagnet that, when
it gets a jolt of energy, causes a switch to trip. In this
circuit, you’ll learn how to control a relay like a pro –
giving your RedBoard even more powerful abilities!
LEDs
(Light-Emitting Diodes)

RelayIC
PAR

TransistorLED
TS:

When the relay is o , the COM (common)


P2N2222AG
pin will be connected to the NC (Normally
X 1 Closed) pin. When the relay is on, the COM
(common) pin will be connected to the NO
(Normally Open) pin.

Diode 330 LED Wire


1N4148 Resistor
X 1 X 1 X 2 X 2 X 14

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A5 A2
ANALOG XR
SCL
A4 A3 XT
AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
7
)(PWM~ 4 ~6
ON
~3 ~5
TX
1 2
RX
0
p.6810
Circuit 13: Relays

7-15V

IOREF

RESET

3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
2 1

Component: Image Reference:

e14 e9
Relay
f15f13 f9

EMITTER

P2N2222A
BASE a2 a3 a4
Transistor P2N2222AG COLLECTOR E B C

29
LED (5mm) + c19 c20

LED (5mm) 4 9
19
0
Diode 1N4148

330 Resistor

330 Resistor

i e Component: Image Reference:


Jumper Wire
- 1i e1
P2 j7 j j9
Jumper Wire
Jumper Wire 53 -
1h9 2+
in e 3
Jumper Wire + 2 c23
- - Jumper Wire + e+
GND e7 a3f7 Jumper Wire a23
Jumper Wire 5V e3 g3
b14 +
Jumper Wire a e+
Jumper Wire

Jumper Wire a7 a9
Jumper Wire
Jumper Wire e b

Jumper Wire 5V +
Jumper Wire GND
Circuit 2 Arduino Code:

13
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 13

When we turn on the transistor, which in turn energizes the


relay's coil, the relay's switch contacts are closed. is connects the
digitalWrite(relayPin, HIGH); relay's COM pin to the NO (Normally Open) pin. Whatever
you've connected using these pins will turn on. (Here we're using
LEDs, but this could be almost anything.)

e relay has an additional contact called NC (Normally Closed).


e NC pin is connected to the COM pin when the relay is OFF.
digitalWrite(relayPin, LOW); You can use either pin depending on whether something should be
normally on or normally o . You can also use both pins to
alternate power to two devices, much like railroad crossing
warning lights.

What You Should See:

You should be able to hear the


R IOREF
relay contacts click, and see the two 5 3.
3V
ESET

GN V
GN D P
LEDs alternate illuminating at 1- V
OWE

IN R
RESET

A
second intervals. If you don't, A
1
0
A2 SCL
A A SDA

double-check that you have 5


A A4
3
ALOG
N
XT

XR
31
AREF

IN
assembled the circuit correctly, and 13

~1112
uploaded the correct sketch to the ~10
~9
ISP LDIGITA 8
board. Also, see the troubleshooting ~6
7
)(PWM~~5
tips below. ON

TX
~3 4
RX
1 2
0

Troubleshooting: Real World Application:


LEDs Not Lighting Garage door openers use relays to operate. You might
Double-check that you've plugged them in be able to hear the clicking if you listen closely.
correctly. e longer lead (and non- at edge of the
plastic ange) is the positive lead.
No Clicking Sound
e transistor or coil portion of the circuit isn't quite
working. Check the transistor is plugged in the right way.

Not Quite Working


e included relays are designed to be soldered rather than
used in a breadboard. As such you may need to press it in
to ensure it works (and it may pop out occasionally).
When you’re building the circuit be careful not to mix
up the temperature sensor and the transistor, they’re
almost identical.
14
CIRCUIT #14

Shift Register
5 volt Now we are going to step into the world of ICs (integrated
circuits). In this circuit, you’ll learn all about using a shift
Resistors (330 ohm)
PIN 2
14
11
SER VCC 16
1
(Orange-Orange-Brown) register (also called a serial-to-parallel converter). e shift
regis ter will give yo ur RedBoard an additio nal eight outpu ts ,

15
RedBoard

QA
PIN 3 SCK QB 3 using only three pins on your board. For this circuit, you’ll
10 SCL QC 2
PIN 4 RCK QD
QE
5 practice by using the shift register to control eight LEDs.
12 4
QF
13 6
OE QG
7
QH
8 9
GND QH*
LEDs
74HC595 (Light-Emitting Diodes)

GND
*Do not connect pin 9
(Ground) VCC
QB 1 16
QC 2 15 QA
QD 3 14 SER
QE 4 13 OE
QF 5 12 RCLK
QG 6 11 SRCLK
QH 7 10 SRCLR
QH’
GND 8 9
PARTS:

IC LED 330 Wire


Align notch on top,
Resistor inbetween “e5” and “f5” on
X 1 X 8 X 8 X 19 the breadboard. The notch
indicates where pin 1 is.

Bend legs to 90° angle.

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG
SCL
A4 A3 XT
XR AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8
~6 7
)(PWM~ 4
ON
~3 ~5
1
TX 2
RX
0

p.72
Circuit 14: Shift Register

7-15V

IOREF

RESET
3.3V
5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
Image Reference: Image Reference:
e e Component:
e e e e e 1 1
5 6 7 8 9 0 1 e12
IC f5 f6 f7 f8 f9 f10 f11 f12 Jumper Wire
Component:

LED - c14 c15


(5mm)
+ j5 +
+ - Jumper Wire
LED c17 c18 Jumper 6j
- + a14
(5mm) + - Wire
LED c20 c21 Jumper
(5mm)
- + Pin 2 j7
+ - Wire
LED c23 c24 Jumper
(5mm) - + j8
+ - Wire
LED h14 h15 Jumper
(5mm) - + Wire Pin 4 j9
+ -
LED h17 h18 Jumper
(5mm)
- + Pin 3 j10
+ - Wire
LED h20 h21 Jumper
(5mm) - + +j11
+ - Wire f14
LED Jumper
(5mm) h23 h24 a8
- + + - Wire
Jumper
330 Resistor a3a15 Wire f17f a9a
Jumper 2 1
330 Resistor a18 Wire 20 a0
Jumper 3 1
330 Resistor a3a21 Wire f 1
Jumper a2 a
330 Resistor a3a24 Wire 3 7
Jumper 20 a
330 Resistor j15 Wire a 6
j1 Jumper
330 Resistor 8 Wire 1
21 Jumper 5 7 a
330 Resistor j Wire Va 5 +
j2 Jumper GND
330 Resistor 4 Wire
+ +
Jumper Wire
14
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 14
Arduino Code:

You'll communicate with the shift register (and a lot of other parts) using an
interface called SPI, or Serial Peripheral Interface. is interface uses a
data

shiftOut(datapin, clockpin, MSBFIRST, data); line and a separate clock line that work together to move
data in or out of the RedBoard at high speed. e MSBFIRST parameter
speci es the order

in which to send the individual bits, in this case we're sending the Most
Signi cant Bit rst.

Bits are the smallest possible piece of memory in a computer; each


one can store either a "1" or a "0". Larger numbers are stored as
arrays of bits.

bitWrite(data, desiredPin, desiredState); Sometimes we want to manipulate these bits directly, for example
now when we're sending eight bits to the shift register and we want to make them 1 or 0
to turn the LEDs on or o . e RedBoard has several commands, such as
bitWrite(), that make this easy to do.

What You Should See:


IOREF
3. RESET
You should see the LEDs light up GND
5V 3V

POWER

similarly to circuit 4 (but this time, VIN GND RESET

A0

you're using a shift register). If A5 A2


A1

ANALOG
SCL
A4 A3
they aren't, make sure you have XT
XR
SDA
AREF
IN 13 GND
assembled the circuit correctly and ~11
12 13
~10
veri ed and uploaded the code to ~9
ISP LDIGITA 8
your board. See the 7
~6
ON )(PWM~ ~5
troubleshooting tips below. ~3 4
RX
TX
1 2
0

Troubleshooting: Real World Application:

e RedBoard's power LED goes out Similar to circuit #4, a scrolling marquee display delivers
is happened to us a couple of times, it happens when a message with multiple LEDs. Essentially the same task
the chip is inserted backward. If you x it quickly the shift register achieves here in Circuit #14.
nothing will break.

Not Quite Working


Sorry to sound like a broken record but it is probably
something as simple as a crossed wire.

Frustration
Shoot us an e-mail, this circuit is both simple and
complex at the same time. We want to hear about
problems you have so we can address them in future
editions: [email protected]
W
O
D
D

D
V
S
S
V

A
K
0

7
/
CIRCUIT #15
LCD 15
In this circuit, you’ll learn about how to use an LCD.
16x2 LCD An LCD, or liquid crystal display, is a simple screen
that can display commands, bits of information, or
readings from your sensor - all depending on how you
5 volt
program your board. In this circuit, you’ll learn the
basics of incorporating an LCD into your project.

dB
Re

oa
PIN 2

rd
PIN 3
PIN 4
PIN 5

PIN 11
PIN 12

GND
(Ground)

LEDPotentiometer330Wir
PARTS:

ICLCD e Wire
Resistor 19
X

X 1 X 1 X 168

7
-

15V

IOREF
3. RESET
5V 3V
GND
POWER

VIN GND RESET

A0
A1
A2
A5 ANALOG XR
SCL
A4 A3 XT
AREF
IN 13 GND
12 13
~11
~10
~9
ISP LDIGITA 8

)(PWM~ 4 ~6 7
ON
~3 ~5

RX
TX
1 2
0

p.76
Circuit 15: LCD

7-15V

IOREF

RESET

3.3V

5V

POWE
GND
VIN

R
GND

ANALOG
A1
A4
A2
A3

IN
A5
0
9

Component: Image Reference:

Component: Image Reference:

in 19
f

P 2
f
LCD
Jumper Wire
Potentiometer
Jumper Wire
Jumper Wire
Jumper Wire j30
j29
Jumper Wire Pin 3 f18
j28
Jumper Wire
j27
Jumper Wire 4
j26
Jumper Wire
j25
Jumper Wire Pin 5 f20

Jumper Wire aa 3
j24 3 Jumper Wire Pin 11 f25
j23
16

Jumper Wire fj22 Jumper Wire f26


j20

j19
Jumper Wire Pin 12 f27
j18

j17
Jumper Wire +
j16

j15
Jumper Wire f30

b8
b7
b6

5V j10+

GND

GNDe6 a3+

GND e7 f28a3

GNDe8

GNDf15 a3

GND +

Pin 2 0jf17
Circuit 2 Arduino Code:

15
Code to Note:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 15

is bit of code tells your Arduino IDE to include the library for a
#include <LiquidCrystal.h> simple LCD display. Without it, none of the commands will
work, so make sure you include it!

is is the rst time you’ll re something up on your screen. You


lcd.print(“hello, world!”); may need to adjust the contrast to make it visible. Twist
the potentiometer until you can clearly see the text!

What you Should See:


REF
3. RESET
5V 3V

Initially, you should see the POWER


GND

VIN GND

words “hello, world!” pop up


RESET

A0
A1
A2
on your LCD. Remember A5
A4 A3
ANALOG

XT
SCL
SDA
XR
AREF
you can adjust the contrast IN 13 GND
12 13
~11
using the potentiometer if ~9
~10

you can’t make out the ISP LDIGITA

~6
7
8
)(PWM~ 4
words clearly. If you have ON
~3
~5

any issues, make sure your RX 1 2


TX
0
code is correct and double-
check your connections.

Troubleshooting: Real World Application:

e Screen is Blank or Completely Lit? LCDs are everywhere! From advanced LCDs like
Fiddle with the contrast by twisting the your television, to simple noti cation screens, this is
potentiometer. If it’s incorrectly adjusted, you a very common and useful display!
won’t be able to read the text.

Not Working At All?


Double check the code, speci cally that you
include the LCD library.

Screen Is Flickering
Double check your connections to your
breadboard and Arduino.
Learning More

Visit us Online:
is is just the beginning of your exploration into embedded
electronics and coding. Our website has a wealth of tutorials
to whet your appetite for more knowledge. We also host a
community of hackers, engineers, DIYers, etc. in our forums.
So log on to our website for more information about Arduino,
or to plan ahead for your next project!

sparkfun.com

NOTES:
Begin your Journey The SparkFun Inventor’s Kit
teaches basic programming,
into Electronics for which you will need both a
This kit will guide you through computer and an internet connection.
experiments of varying difficulty
as you learn all about embedded
systems, physical computing,
You will also learn to
programming and more! This kit assemble 15 basic physical
is perfect for anyone who wants electronic circuits, but no
to explore the power of the soldering is required. No previous
RedBoard platform.
experience is necessary!

KIT INCLUDES

SparkFun RedBoard RGB LED Photoresistor 330 ohm resistors


Breadboard Temperature sensor Transistors Piezo buzzer
Instruction booklet DC motor Jumper wires Flex sensor
Sealed relay 8-bit shift register USB cable Soft potentiometer
Small servo Push button switches Signal diodes Baseplate
Yellow and red LEDs Potentiometer 10k ohm resistors LCD

© SparkFun Electronics, inc. All rights reserved. The SparkFun Inventor’s kit for the SparkFun RedBoard features, specifications, system requirements

and availability are subject to change without notice. All other trademarks contained herein are the property of their respective owners.

The SIK Guide for the SparkFun Inventor’s Kit for the SparkFun RedBoard is
licensed under the Creative Commons Attribution Share-Alike 3.0 Unported License

To view a copy of this license visit: http://creativecommons.org/by-sa/3.0/


Or write: Creative Commons, 171 Second Street, Suite 300, San Francisco, CA 94105, USA.

You might also like