SIK Guide
SIK Guide
SIK Guide
RES
Table of Contents
Welcome to the SparkFun Inventors Guide
The SparkFun Inventor's Guide is your map for navigating
the waters of beginning embedded electronics. This
booklet contains all the information you will need to
explore the 14 circuits of the SparkFun Inventor's Kit for
Arduino. 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!
sparkfun.com
Section 1:
Section 2:
Inventory of Parts
11
Arduino Uno
13
Breadboard
15
17
Circuit #2 - Potentiometer
24
28
32
36
40
44
48
52
56
60
64
68
72
What is an Arduino?
The Arduino Revolution
Arduino is an open-source physical computing platform
designed to make experimenting with electronics more
fun and intuitive. Arduino has its own unique, simplified
programming language, a vast support network, and
thousands of potential uses, making it the perfect platform
for both beginner and advanced DIY enthusiasts.
arduino.cc
c
b
f
a
Auto-Coffee Maker
Auto-Plant Watering
Quadcopter
NW
NE
E
SE
SW
arduino.cc/en/Main/Software
Download
Windows
Mac OS
X
Mac OS X
Linux: 32 bit, 64 bit
Linux:source
32 bit, 64 bit
user
Choose the appropriate Operating System installation package for your computer.
2
3
// Install Drivers
Depending on your computers operating system, you will need to follow specific
instructions. Please consult the URLs below for specific instructions on how to
install the drivers onto your Arduino Uno.
* You will need to scroll to the section labeled Install the drivers.
2 Upload: Sends your code to the Arduino board. 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 Arduino 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
Edit
Sketch
Tools
Help
Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor
Board
Serial Port
Programmer
Burn Bootloader
Arduino Uno
Arduino Duemilanove w/ ATmega328]
Arduino Diecimila or Duemilanove w/ ATmega168
Arduino Nano w/ ATmega328
Arduino Nano w/ ATmega168
Arduino Mega 2560 or Mega ADK
Arduino Mega (ATmega1280)
Arduino Mini
Arduino Mini w/ATmega168
Arduino Ethernet
Arduino Fio
Arduino BT w/ ATmega328
Arduino BT w/ATmega168
LilyPad Arduino w/ ATmega328
LilyPad Arduino w/ ATmega168
Arduino Pro or Pro Mini (5V, 16 MHz) w/ATmega328
Arduino Pro or Pro Mini (5V, 16 MHz) w/ATmega168
Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ATmega328
Arduino Pro or Pro Mini (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
Programmer
Burn Bootloader
Tools
com 1
com 12
Help
Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor
Board
Serial Port
Programmer
Burn Bootloader
http://www.arduino.cc/playground/Learning/Linux
/dev/tty.usbmodem262471
/dev/cu.usbmodem262471
/dev/tty.Bluetooth-Modem
/dev/cu.Bluetooth-Modem
/dev/tty.FireFly-7256-SPP
/dev/cu.FireFly-7256-SPP
/dev/tty.tiPhone-WirelessiAP-1
/dev/cu.tiPhone-WirelessiAP-1
/dev/tty.Bluetooth-PDA-Sync
/dev/cu.Bluetooth-PDA-Sync
Download Arduino Code (For use with the circuits in this guide)
5
Type in the following URL to download the code:
sparkfun.com/sikcode
Start
Programs
arduino
examples
Contents
Resources
Java
examples
Arduino
Open
Show Package Contents
Move to Trash
http://www.arduino.cc/playground/Learning/Linux
a b c d e
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
a b c d e
f g h i
f g h 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
Inventory of Parts
LED (5mm)
Jumper Wire
x30
x10
330 Resistor
x25
Various Colors
x10
x1
10K Resistor
* ACTUAL SIZE
Potentiometer
* ACTUAL SIZE
x25
Diode
(1N4148)
x1
* ACTUAL SIZE
x2
Piezo Element
Photo Resistor
x1
x1
Transistor
(TMP36)
P2N2
222A
A18
Temp. Sensor
(P2N2222AG)
FRONT
x1
DC Motor
FRONT
BACK
x2
Push Button
x1
x2
BACK
Flex Sensor
Arduino Board
UNO - SMD
PTH Version
Version
MADE
IN ITALY
x1
AREF
GND
13
12
11
10
TX
RX
Soft Potentiometer
RESET-EN
RESET
3.3V
5V
GND
GND
VIN
POWER
9
8
DIGITAL (PWM )
RESET
Servo
ANALOG IN
x1
A0
A1
A2
A3
A4
A5
6
5
4
3
2
TX
1
0
RX
WWW.ARDUINO.CC
x1
Breadboard
Standard Solderless
x1
a b c d e
Relay
x1
Integrated Circuit
(IC)
x1
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
a b c d e
f g h i
f g h 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
x1
2
1
8
3 4
6
10
7
9
Arduino Uno
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 Arduino is receiving data (such as when being programmed).
4 LED (TX: Transmitting)
- This shows when your Arduino is transmitting data (such as when running a program).
- 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 Arduino is ON) - This is a simple power indicator LED.
8 Reset Button - This is a way to manually reset your Arduino, 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 boot loader.
10 Pins (Analog In, Power In, Ground, Power Out, Reset) - These various pins can be used for inputs, outputs, power, and ground. // See Diagram Below
// 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 Arduino Uno.
SCL
SDA
ARef
RFU
IOREF
Reset
Power Out
Power Out
Ground
Ground
10
Power In
Ground
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Analog
Digital
Analog
Digital
Analog
Digital
Analog
Digital
Analog
TX - Out
Analog
RX - In
a b c d e
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
a b c d e
f g h i
f g h 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
This line divides the board in half, restricting electricity to one half or the other.
Breadboard
1 Vertical Connection (+ Power and - Ground // See Diagram Below)
2 Horizontal Connection (a-e & f-j // See Diagram Below)
Making a Connection:
Above the breadboard
LED
CONNECTED!
a b c d e
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
a b c d e
f g h i
f g h 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
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.
ASSEMBLE
a b c d e
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
a b c d e
WRITE
UPLOAD
f g h i
f g h 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
5V Current Your Arduino runs on five volts. This 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 Arduino board 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 citcuit.
Circuit 2
Pin 13
Blinking a LED
Arduino
LED
(Light Emitting Diode)
Resistor (330ohm)
(Orange-Orange-Brown)
GND
PARTS:
(ground) (-)
LED
330
Resistor
X
Wire
X
a b c d e
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
f g h i
LED:
(-).
Flat Edge
Short Leg
a b c d e
f g h 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
Component:
LED (5mm)
Image Reference:
-
c2 c3
330 Resistor
Jumper Wire
GND
Jumper Wire
5V
Jumper Wire
GND
a3
a3
+
e2
e2
Edit
Sketch
Tools
New
Open...
Sketchbook
Examples
Close
Save
Save As...
Upload
Upload Using Progammer
Page Setup
Print
Help
1.Basics
2.Digital
3.Analog
4.Communication
5.Control
6.Sensors
7.Displays
8.Strings
ArduinoISP
SIK Guide Code
Circuit #1
Circuit #2
Circuit #3
Circuit #4
Circuit #5
Circuit #6
Circuit #7
Circuit #8
Circuit #9
Circuit #10
Circuit #11
Circuit #12
Circuit #13
Circuit #14
EEPROM
Ethernet
Firmata
Liquid Crystal
SD
Servo
SoftwareSerial
SPI
Stepper
Wire
// 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);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
//
//
//
//
This compiles your code. The IDE changes it from text into instructions the computer
can understand.
This sends the instructions via the USB cable to the computer chip on the Arduino board.
The Arduino will then begin running your code automatically.
// The result of a completed circuit with correct code after verified and uploaded.
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 1
Code to Note:
pinMode(13, OUTPUT);
Before you can use one of the Arduino's pins, you need to tell the
Arduino whether it is an INPUT or OUTPUT. We use a built-in
"function" called pinMode() to do this.
digitalWrite(13, HIGH);
Troubleshooting:
Circuit 2
CIRCUIT
#5
#2
Potentiometer
+5 Volts
Pin 13
Arduino
Potentiometer
Arduino
Pin A
LED
resistor
(330ohm)
(Orange-Orange-Brown)
GND
PARTS:
(ground) (-)
IC
Potentiometer
LED
X
330
Resistor
X
18
Wire
X
18
19
6
p.24
p.10
Circuit 2: Potentiometer
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
a6
Potentiometer
a7
If you look closely at your Arduino, you'll see some pins labeled "DIGITAL",
and some labeled "ANALOG". What's the difference?
a8
LED (5mm)
h20 h21
330 Resistor
i21
Jumper Wire
e6
Jumper Wire
A0
Jumper Wire
Many of the devices you'll interface to, such as LEDs and pushbuttons, have
only two possible states: on and off, or as they're known to the Arduino,
"HIGH" (5 Volts) and "LOW" (0 Volts). The digital pins on an Arduino are
great at getting these signals to and from the outside world, and can even do
tricks like simulated dimming (by blinking on and off really fast), and serial
communications (transferring data to another device by encoding it as patterns
of HIGH and LOW).
e7
+
e8
Jumper Wire
5V
j20
Jumper Wire
GND
5V
Jumper Wire
GND
DIGITAL
LOW
HIGH
off
on
0 volts
5 volts
But there are also a lot of things out there that aren't just "on" or "off".
Temperature levels, control knobs, etc. all have a continuous range of values
between HIGH and LOW. For these situations, the Arduino offers six analog
inputs that translate an input voltage into a number that ranges from 0 (0 Volts)
to 1023 (5 Volts). The analog pins are perfect for measuring all those "real
world" values, and allow you to interface the Arduino to all kinds of things.
ANALOG
0 volts
5 volts
1023
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 2
Code to Note:
int sensorValue;
sensorValue = analogRead(sensorPin);
delay(sensorValue);
Troubleshooting:
Sporadically Working
This is most likely due to a slightly dodgy connection
with the potentiometer's pins. This can usually be
conquered by holding the potentiometer down.
Not Working
Make sure you haven't accidentally connected the
potentiometer's wiper to digital pin 2 rather than analog
pin 2. (the row of pins beneath the power pins).
Still Backward
You can try operating the circuit upside down.
Sometimes this helps.
Circuit 2
CIRCUIT
#3
RGB LED
Pin 11
Pin 10
Pin 9
resistor
(330ohm)
(Orange-Orange-Brown)
red
green
blue
GND
PARTS:
(ground) (-)
LED
IC
Potentiometer
330 Transistor
LED
Wire
330
Resistor P2N2222AG Resistor
X
38
1X6
red
blue
green
common
p.10
p.28
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
a b c d e
a b c d e
f g h i
f g h 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
Component:
Image Reference:
a4 a5 a6 a7
5V
e4 eg4
e7
11
330 Resistor
5V
e6 eg6
e7
11
330 Resistor
5V
e7 eg7
11
Jumper Wire
h4
Jumper Wire
e5
Jumper Wire
h6
Jumper Wire
h7
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 Arduino to
output analog voltages as well?
The answer is no... and yes. The Arduino does not have a true analog voltage
output. But, because the Arduino is so fast, it can fake it using something
called PWM ("Pulse-Width Modulation").
The Arduino is so fast that it can blink a pin on and off almost 1000 times per
second. PWM goes one step further by varying the amount of time 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 Arduino creates the illusion of a
"true" analog output.
HIGH (5 volts)
0.5 v
90%
LOW (0 volts)
Jumper Wire
5V
Jumper Wire
GND
10%
+
HIGH (5 volts)
50%
LOW (0 volts)
10%
HIGH (5 volts)
LOW (0 volts)
2.5 v
50%
4.5 v
90%
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 3
Code to Note:
for (x = 0; x < 768; x++)
{}
if (x <= 255)
{}
else
{}
"If / else" statements are used to make choices in your programs. The
statement within the parenthesis () is evaluated; if it's true, the code within
the first brackets {} will run. If it's not true, the code within the second
brackets {} will run.
delay(sensorValue);
Troubleshooting:
Seeing Red
The 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);
CIRCUIT #4
Pin 2
Pin
2
Pin 33
Pin
Pin 44
Pin
Multiple LEDs
Pin 55
Pin
LED
Light Emitting Diode
resistor
(330ohm)
(Orange-Orange-Brown)
GND
Pin 66
Pin
Pin 77
Pin
Pin 88
Pin
Pin 99
Pin
LED
resistor
(330ohm)
(Orange-Orange-Brown)
GND
PARTS:
(ground) (-)
LED
330
Resistor
X
Wire
X
10
p.32
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Component:
+
Image Reference:
c2 c3
330 Resistor
GND
a18
a3
c5 c6
330 Resistor
GND
a21
c8 c9
330 Resistor
GND
a24
c11 c12
Jumper Wire
e2
c14 c15
Jumper Wire
e5
c17 c18
Jumper Wire
e8
c20 c21
Jumper Wire
e11
c23 c24
Jumper Wire
e14
330 Resistor
GND
c23
c24
a3
Jumper Wire
e17
330 Resistor
GND
a6
Jumper Wire
e20
330 Resistor
GND
a9
Jumper Wire
e23
330 Resistor
GND
a12
Jumper Wire
5V
330 Resistor
GND
a15
Jumper Wire
GND
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 4
Code to Note:
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.
digitalWrite(ledPins[0], HIGH);
index = random(8);
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. The random() function is a great way to do this. See
http://arduino.cc/en/Reference/Random for more information.
Troubleshooting:
Circuit 2
CIRCUIT
#5
Push Buttons
Pin 22
Pin
Pin 33
Pin
+5 Volts
Pin 13
resistor
LED
resistor (330ohm)
(Orange-Orange-Brown)
GND
PARTS:
(ground) (-)
IC Button
Push
LED
X
21
10K
330
Resistor
X
18
330
Wire
Resistor
X
28
19
Wire
X
p.36
p.10
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
d4 g4
Push Button
d6 g6
d9 g9
Push Button
LED (5mm)
d11 g11
h20 h21
10K Resistor
i6 a15
+
10K Resistor
i11
330 Resistor
j21
Jumper Wire
i4
Jumper Wire
i9
Jumper Wire
+
+
One of the things that makes the Arduino so useful is that it can make complex decisions
based on the input it's getting. For example, you could make a thermostat that turns on a
heater if it gets too cold, a fan if it gets too hot, waters your plants if they get too dry, etc.
In order to make such decisions, the Arduino provides a set of logic operations that let you
build complex "if" statements. They include:
==
EQUIVALENCE
!=
DIFFERENCE
&&
AND
||
OR
NOT
Jumper Wire
h11
Jumper Wire
j20
For example:
if ((mode == heat) && ((temperature < threshold) || (override == true)))
{
digitalWrite(HEATER, HIGH);
}
...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 Arduino to
make intelligent decisions and take control of the world around it!
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 5
Code to Note:
pinMode(button2Pin, INPUT);
button1State = digitalRead(button1Pin);
if (button1State == LOW)
Troubleshooting:
Circuit 2
CIRCUIT
#6
Photo Resistor
Pin 9
+5 Volts
photo
resistor
LED
Pin A
resistor (330ohm)
(Orange-Orange-Brown)
GND
PARTS:
(ground) (-)
Photo Resistor
LED
X
330
Resistor
X
Wire
X
10K
Resistor
X
p.40
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Photo Resistor
LED (5mm)
f5
f6
h20 h21
i21
10K Resistor
i1
i5
Jumper Wire
j1
Jumper Wire
A0
Jumper Wire
Pin
Pin 33
j5
j6
GND
Jumper Wire
j20
Jumper Wire
5V
Jumper Wire
GND
(ground) (-)
A voltage divider consists of two resistors. The "top" resistor is the sensor
you'll be using. The "bottom" one is a normal, fixed resistor. When you
connect the top resistor to 5 Volts, and the bottom resistor to ground, the
middle will output a voltage proportional to the values of the two resistors.
When one of the resistors changes (as it will when your sensor senses things),
the output voltage will change as well!
Although the sensor's resistance will vary, the resistive sensors (flex
sensor,light sensor, softpot, and trimpot) in the SIK are around 10K Ohms.
We usually want the fixed resistor to be close to this value, so using a 10K
resistor is a great choice for the fixed "bottom" resistor.
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 6
Code to Note:
Troubleshooting:
Circuit 2
CIRCUIT
#7
Temperature Sensor
5 Volts
Pin A
+5v
signal
gnd
TMP36
(precision
temperature
sensor)
GND
PARTS:
(ground) (-)
Temp. Sensor
Wire
X
5
FRONT
BACK
p.44
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Temperature Sensor
f5
Jumper Wire
f6
f7
This circuit uses the Arduino IDE's serial monitor. To open this, first upload the
program then click the button which looks like a magnifying glass in a square.
j5
1
Jumper Wire
A0
Jumper Wire
j6
+
j7
Jumper Wire
5V
Jumper Wire
GND
+
3
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 7
Code to Note:
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(degreesC);
Serial.println(degreesF);
Troubleshooting:
Gibberish is Displayed
This happens because the serial monitor is receiving data at
a different speed than expected. To fix 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 fingers to heat it up or
pressing a bag of ice against it to cool it down.
Circuit 2
CIRCUIT
#8
A Single Servo
Pin 9
Mini Servo
signal
(white)
+5v
gnd
(red)
(black)
GND
+5 volts
PARTS:
(ground) (-)
Servo
(5V)
Wire
X
p.48
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Servo
e5 e6 e7
Jumper Wire
e5
Jumper Wire
e6
Jumper Wire
e7
Jumper Wire
b5
Jumper Wire
a6
Jumper Wire
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 to more advanced
devices (LCD displays, stepper motors, ethernet ports, etc.)
See http: //arduino.cc/en/Reference/Libraries for a list of the standard libraries and
information on using them.
a7
Jumper Wire
5V
Arduino 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.
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 that device to the
Arduino. Many of SparkFun's products come with Arduino libraries, and you can find even
more using Google and the Arduino Playground at http://arduino.cc/playground/. And
when YOU get the Arduino working with a new device, consider making a library for it and
sharing it with the world!
+
Edit Sketch
Tools
Help
Verify / Compile
Jumper Wire
GND
EEPROM
Ethernet
Firmata
LiquidCrystal
SD
Servo
SoftwareSerial
SPI
Stepper
Wire
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 8
Code to Note:
#include is a special "preprocessor" command that inserts a library
(or any other file) into your sketch. You can type this command
yourself, or choose an installed library from the "sketch / import
library" menu.
#include <Servo.h>
Servo servo1;
servo1.attach(9);
servo1.write(180);
The servo library adds new commands that let you control a servo.
To prepare the Arduino to control a servo, you must first 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).
Servos don't spin all the way around, but they can be commanded to move to
a specific position. We use the servo library's write() command to move a
servo to a specified number of degrees(0 to 180). Remember that the servo
requires time to move, so give it a short delay() if necessary.
Troubleshooting:
CIRCUIT #9
Flex Sensor
+5 volts
(5V)
Pin A
resistor
(10K ohm)
(Brown-Black-Orange)
flex
sensor
+5 volts
(5V)
Pin 9
Mini Servo
GND
PARTS:
(ground) (-)
Flex
IC Sensor
Potentiometer
Servo
LED
11
X X
33010K
Resistor
Resistor
X
Wire
X
8 X1
11
p.10
p.52
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Servo
e1 e2 e3
Jumper Wire
e1
Jumper Wire
e2
Jumper Wire
e3
Flex Sensor
h19 h20
10K Resistor
i20 i24
Jumper Wire
i19
Jumper Wire
A0
The key to visibility into a microcontroller is output. This 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
data from the Arduino to a window back on the host computer. This is great for your
sketch's final output, but it's also incredibly useful for debugging.
h24 +
Jumper Wire
b1 +
h24
Jumper Wire
a2 +
h24
Jumper Wire
a3
5V
Jumper Wire
GND
j20
Jumper Wire
Jumper Wire
It happens to everyone - you write a sketch which successfully compiles and uploads,
but you can't figure out why it's not doing what you want it to. Larger computers
have screens, keyboards, and mice that you can use to debug your code, but tiny
computers like the Arduino have no such things.
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 9
Code to Note:
Serial.print("sensor: ");
Serial.print(flexposition);
Serial.print(" servo: ");
Serial.println(servoposition);
Troubleshooting:
Circuit 2
CIRCUIT
#5
#10
Pin 0
Pin
A
Soft Potentiometer
10
+5 volts
resistor (10K ohm)
gnd
V+
Brown-Black-Orange)
Pin 9
green
Pin 11
red
Pin 10
soft pot
wiper
GND
blue
(ground) (-)
resistor (330ohm)
PARTS:
(Orange-Orange-Brown)
LED
IC
330
LED
Soft Potentiometer
Resistor
X
Wire
330
Resistor
318
330
Resistor
X
10K
Resistor
X
p.10
p.56
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Component:
a4 a5 a6 a7
Jumper Wire
5V
Jumper Wire
GND
Soft Potentiometer
5V
330 Resistor
5V
e4 eg4
e7
11
330 Resistor
5V
e6 eg6
e7
11
330 Resistor
5V
e7 eg7
11
i19
10K Resistor
Jumper Wire
h4
Jumper Wire
e5
Jumper Wire
h6
Jumper Wire
h7 +
Jumper Wire
Jumper Wire
Jumper Wire
j18
A0
Image Reference:
j19
j20
10
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 10
Code to Note:
Troubleshooting:
Bizarre Results
The most likely cause of this is if youre pressing the
potentiometer in more than one position. This is normal
and can actually be used to create some neat results.
Circuit 2
CIRCUIT
#11
Buzzer
Pin 9
Piezo
Element
11
GND
PARTS:
(ground) (-)
Piezo Element
Wire
X
p.60
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Piezo Element
j9
Jumper Wire
i7
j7
Jumper Wire
j9
Jumper Wire
5V
Jumper Wire
GND
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. Here's a simple example named "add", which adds two numbers
together and returns the result. Let's break it down.
int add(int parameter1, int parameter2)
{
int x;
x = parameter1 + parameter2;
}
return(x);
Your functions can take in values ("parameters"), and return a value, as this one does.
But you can also do either or none of those things, if you wish.
If you'll be passing parameters /to/ your function, put them (and their types) in the
parentheses after the function name. If you won't be giving your function any
parameters, just use an empty parenthesis () after the name.
If you'll be returning a value /from/ your function, put the type of the return value in
front of the function name. Then in your function, when you're ready to return the
value, put in a return() statement. If you won't be returning a value, put "void" in
front of the function name (just like you've already seen for the setup() and loop()
functions).
When you write your own functions, you make your code neater and easier to re-use.
11
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 11
Code to Note:
Troubleshooting:
No Sound
Given the size and shape of the piezo element it is easy to
miss the right holes on the breadboard. Try double
checking its placement.
12
Circuit 2
CIRCUIT
#12
Spinning a Motor
Pin 9
resistor (330ohm)
(Orange-Orange-Brown)
base
transistor
P2N2222AG
emitter
collector
motor
multimeter
diode
GND
(ground) (-)
+5 volts
Transistor
Diode
P2N2222AG
DC Motor
1N4148
330
Resistor
X
P2N2
222A
A18
Wire
FRONT
P2N2
222A
A18
PARTS:
(5V)
BACK
p.64
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
a b c d e
a b c d e
f g h i
f g h 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
Transistor P2N2222AG
Image Reference:
P2N2
222A
A18
Component:
a1 a2 a3
Diode 1N4148
GND
b7
b11
a3
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 programming in
general.
Most of the sketches you write will be a loop with some or all of these steps:
DC Motor
330 Resistor
e7 e11
5V
Jumper Wire
e2 eg2
e7
11
We've already shown you how to use a bunch of different 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.
e1
Jumper Wire
j2
Jumper Wire
a7
Jumper Wire
e3 d11
Jumper Wire
5V
Jumper Wire
GND
It's usually pretty easy to pull pieces of different sketches together, just open them in
two windows, and copy and paste between them. This is one of the reasons we've
been promoting "good programming habits". Things 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, 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.)
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
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. (And be sure to let us know so we can put it
on our home page!)
12
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 12
Code to Note:
speed = Serial.parseInt();
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 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.
Troubleshooting:
Motor Not Spinning
If you sourced your own transistor, double check with
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 Arduino board will disconnect from the
computer. Try un-plugging and then re-plugging it into
your USB port.
13
5
Circuit 2
CIRCUIT
#5
#13
Pin 2
Relays
resistor (330ohm)
(Orange-Orange-Brown)
base
5 volts
transistor
P2N2222AG
emitter
collector
resistor
(330ohm)
(Orange-Orange-Brown)
com
coil
diode
(flyback)
NC
NO
LED
LED
5 volts
GND
PARTS:
(ground) (-)
IC
Relay
Transistor
LED
Diode
P2N2222AG
X
330
Resistor
1N4148
X
LED
X
Wire
X
14
p.10
p.68
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Component:
e9 f9
Relay
Jumper Wire
f7
f5 f6e19
e15
a2 a3 a4
Jumper Wire
+ e19
e15
c19 c20
Jumper Wire
+ e19
+
a23
e15
c22 c23
Jumper Wire
+
a20
b14 e19
GND
b7
b11
a3
Jumper Wire
a7 a9
e4 e9
e15 f15
P2N2
222A
A18
Transistor P2N2222AG
LED (5mm)
LED (5mm)
Diode 1N4148
Image Reference:
330 Resistor
5V
e3 eg3
e7
11
Jumper Wire
330 Resistor
5V
e2 eg2
e7
11
Jumper Wire
5V
e2
Jumper Wire
GND
Jumper Wire
Jumper Wire
j3
Jumper Wire
j5
j7
j9
Jumper Wire
h9
Jumper Wire
i13 e22
Jumper Wire
i15 e19
13
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 13
Code to Note:
digitalWrite(relayPin, HIGH);
digitalWrite(relayPin, LOW);
Troubleshooting:
No Clicking Sound
The transistor or coil portion of the circuit isn't quite
working. Check the transistor is plugged in the right way.
Not Quite Working
The 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).
14
Circuit 2
CIRCUIT
#14
Shift Register
+5 volts
+5 volts
resistors (330ohm)
(Orange-Orange-Brown)
LEDs
15 16 10
1
11
12
14
Pin 3
44
Pin
clock
latch
Pin 2
data
4
5
6
7
13
GND
PARTS:
(ground) (-)
IC
LED
X
330
Resistor
X
Wire
X
19
VCC
QB
16
QC
15
QA
QD
14
SER
QE
13
OE
QF
12
RCLK
QG
11
SRCLK
QH
10
SRCLR
GND
QH
p.72
a b c d e
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
a b c d e
f g h i
f g h 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
Component:
Image Reference:
Component:
e5 e6 e7 e8 e9 e10 e11 e12
IC
Jumper Wire
GND
+
+
a3
c14 c15
Jumper Wire
GND
j5
+
a3
c17 c18
Jumper Wire
GND
j6
a14
a3
c20 c21
Jumper Wire
c23 c24
Jumper Wire
h14 h15
Jumper Wire
j9
h17 h18
Jumper Wire
j10
h20 h21
Jumper Wire
GND
j11
+
a14
a3
h23 h24
Jumper Wire
GND
f14
a8
a3
a15
a3
Jumper Wire
GND
f17
a9
a3
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
LED (5mm)
Image Reference:
330 Resistor
j7
GND
j8
a14
a3
330 Resistor
GND
c23
a18
a3
Jumper Wire
GND
f20
a
10
a3
330 Resistor
GND
c23
a21
a3
Jumper Wire
GND
f23
a
11
a3
330 Resistor
GND
c23
a24
a3
Jumper Wire
GND
a23
a7
a3
330 Resistor
GND
j15
c24
a3
Jumper Wire
GND
a20
a6
a3
330 Resistor
GND
j18
c24
a3
Jumper Wire
GND
a17
a5
a3
330 Resistor
GND
j21
c24
a3
Jumper Wire
GND
a14
j6
a3
330 Resistor
GND
j24
c24
a3
Jumper Wire
5V
Jumper Wire
GND
+
+
a3
Jumper Wire
GND
+
j10
14
Arduino Code:
Circuit 2
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 14
Code to Note:
You'll communicate with the shift register (and a lot of other parts)
using an interface called SPI, or Serial Peripheral Interface. This
interface uses a data line and a separate clock line that work together
to move data in or out of the Arduino at high speed. The MSBFIRST
parameter specifies the order in which to send the individual bits, in
this case we're sending the Most Significant Bit first.
bitWrite(data,desiredPin,desiredState);
Troubleshooting:
Learning More
Visit us Online:
This 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:
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License.
To view a copy of this license visit:
http://creativecommons.org/licenses/by-sa/3.0/
Or send a letter to:
Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.