0% found this document useful (0 votes)
398 views

SFE SIK RedBoard Guide Version3.0 Online

electronics

Uploaded by

BASEER AHMAD
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
398 views

SFE SIK RedBoard Guide Version3.0 Online

electronics

Uploaded by

BASEER AHMAD
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A L ~ 4 (P W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

1 3for the SparkFun RedBoard Your guide to the SparkFun Inventors Kit I TA ~6 ~5 4 RX TX
AR

SC SC L AR A E GN F D 13 1 ~1 2 ~1 1 0 ~9 8

SIK GUIDE
DIG 7 L( PW M~ )
DU INO LA NG UA GE DE

VE

15

LO

PM

EN

7-

TP

LA

TF

OR

ON

EF

Version 3.0
V ET

IOR

ES

~3

G IN 8

13 ~ ~ ~ 9 10 11

12

RE

SE

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 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:
What is the RedBoard platform? Download Arduino Software (IDE) Install Drivers Identify Your Hardware Download SIK Guide Code

Getting Started
1 3 4 7 8

Section 2:

Getting Started with Circuits


The World Runs on Circuits Inventory of Parts RedBoard Breadboard Circuit #1 - Your First Circuit: Blinking a LED Circuit #2 - Potentiometer Circuit #3 - RGB LED Circuit #4 - Multiple LEDs Circuit #5 - Push Buttons Circuit #6 - Photo Resistor Circuit #7 - Temperature Sensor Circuit #8 - A Single Servo Circuit #9 - Flex Sensor Circuit #10 - Soft Potentiometer Circuit #11 - Piezo Element Circuit #12 - Spinning a Motor Circuit #13 - Relay Circuit #14 - Shift Register Circuit #15 - LCD 9 11 13 15 17 24 28 32 36 40 44 48 52 56 60 64 68 72 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. The 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


The 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). That'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

The SparkFun RedBoard is one of a multitude of development boards based on the ATmega328. It has 14 digital input/output pins (6 of which can be PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ISP header, and a reset button. Dont worry, youll learn about all these later.

7-15V

FPO
FPO
13 RX TX ON ISP

IOREF RESET 3.3V 5V GND GND VIN


A0 A1

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

POWER ANALOG IN

DIGITAL (PWM~)

A2 A3 A4 A5

7 ~6 ~5 4 ~3 2 TX 1 RX 0

c b

RedBoard

f a b c
Bug Zapper Counter Old Toy Email Notifer Power-Lacing High Tops

d e f

Camera Time-lapse operation Auto-Plant Watering Re-Programmed Trafc Light

g h

Auto-Coffee Maker Quadcopter

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 first from www.arduino.cc (it's free!). This software, known as the Arduino IDE, will allow you to program the board to do exactly what you want. Its like a word processor for writing programs. With an internet-capable computer, open up your favorite browser and type in the following URL into the address bar:

NW

NE

SE

Choose the appropriate Operating System installation package for your computer.

SW

arduino.cc/en/main/software

Download

operating system next to the + sign. Windows Windows Mac OS X

Click on your appropriate computer

Mac OS X Linux: 32 bit, 64 bit

Linux: 32 bit, 64 bit source

user

// Connect your RedBoard to your Computer


Use the USB cable provided in the SIK kit to connect the RedBoard to one of your computers USB inputs.

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I ~ T AL ~5 (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

// Install Arduino Drivers


Depending on your computers operating system, you will need to follow specific instructions. Please go to https://learn.sparkfun.com/tutorials/how-to-install-ftdi-drivers for specific instructions on how to install the FTDI drivers onto your RedBoard.

~ 10

11

// Open the Arduino IDE:


Open the Arduino IDE software on your computer. Poke around and get to know the interface. We arent going to code right away, this is just an introduction. This step is to set your IDE to identify your RedBoard.

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


File 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

Note:
Your SparkFun RedBoard and the Arduino UNO are interchangeable but you wont nd the RedBoard listed in the Arduino Software. Select Arduino UNO instead.

Tools

Help

Auto Format Archive Sketch Fix Encoding & Reload Serial Monitor Board Serial Port com 1 com 12

// Select your Serial Device

Select the serial device of the RedBoard from the Tools | Serial Port menu. This is likely to be com3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your RedBoard and re-open the menu; the entry that disappears should be the RedBoard. Reconnect the board and select that serial port.

Programmer Burn Bootloader

Tools

Help

Auto Format Archive Sketch Fix Encoding & Reload Serial Monitor Board Serial Port /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

Select the serial device of the RedBoard from the Tools > Serial Port menu. On the Mac, this should be something with /dev/tty.usbmodem or /dev/tty.usbserial in it.

Programmer Burn Bootloader

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
// Copy SIK Guide Code into Examples library in Arduino folder

Start

Programs

arduino

examples

Unzip the file SIK Guide Code. It should be located in your browsers Downloads folder. Right click the zipped folder and choose unzip.

Copy the SIK Guide Code folder into Arduinos folder named examples.

Contents Resources Find Arduino in your applications folder. Right click(ctrl + click) on Arduino. Select Show Package Contents.
Arduino Open Show Package Contents Move to Trash

Java examples Copy the SIK Guide Code folder into Arduinos folder named examples.

Unzip the file SIK Guide Code. It should be loacted in your browsers Downloads folder. Right click the zipped folder and choose unzip.

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

WHATS NEXT? Read on to learn more about getting started with circuits. Then you can start on your first 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 find circuits. The 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.

// Simple and Complex Circuits In this guide, you will be primarily exploring simple circuits - but that doesn't mean you can't do amazing things with simple tools! When you've finished the SIK, your knowledge of circuits will enable you to explore amazing projects and unleash the power of your imagination.

a b c d e
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

f g h i
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

Inventory of Parts
Jumper Wire
Various Colors

LED (5mm)

(Light Emitting Diode)

x30

x10

x10

x1

330 Resistor

10K Resistor

x25

* ACTUAL SIZE

x25

* ACTUAL SIZE

Potentiometer

Diode

(1N4148)

x1

x2

* ACTUAL SIZE

Photo Resistor

Piezo Element

x1

x1

(TMP36)

(P2N2222AG)

FRONT

P2N2 222A A18


FRONT

Temp. Sensor

Transistor

x1

BACK

x2

BACK

DC Motor

Push Button

x1

x2

Flex Sensor

SparkFun RedBoard

RESET

x1

7-15V SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

Soft Potentiometer
13 RX TX
IOREF RESET 3.3V 5V GND GND VIN
A0 A1

POWER

DIGITAL (PWM~)

x1

A2 A3 A4 A5

7 ~6 ~5 4 ~3 2 TX 1 RX 0

ANALOG IN

ON

ISP

Servo

x1

Breadboard
x1

Standard Solderless (Color may vary)

a b c d e

f g h i
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Relay

Integrated Circuit
(IC)

x1

x1

LCD

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

x1

x1

RESET

2 1

7-15V SCL SDA AREF 4 3 5 GND 13 12 ~11 ~10 ~9 8

13 RX TX

IOREF RESET 3.3V 5V GND GND

POWER

DIGITAL (PWM~)

10

VIN
A0 A1

A2 A3 A4 A5

7 ~6 ~5 4 ~3 2 TX 1 RX 0

ANALOG IN

ON

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.
LED (RX: Receiving) - This shows when the FTDI chip is receiving data bits from the microcontroller. This happens when the microcontroller is 3 sending data bits back to the computer. LED (TX: Transmitting) - This shows when the FTDI chip is transmitting data bits to the microcontroller. This happens when the 4 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 Digital Digital Digital Digital Digital Digital Digital Digital Analog Analog Analog Analog Analog Analog Digital Digital Digital Digital TX - Out RX - In = PWM/Analog out compatible (i.e. )

11 RFU
IOREF Reset Power Out Power Out Ground Ground

10

Power In

a b c d e
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

f g h i
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

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 2 Horizontal Connection (a-e & f-j) // See Diagram Below)
Making a Connection:
Above the breadboard LED CONNECTED!

Hows it all connected?


a b c d e
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

f g h i
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 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.
Inside the breadboard

Horizontal Rows:
Each of these rows numbered 1-30 are comprised of ve horizontal sockets. Components placed in the same row will be connected in a circuit when power is running.

a b c d e

f g h 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 b c d e
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

f g h i
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

RESET RESET

7-15V 7-15V SCL SCL SDA SDA AREF AREF GND GND 13 13 12 12 ~11 ~11 ~10 ~10 ~9 ~9 8 8 7 7 ~6 ~6 ~5 ~5 4 4 ~3 ~3 2 2 TX 1 TX 1 RX 0 RX 0

13 13 RX RX TX TX

IOREF IOREF RESET RESET 3.3V 3.3V 5V 5V GND GND GND GND VIN VIN
A0 A0 A1 A1 A2 A2 A3 A3 A4 A4 A5 A5

Connect the USB cable.

Screw the RedBoard down and into place.

POWER POWER ANALOG ANALOG ININ ON ON ISP ISP

DIGITAL (PWM~) DIGITAL (PWM~)

a b c d e

f g h i

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I ~ T AL ~5 (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

Your RedBoard runs on 5V. 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 RedBoard into your computer, you are supplying it with just the right voltage it needs to thrive! 5V cant hurt you, so dont be afraid to touch anything in your circuit. You can also power the RedBoard through the barrel jack. The on-board voltage regulator can handle anything from 7 to 15VDC.

~ 10

11

Peel sticker o back of breadboard and stick into place.

Circuit 2

PIN 13 RedBoard LED (Light-Emitting Diode)

Blinking an LED

Resistor (330 ohm) (Orange-Orange-Brown)

LEDs (light-emitting diodes) are small, powerful lights that are used in many different applications. To start off the SIK, we will work on blinking an LED. That's right - it's as simple as turning a light on and off. It might not seem like much, but establishing this important baseline will give you a solid foundation as we work toward more complex experiments.

GND (Ground)

Each circuit begins with a brief description of the what you are putting together and the expected result.

This is a schematic of your circuit.

PARTS:

LED
X

330 Resistor 1
X

Wire 1
X

This section lists the parts you will need to complete the circuit.

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

This is an illustration of how the completed circuit should look. It is not necessary to use the black holder for the RedBoard and breadboard, but we recommend it for the rst time inventor!

G IN 8

13 ~ ~ ~ 9 10 11

12

Components like resistors need to have their legs bent into 90 angles in order to correctly t the breadboard sockets. You can also cut the legs shorter to make them easier to work with on the breadboard.

Circuit 1: Blinking an LED

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 330 Resistor: The color banding 8 should read orange-or9 ange-brown-gold. The compo1 0 nent legs can go in either hole. 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 Jumper Wire: All jumper wires work the same. They are used to 23 24 connect two points together. This guide will show the wires with dierent 25 colored insulations for clarity, but using 26 dierent combinations of colors is 27 completely acceptable. 28 29 30

a b c d e

1 2 3 4 5 LED: Make sure the short leg,6 marked with at side, goes into 7 the negative position (-). 8 9 1 0 1 1 1 2 1 3 1 4 Flat Edge 1 5 1 6 1 7 1 8 Short Leg 1 9 20 2 1 22 23 24 25 26 27 28 29 30

f g h i

Component:
c2 c3
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 the components markings indicating how to place it on the breadboard.

Image Reference:

LED (5mm) + a3
a3 GND

+
Resistors are placed in breadboard sockets only. The - symbol represents any socket in its vertical column on the Power bus.

330 Resistor GND 5V


+ e2
5V on the RedBoard connects to the row marked + on the breadboard.

Jumper Wire

GND on the RedBoard should be connected to the row marked - on the breadboard.

Jumper Wire Pin 13

Jumper Wire

Pin 13 on the RedBoard connects to socket e2 on the breadboard.

RedBoard: The red background represents a connection to one of the RedBoard header pins. Breadboard: The white background represents a connection to a breadboard socket specied 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 Close Save Save As... Upload Upload Using Progammer Page Setup Print

1.Basics 2.Digital 3.Analog 4.Communication 5.Control 6.Sensors 7.Displays 8.Strings ArduinoISP SIK Guide Code EEPROM Ethernet Firmata Liquid Crystal SD Servo SoftwareSerial SPI Stepper Wire

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 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); delay(1000); digitalWrite(13, LOW); delay(1000); } // // // // set the LED on wait for a second set the LED off wait for a second

Verify

This compiles your code. The IDE changes it from text into instructions the computer can understand.

Upload

This sends the instructions via the USB cable to the computer chip on the RedBoard. The RedBoard will then begin running your code automatically.

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

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ AL ~5 (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

Code to Note:
Begin to understand how the Arduino code works. See below.

1
Circuit 2

This is where you will nd the Arduino code for each circuit.

Arduino Code:

Open Arduino IDE // File > Examples > SIK Guide > Circuit # 1
Remember to Verify and Upload your code.

pinMode(13, OUTPUT);

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

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

What you Should See:


You should see your LED blink on and off. If it isn't, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.

See if your circuit is complete and working in this section.

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P

L SC A SD EF AR ND G 13

TX

AL

RX

O G 8

13

IN ~ ~ 9

12

This is a section dedicated to the most common mistakes made while assembling the circuit.

RX

Here you will nd examples of the circuit you just completed in the real world. Many of the theories in these circuits are used in things you use everyday!
10
TX

11

O N

Troubleshooting:
LED Not Lighting Up? LEDs will only work in one direction. Try taking it out and twisting it 180 degrees (no need to worry, installing it backward does no permanent harm). Program Not Uploading This 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]

Real World Application:


Almost all modern flat screen televisions and monitors have LED indicator lights to show they are on or off.

Circuit 2 CIRCUIT #5 #2

Potentiometer
PIN 13 RedBoard

5 volt
LED (Light-Emitting Diode)

Potentiometer Resistor (330 ohm) (Orange-Orange-Brown)

PIN A0 RedBoard

In this circuit youll work with a potentiometer. A potentiometer is also known as a variable resistor. When its connected with 5 volts across its two outer pins, the middle pin outputs a voltage between 0 and 5, depending on the position of the knob on the potentiometer. A potentiometer is a perfect demonstration of a variable voltage divider circuit. The voltage is divided proportionate to the resistance between the middle pin and the ground pin. In this circuit, youll learn how to use a potentiometer to control the brightness of an LED.

GND (Ground)

PARTS:

IC Potentiometer
X

LED 1
X

330 Resistor 1 8
X

Wire 1 8
X

19 6

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.24 p.10

Circuit 2: Potentiometer

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
a6 a7 a8

Image Reference: If you look closely at your RedBoard, you'll see some pins labeled "DIGITAL", and some labeled "ANALOG". What's the difference? +

Digital versus Analog:

Potentiometer
h20 h21

LED (5mm) +
j21

330 Resistor
e6

Jumper Wire A0
e7 e8 +

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 RedBoard, "HIGH" (5 volts) and "LOW" (0 volts). The digital pins on an RedBoard 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).

Jumper Wire

Jumper Wire

LOW

HIGH or on

DIGITAL

off 0 volts

Jumper Wire GND 5V GND


+

Pin 13 5V

j20

5 volts

Jumper Wire

Jumper Wire

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 RedBoard 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 RedBoard to all kinds of things.

ANALOG

0 volts 0

to

5 volts 1023

Code to Note:
int sensorValue; A variable is a stored value youve given a name to. You must introduce, or "declare" variables before you use them; here we're declaring a variable called sensorValue, of type "int" (integer). Don't forget that variable names are case-sensitive!
We use the analogRead() function to read the value on an analog pin. analogRead() takes one parameter, the analog pin you want to use ("sensorPin"), and returns a number ("sensorValue") between 0 (0 volts) and 1023 (5 volts).

2
Circuit 2

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

sensorValue = analogRead(sensorPin);

delay(sensorValue);

The Arduino is very very fast, capable of running thousands of lines of code each second. To slow it down so that we can see what it's doing, we'll often insert delays into the code. delay() counts in milliseconds; there are 1000 ms in one second.

What you Should See:


715 V

You should see the LED blink faster or slower in accordance with your potentiometer. If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ AL ~5 (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

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 havent 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).

Real World Application:


Most traditional volume knobs employ a potentiometer.

Circuit 2 CIRCUIT #3

PIN 11 PIN 10 PIN 9 Resistors (330 ohm) (Orange-Orange-Brown) RedBoard

RGB LED

You know whats even more fun than a blinking LED? Changing colors with one LED. RGB, or red-green-blue, LEDs have three different color-emitting diodes that can be combined to create all sorts of colors. In this circuit, youll learn how to use an RGB LED to create unique color combinations. Depending on how bright each diode is, nearly any color is possible!

LED (Light-Emitting Diode)

PARTS:

LED IC Potentiometer 330 Transistor LED Wire 330 Resistor P2N2222AG Resistor
X

BLUE
A0 A1 A2 A3 A4 A5

GREEN
X

GND (Ground)

RED

3 8

1X6

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

red blue

green

common

p.10 p.28

Circuit 3: RGB LED

a b c d e

f g h i

RESET

* The longest lead is the common(gnd).

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
a4 a5 a6 a7

Image Reference: 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?

The shocking truth behind analogWrite():

RGB LED (5mm)


5V 5V 5V
e7 e1 g7 1 g6 e6 e7 e1 1 e4 e1 g4 e7 1

330 Resistor

330 Resistor

The answer is no... and yes. The RedBoard does not have a true analog voltage output. But, because the RedBoard is so fast, it can fake it using something called PWM ("Pulse-Width Modulation"). The pins on the RedBoard with ~ next to them are PWM/Analog out compatible.

330 Resistor

Jumper Wire Pin 9


e5

h4

Jumper Wire Pin 10


HIGH (5 volts)

The RedBoard 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 RedBoard creates the illusion of a "true" analog output.

Jumper Wire Pin 11


LOW (0 volts)

h6

Jumper Wire 5V GND


+
HIGH (5 volts)

h7
10%

90%

0.5V

Jumper Wire

Jumper Wire

50%
LOW (0 volts)

2.5V
50%

HIGH (5 volts)

10%

LOW (0 volts)

4.5V
90%

Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 3
A for() loop is used to step a number across a range, and repeatedly runs code within the brackets {}. Here the variable "x" starts a 0, ends at 767, and increases by one each time ("x++").
"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.

Code to Note:
for (x = 0; x < 768; x++) {}

if (x <= 255) {} else {}

delay(sensorValue);

The RedBoard is very very fast, capable of running thousands of lines of code each second. To slow it down so that we can see what it's doing, we'll often insert delays into the code. delay() counts in milliseconds; there are 1000 ms in one second.

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 verified and uploaded the code to your board or see the troubleshooting tips below.
IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

715 V

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ AL ~5 (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

Troubleshooting:
LED Remains Dark or Shows Incorrect Color With the four pins of the LED so close together, its sometimes easy to misplace one. Double check each pin is where it should be. Seeing 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);

Real World Application:


Many electronics such as videogame consoles use RGB LEDs to have the versatility to show different colors in the same area. Often times the diffent colors represent different states of working condition.

CIRCUIT #4
PIN 2 PIN 3 PIN 4 PIN 5

RedBoard

Multiple LEDs

LEDs (Light-Emitting Diodes) Resistors (330 ohm) (Orange-Orange-Brown) GND (Ground)


PIN 6 PIN 7 PIN 8 PIN 9

So you have gotten one LED to blink on and off fantastic! Now it's time to up the stakes a little bit by connecting EIGHT LEDS AT ONCE. We'll also give our RedBoard a little test by creating various lighting sequences. This circuit is a great setup to start practicing writing your own programs and getting a feel for the way RedBoard works. Along with controlling the LEDs, youll learn about a couple programming tricks that keep your code neat and tidy: for() loops - used when you want to run a piece of code several times arrays[ ] - used to make managing variables easier by grouping them together

RedBoard

LEDs (Light-Emitting Diodes) Resistors (330 ohm) (Orange-Orange-Brown) GND (Ground)

PARTS:

LED
X

330 Resistor 8
X

Wire 8
X

10

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.32

Circuit 4: Multiple LEDs

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
c2 c3

Image Reference: 330 Resistor 330 Resistor 330 Resistor Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire
a15 a18 GND a21 a24

Component:

Image Reference:
a1 8

LED (5mm) + c5 c6

LED (5mm) +
c8 c9

LED (5mm) + c11 c12

LED (5mm) +
c14 c15

Pin 2 Pin 3 Pin 4 Pin 5 Pin 6 Pin 7 Pin 8 Pin 9 5V

e2 e5 e8 e11 e 14 e 17 e20 e23 +

LED (5mm) +
c17 c18

LED (5mm) +
c20 c21

LED (5mm) +
c23 c24

LED (5mm) +
a3 a6 a9 a12

330 Resistor

330 Resistor

330 Resistor

330 Resistor

330 Resistor

Jumper Wire

GND

Code to Note:
int ledPins[] = {2,3,4,5,6,7,8,9}; 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. You refer to the elements in an array by their position. The first element is at position 0, the second is at position 1, etc. You refer to an element using "ledPins[x]" where x is the position. Here we're making digital pin 2 HIGH, since the array element at position 0 is "2". 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.

4
Circuit 2

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

digitalWrite(ledPins[0], HIGH);

index = random(8);

What you Should See:


This is similar to circuit number one, but instead of one LED, you should see all the LEDs blink. If they aren't, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.
715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

Troubleshooting:
Some LEDs Fail to Light It is easy to insert an LED backwards. Check the LEDs that aren't working and ensure they the right way around. Operating out of sequence With eight wires it's easy to cross a couple. Double check that the first 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.

Real World Application:


Scrolling marquee displays are generally used to spread short segments of important information. They are built out of many LEDs.

Circuit 2 CIRCUIT #5

Push Buttons
5 volt

PIN 13 RedBoard PIN 3 LED (Light-Emitting Diode) PIN 2 Buttons

Resistors (10K ohm) (Brown-Black-Orange)

Resistors (330 ohm) (Orange-Orange-Brown)

Up until now, weve focused solely on outputs. Now were going to go to the other end of spectrum and play around with inputs. In this circuit, well be looking at one of the most common and simple inputs a push button. The way a push button works with RedBoard is that when the button is pushed, the voltage goes LOW. The RedBoard reads this and reacts accordingly. In this circuit, you will also use a pull-up resistor, which keeps the voltage HIGH when you're not pressing the button.

GND (Ground)

PARTS:

IC Button Push
X

LED 1 2
X

10K 330 Resistor 1 8


X

330 Wire Resistor 2 8


X

Wire
X

19

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.36 p.10

Circuit 5: Push Buttons

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
d4 g4 d6 g6 d9 g9 d11 g11

Image Reference:
One of the things that makes the RedBoard 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 environment provides a set of logic operations that let you build complex "if" statements. They include:

How to use logic like a Vulcan:

Push Button

Push Button
h20 h21

LED (5mm) + i6 a15 +

10K Resistor

== != DIFFERENCE AND OR NOT

EQUIVALENCE

A == B is true if A and B are the SAME. A != B is true if A and B are NOT THE SAME. A && B is true if BOTH A and B are TRUE. A || B is true if A or B or BOTH are TRUE. !A is TRUE if A is FALSE. !A is FALSE if A is TRUE.

10K Resistor

i11 +

&&
j21
+

330 Resistor

|| !

Jumper Wire
i9

i4

Jumper Wire Pin 2 Pin 3 Pin 13


5V GND
+

You can combine these functions to build complex if() statements.

Jumper Wire
h11 j20

h6

For example: if ((mode == heat) && ((temperature < threshold) || (override == true))) { digitalWrite(HEATER, HIGH); }

Jumper Wire

Jumper Wire

Jumper Wire

...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 RedBoard to make intelligent decisions and take control of the world around it!

Jumper Wire

Code to Note:
pinMode(button2Pin, INPUT); The digital pins can be used as inputs as well as outputs. Before you do either, you need to tell the RedBoard which direction you're going.

5
Circuit 2

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

button1State = digitalRead(button1Pin);

To read a digital input, you use the digitalRead() function. It will return HIGH if there's 5V present at the pin, or LOW if there's 0V present at the pin.

if (button1State == LOW)

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

What You Should See:


You should see the LED turn on if you press either button, and off if you press both buttons. (See the code to find out why!) If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.
715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

Troubleshooting:
Light Not Turning On The pushbutton is square, and because of this it is easy to put it in the wrong way. Give it a 90 degree twist and see if it starts working. Underwhelmed No worries, these circuits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.

Real World Application:


The buttons we used here are similar to the buttons in most video game controllers.

Circuit 2 CIRCUIT #6

Photo Resistor
5 volt
PIN 9 LED (Light-Emitting Diode)

Photocell (Light Sensitive Resistor) PIN A0 RedBoard

Resistor (330 ohm) (Orange-Orange-Brown)

Resistor (10K ohm) (Brown-Black-Orange)

So youve already played with a potentiometer, which varies resistance based on the twisting of a knob. In this circuit, youll be using a photo resistor, which changes resistance based on how much light the sensor receives. Since the RedBoard cant directly interpret resistance (rather, it reads voltage), we use a voltage divider to use our photo resistor. This voltage divider will output a high voltage when it is getting a lot of light and a low voltage when it is not.

GND (Ground)

PARTS:

Photo Resistor
X

LED 1
X

330 Resistor 1
X

Wire 1
X

10K Resistor 6
X

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.40

Circuit 6 : Photo Resistor

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
f5 f6 h20 h21

Image Reference: Many of the sensors you'll use (potentiometers, photoresistors, etc.) are resistors in disguise. Their resistance changes in proportion to whatever they're sensing (light level, temperature, sound, etc.).

Measuring resistive sensors:

Photo Resistor

LED (5mm) + +

j21 i1 i5 j1
PIN A0 3 Pin 5 volts

330 Resistor (sensor)

The RedBoard's analog input pins measure voltage, not resistance. But we can easily use resistive sensors with the RedBoard by including them as part of a "voltage divider".

10K Resistor

Jumper Wire A0
j6 + j5

Jumper Wire

Jumper Wire Pin 9


j20 +

GND
(ground) (-)

Jumper Wire 5V GND

Jumper Wire

Jumper Wire

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 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! 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. Please note the fixed resistor isn't necessarily the bottom resistor. We do that with the photodiode only so that more light = more voltage, but it could be flipped and we'd get the opposite response.

Code to Note:
lightLevel = map(lightLevel, 0, 1023, 0, 255);
Parameters map(value, fromLow, fromHigh, toLow, toHigh) value: the number to map fromLow: the lower bound of the value's current range fromHigh: the upper bound of the value's current range toLow: the lower bound of the value's target range toHigh: the upper bound of the value's target range

6
Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 6
When we read an analog signal using analogRead(), it will be a number from 0 to 1023. But when we want to drive a PWM pin using analogWrite(), it wants a number from 0 to 255. We can "squeeze" the larger range into the smaller range using the map() function.
See http://arduino.cc/en/reference/map for more info.

lightLevel = constrain(lightLevel, 0, 255);


Parameters constrain(x, a, b) x: the number to constrain, all data types a: the lower end of the range, all data types b: the upper end of the range, all data types

Because map() could still return numbers outside the "to" range, we'll also use a function called constrain() that will "clip" numbers into a range. If the number is outside the range, it will make it the largest or smallest number. If it is within the range, it will stay the same.
See http://arduino.cc/en/reference/constrain for more info.

What You Should See:


You should see the LED grow brighter or dimmer in accordance with how much light your photoresistor is reading. If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.
715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

Troubleshooting:
LED Remains Dark This is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist. It Isn't Responding to Changes in Light Given that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check its in the right place. Still Not Quite Working You may be in a room which is either too bright or dark. Try turning the lights on or off to see if this helps. Or if you have a flashlight near by give that a try.

Real World Application:


A street lamp uses a light sensor to detect when to turn the lights on at night.

Circuit 2 CIRCUIT #7

Temperature Sensor
5 volt

TMP36 (Precision Temperature Sensor)


1 3 VCC VOUT 2 GND

PIN A0
RedBoard

A temperature sensor is exactly what it sounds like a sensor used to measure ambient temperature. This particular sensor has three pins a positive, a ground, and a signal. This is a linear temperature sensor. A change in temperature of one degree centigrade is equal to a change of 10 millivolts at the sensor output. The TMP36 sensor has a nominal 750 mV at 25C (about room temperature). In this circuit, youll learn how to integrate the temperature sensor with your RedBoard, and use the Arduino IDEs serial monitor to display the temperature.
When youre building the circuit be careful not to mix up the transistor and the temperature sensor, theyre almost identical. Look for TMP on the body of the temperature sensor.

GND (Ground)

PARTS:

Temp. Sensor
X

Wire 1
X

5
FRONT

GND SIGNAL +V

+V SIGNAL GND

BACK

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.44

Circuit 7: Temperature Sensor

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
f5 f6 f7
V OUT +

Image Reference:

Opening your serial monitor:

Temperature Sensor

GND SIGNAL +V

Jumper Wire A0
1

j5
j6

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. In order for the serial monitor to operate correctly it must be set to the same baud rate (speed in bits per second) as the code you're running. This code runs at 9600 baud; if the baud rate setting is not 9600, change it to 9600.

Jumper Wire
j7 + +
3

Jumper Wire 5V GND

Jumper Wire

Jumper Wire

7
Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 7
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. The Serial.print() command is very smart. It can print out almost anything you can throw at it, including variables of all types, quoted text (AKA "strings"), etc.
See http://arduino.cc/en/serial/print for more info.

Code to Note:
Serial.begin(9600);

Serial.print(degreesC);

Serial.println(degreesF);

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

What You Should See:


You should be able to read the temperature your temperature sensor is detecting on the serial monitor in the Arduino IDE. If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.

voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73 voltage: 0.73
A0 A1 A2

deg C: 23.24 deg F: 73.84 deg C: 23.24 deg F: 73.84 deg C: 23.24 deg F: 73.84 deg C: 22.75 deg F: 72.96 deg C: 23.24 deg F: 73.84 deg C: 23.24 deg F: 73.84 deg C: 23.24 deg F: 73.84 deg C: 22.75 deg F: 72.96 deg C: 23.24 deg F: 73.84 deg C: 22.75 deg F: 72.96 deg C: 22.75 deg F: 72.96 deg C: 23.24 deg F: 73.84 deg C: 22.75 deg F: 72.96 deg C: 23.24 T deg F: 73.84
715 V
IO RE RE F SE 3. T 3V 5V GN D

RE

PO

GN

SE

VI

ER

AN

L SC A SD EF AR ND G 13

A3

TX

AL O

A4

RX

A5

13

IN

12

~ ~ ~ 10

11

IS

D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1

RX

Troubleshooting:
Nothing Seems to Happen This program has no outward indication it is working. To see the results you must open the Arduino IDE's serial monitor (instructions on previous page). Gibberish is Displayed 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.

Real World Application:


Building climate control systems use a temperature sensor to monitor and maintain their settings.

Circuit 2 CIRCUIT #8

A Single Servo
No junction dot means no connection 5 volt

SIG V+ GND

W R B

PIN 9

RedBoard
GND (Ground)

Servos are ideal for embedded electronics applications because they do one thing very well that motors cannot they can move to a position accurately. By varying the pulse width of the output voltage to a servo, you can move a servo to a specific position. For example, a pulse of 1.5 milliseconds will move the servo 90 degrees. In this circuit, youll learn how to use PWM (pulse width modulation) to control and rotate a servo.

PARTS:

Servo
X

Wire 1
X

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.48

Circuit 8: A Single Servo

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
e5 e6 e7

Image Reference:
The 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.

Expand your horizons using Libraries:

Servo
e5 e6 e7

Jumper Wire

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.

Jumper Wire Pin 9


b5 a6 +
File Edit Sketch

Jumper Wire

a7

Jumper Wire

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 RedBoard. 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/. When YOU get the RedBoard working with a new device, consider making a library for it and sharing it with the world! To use a library in a sketch, select it from Sketch > Import Library.
Tools Verify / Compile Help

Jumper Wire 5V GND


+

Jumper Wire

Show Sketch Folder Add File... Import Library

Jumper Wire

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

Code to Note:
#include <Servo.h> #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.

8
Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 8

Servo servo1; servo1.attach(9);

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).
The servos in this kit 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.
IO RE RE F SE 3. T 3V 5V GN

715 V

servo1.write(180);

RE

PO

GN

SE

VI

ER

A0

A1

A2 A3 A4 A5

AN

L SC A SD EF AR ND G 13

TX

LO G

RX 13

IN

What You Should See:


You should see your servo motor move to various locations at several speeds. If the motor doesn't move, check your connections and make sure you have verified and uploaded the code, or see the troubleshooting tips below.

12

~ ~ ~ 10

11

IS P O N
RX TX

9 8

D 7 IG 6 IT ~ AL ~5 4 ( P W 3 M ~ ~ 2 ) 1

Troubleshooting:
Servo Not Twisting Even with colored wires it is still shockingly easy to plug a servo in backward. This 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 flashing 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.

Real World Application:


Robotic arms you might see in an assembly line or sci-fi movie probably have servos in them.

CIRCUIT #9 Flex Sensor


5 volt

Resistor (10K ohm) (Brown-Black-Orange)


SIG V+ GND
W R B

PIN 9

PIN A0

RedBoard Flex Sensor GND (Ground)

In this circuit, we will use a flex sensor to measure, well, flex! A flex sensor uses carbon on a strip of plastic to act like a variable resistor, but instead of changing the resistance by turning a knob, you change it by flexing (bending) the component. We use a "voltage divider" again to detect this change in resistance. The sensor bends in one direction and the more it bends, the higher the resistance gets; it has a range from about 10K ohm to 35K ohm. In this circuit we will use the amount of bend of the flex sensor to control the position of a servo.

PARTS:

Flex IC Sensor Potentiometer

Servo LED 11
X

330 10K Resistor Resistor 8


X

Wire
X

X X

8 X1

11

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.10 p.52

Circuit 9: Flex Sensor

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
e1 e2 e3

Image Reference:

Debugging your sketches using the Serial Monitor:

Servo
e1 e2
e3

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 RedBoard have no such things.

Jumper Wire

Jumper Wire
h19 h20 i20 i24 i19

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

Flex Sensor

10K Resistor

Jumper Wire A0
h24 + b1 + h24 a2 + h24 j20

for (x = 0; x < 8; x++) { Serial.print(x); }

Let's say you wanted a for() loop from 1 to 8, but your code just doesn't seem to be working right. Just add Serial.begin(9600); to your setup() function, and add a Serial.print() or println() to your loop:

Jumper Wire

Jumper Wire

You wanted 1 to 8, but the loop is actually giving you 0 to 7. Whoops! Now you just need to fix the loop.
01234567

Jumper Wire

Jumper Wire Pin 9 5V GND


+ a3

Jumper Wire

And if you run the code again, you'll see the output you wanted: for (x = 1 ; x < 9 ; x++) { Serial.print(x); }
12345678

Jumper Wire

Jumper Wire

Circuit 2

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

Code to Note:

servoposition = map(flexposition, 600, 900, 0, 180); map(value, fromLow, fromHigh, toLow, toHigh)

Because the flex sensor / resistor combination won't give us a full 0 to 5 volt range, we're using the map() function as a handy way to reduce that range. Here we've told it to only expect values from 600 to 900, rather than 0 to 1023.

servoposition = constrain(servoposition, 0, 180); constrain(x, a, b)

Because map() could still return numbers outside the "to" range, we'll also use a function called constrain() that will "clip" numbers into a range. If the number is outside the range, it will make it the largest or smallest number. If it is within the range, it will stay the same.

What You Should See:


715 V

You should see the servo motor move in accordance with how much you are flexing the flex sensor. If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 W 3 M ~ ~ 2 ) 1 P (P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

Troubleshooting:
Servo Not Twisting Even with colored wires it is still shockingly easy to plug a servo in backwards. This might be the case. Servo Not Moving as Expected The sensor is only designed to work in one direction. Try flexing it the other way (where the striped side faces out on a convex curve). Servo Doesnt Move very Far You need to modify the range of values in the call to the map() function.

Real World Application:


Controller accessories for video game consoles like Nintendos Power Glove use flex-sensing technology. It was the first video game controller attempting to mimic hand movement on a screen in real time.

Circuit 2 CIRCUIT #5 #10

Soft Potentiometer
RedBoard

10

PIN 11

5 volt
RedBoard

PIN 10 PIN 9
Resistors (330 ohm) (Orange-Orange-Brown)

PIN A0

Soft Pot

Resistor (10K ohm) (Brown-Black-Orange)

LED (Light-Emitting Diode)

In this circuit, we are going to use yet another kind of variable resistor this time, a soft potentiometer (or soft pot). This is a thin and flexible strip that can detect where pressure is being applied. By pressing down on various parts of the strip, you can vary the resistance from 100 to 10K ohms. You can use this ability to track movement on the soft pot, or simply as a button. In this circuit, well get the soft pot up and running to control an RGB LED.

BLUE

GREEN

GND (Ground)

RED

PARTS:

LED IC
X

330 LED Soft Potentiometer Resistor 1


X

Wire 330 Resistor 3 8 1


X

330 Resistor
X

10K Resistor
X

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.10 p.56

Circuit 10: Soft Potentiometer

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
a4 a5 a6 a7

Image Reference: Jumper Wire Jumper Wire GND 5V


+

Component:

Image Reference:

RGB LED (5mm)


5V
h18 h19 h20

Soft Potentiometer 5V 5V 5V
i19

330 Resistor
e6 e1 g6 e7 1 g7 e7 e1 1

e4 e1 g4 e7 1

330 Resistor

330 Resistor

10K Resistor Pin 9


e5 h4

Jumper Wire

Jumper Wire Pin 10 Pin 11


j18 + h7 h6

Jumper Wire

Jumper Wire

Jumper Wire
A0
j19
j20

Jumper Wire

Jumper Wire

10
Circuit 2

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

Code to Note:
These big, scary functions take a single Value (RGBposition) and calculate the three RGB values necessary to create a rainbow of color. The functions create three "peaks" for the red, green, and blue values, which overlap to mix and create new colors. See the code for more information! Even if you're not 100% clear how it works, you can copy and paste this (or any) function into your own code and use it yourself. If you want to know more about creating your own functions - take a look at circuit #11.

redValue = constrain(map(RGBposition, 0, 341, 255, 0), 0, 255) + constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255);

greenValue = constrain(map(RGBposition, 0, 341, 0, 255), 0, 255) - constrain(map(RGBposition, 341, 682, 0,255), 0, 255);

blueValue = constrain(map(RGBposition, 341, 682, 0, 255), 0, 255) - constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255);

What You Should See:


You should see the RGB LED change colors in accordance with how you interact with the soft potentiometer. If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board, or see the troubleshooting tips below.
A0 A1 A2 A3 A4 A5

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

A 0

LO G

RX 13

IN ~ ~ 9 8

12

~ 10

11

Troubleshooting:
LED Remains Dark or Shows Incorrect Color With the four pins of the LED so close together, its sometimes easy to misplace one. Try double checking each pin is where it should be. 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.

Real World Application:


The knobs found on many objects, like a radio for instance, are using similar concepts to the one you just completed for this circuit.

Circuit 2 CIRCUIT #11

Buzzer

11

Piezo Buzzer RedBoard


PIN 9

In this circuit, we'll again bridge the gap between the 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 off hundreds of times a second, the buzzer will produce a tone. And if you string a bunch of tones together, you've got music! This circuit and sketch will play a classic tune. We'll never let you down!

GND (Ground)

PARTS:

Piezo Element
X

Wire 1
X

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
TX RX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

If the buzzer doesn't easily t into the holes on the breadboard, try rotating it slightly.

p.60

Circuit 11: Piezo Elements

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
f9 f7

Image Reference:

Creating your own functions:


+ -

Piezo Element
i7

Jumper Wire Pin 9 GND


x = parameter1 + parameter2; } return(x); int add(int parameter1, int parameter2) { int x; j9

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 "add," which adds two numbers together and returns the result. Let's break it down.

Jumper Wire

Jumper Wire

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

11
Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 11
Up until now we've been working solely with numerical data, but the Arduino can also work with text. Characters (single, printable, letters, numbers and other symbols) have their own type, called "char". When you have an array of characters, it can be defined 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. This function drives an output pin at a certain frequency, making it perfect for driving buzzers and speakers. If 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() ).

Code to Note:

char notes[] = "cdfda ag cdfdg gf "; char names[] = {'c','d','e','f','g','a','b','C'};

tone(pin, frequency, duration);

What You Should See:


715

You should see - well, nothing! But you should be able to hear a song. If it isn't working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting tips below.

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL O 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

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. Can't Think 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 The code is written so you can easily add your own songs.

Real World Application:


Many modern megaphones have settings that use a loud amplified buzzer. They are usually very loud and quite good at getting peoples attention.

Circuit 2 CIRCUIT #12

Spinning a Motor
5 volt

12

Diode (1N4148)

DC Motor

RedBoard PIN 9 Resistor (330 ohm) (Orange-Orange-Brown)

Transistor (P2N2222AG) GND (Ground)

Remember before when you played around with a servo motor? Now we are going to tackle spinning a motor. This requires the use of a transistor, which can switch a 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. The transistor we are using for this circuit is rated at 40V max and 200 milliamps max perfect for our toy motor! When the motor is spinning and suddenly turned off, the magnetic field inside it collapses, generating a voltage spike. This can damage the transistor. To prevent this, we use a "flyback diode", which diverts the voltage spike around the transistor.
When youre building the circuit be careful not to mix up the transistor and the temperature sensor, theyre almost identical. Look for P2N2222A on the body of the transistor.

PARTS:

P2N2222AG

Transistor
X

1N4148

Diode
X

DC Motor 1
X

Wire 1
X

330 Resistor 6
X

P2N2 222A

EMITTER BASE COLLECTOR

FRONT
COLLECTOR BASE EMITTER

BACK
715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.64

Circuit 12 : Spinning a Motor

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
a1 a2 a3
E B C

Image Reference:
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:
e7 e11

Putting it all together:

P2N2 222A

Transistor P2N2222AG
GND b7

EMITTER BASE COLLECTOR

Diode 1N4148

b11 a3

DC Motor 5V
e1 e2 e1 g2 e7 1

330 Resistor

1. Perform some sort of input 2. Make some calculations or decisions 3. Perform some sort of output 4. Repeat! (Or not!) 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.

Jumper Wire Pin 9


a7 e3 d11 + j2

Jumper Wire

Jumper Wire

Jumper Wire 5V 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.)

Jumper Wire

Jumper Wire

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. Be sure to let us know on https://www.sparkfun.com/project_calls so we can put it on our home page!

12
Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 12
The 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 "buffers" data coming into the port until you're ready to use it. The 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.

Code to Note:

while (Serial.available() > 0)

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.
715 V

What You Should See:


GN D GN D VI N
A0 A1

IO RE F T RE 3. 3V 5V SE

RE

PO

SE

ER

The DC Motor should spin if you have assembled the circuits components correctly, and also verified/uploaded the correct code. If your circuit is not working check the troubleshooting section below.

A2 A3 A4 A5

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 W 3 M ~ ~ 2 ) 1 P (P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

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 RedBoard will disconnect from the computer. Try un-plugging and then re-plugging it into your USB port.

Real World Application:


Radio Controlled(RC) cars use Direct Current(DC) motors to turn the wheels for propulsion.

Circuit 2 CIRCUIT #5 #13

Relays
5 volt
Resistor (330 ohm) (Orange-Orange-Brown)

13 5
When the relay is off, the COM (common) pin will be connected to the NC (Normally Closed) pin. When the relay is on, the COM (common) pin will be connected to the NO (Normally Open) pin.

Diode (1N4148) SPDT Relay Transistor (P2N2222AG)


LEDs (Light-Emitting Diodes)

In this circuit, we are going to use some of the lessons we learned in circuit 12 to control a relay. A relay is basically an electrically controlled mechanical switch. Inside that harmless looking plastic box is an electromagnet that, when it gets a jolt of energy, causes a switch to trip. In this circuit, youll learn how to control a relay like a pro giving your RedBoard even more powerful abilities!

RedBoard

PIN 2
Resistor (330 ohm) (Orange-Orange-Brown)

GND (Ground)

PARTS:

IC Relay
X

P2N2222AG

Transistor LED
X

1N4148
X

Diode
X

330 Resistor 1
X

LED 2
X

Wire 2
X

14

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.10 p.68

Circuit 13: Relays

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
e14 e9 f15 f13 f9
a2 a3 a4
E B C

Image Reference: Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire
j3 j7 j5 h9 i13 e22 i13 i15 e19 + j9

Component:

Image Reference:
f7 f5 f6e19 e15

Relay

P2N2 222A

Transistor P2N2222AG

EMITTER BASE COLLECTOR

+ e19 + e15 a23 + e19 + e15 a20 e19 + b14 a7 a9 e4 b9

LED (5mm) + f7 a3

c22 c23

+
c19 c20

LED (5mm) +
GND e7

Diode 1N4148 5V 5V
e2
b14 +1 e7 e1 e3 e1 g3 e7 1

330 Resistor

330 Resistor

5V GND

Jumper Wire Pin 2

Jumper Wire

Jumper Wire

Jumper Wire

Jumper Wire

Jumper Wire

13
Circuit 2

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

Code to Note:
When we turn on the transistor, which in turn energizes the relay's coil, the relay's switch contacts are closed. This connects the 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.)

digitalWrite(relayPin, HIGH);

digitalWrite(relayPin, LOW);

The relay has an additional contact called NC (Normally Closed). The NC pin is connected to the COM pin when the relay is OFF. You can use either pin depending on whether something should be normally on or normally off. You can also use both pins to alternate power to two devices, much like railroad crossing warning lights.

What You Should See:


V 15 7-

You should be able to hear the relay contacts click, and see the two LEDs alternate illuminating at 1-second intervals. If you don't, double-check that you have assembled the circuit correctly, and uploaded the correct sketch to the board. Also, see the troubleshooting tips below.

FF REE OR EETT IIO ESS RRE VV .33 33.

V PO 55V DD O W N WE GGN DD E R N R GGN INN VVI


0 AA0 1 AA1 2 AA2

RE R E SS EETT

AAN N AALL OO G G IISS PP OO N N


R RX X T TX X

CLL SSC AA D SSD EEFF R AAR NNDD GG 1133 2 112 1 1133 111 ~~ 100 RRXX 1 ~~ ~99 TTXX ~ 8 8 DD I 77 I GG 66 I ITT ~~ 5 AA 5 ~ L ~ L ((PP 44 W 33 W M ~~ M ~~ ) 22 ) 11

3 AA3
AA44 AA55

IINN

00

Troubleshooting:
LEDs Not Lighting Double-check that you've plugged them in correctly. The longer lead (and non-flat edge of the plastic flange) is the positive lead. 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).
When youre building the circuit be careful not to mix up the temperature sensor and the transistor, theyre almost identical.

Real World Application:


Garage door openers use relays to operate. You might be able to hear the clicking if you listen closely.

Circuit 2 CIRCUIT #14

Shift Register
5 volt Resistors (330 ohm) (Orange-Orange-Brown)

14
QB QC QD QE QF QG QH GND 1 2 3 4 5 6 7 8 16 15 14 13 12 11 10 9 VCC QA SER OE RCLK SRCLK SRCLR QH

PIN 2

14 11 10 12 13 8

SER SCK SCL RCK OE GND

VCC QA QB QC QD QE QF QG QH QH*

16 15 1 2 3 4 5 6 7 9

PIN 3 PIN 4

Now we are going to step into the world of ICs (integrated circuits). In this circuit, youll learn all about using a shift register (also called a serial-to-parallel converter). The shift register will give your RedBoard an additional eight outputs, using only three pins on your board. For this circuit, youll practice by using the shift register to control eight LEDs.
LEDs (Light-Emitting Diodes)

RedBoard

74HC595
GND (Ground)

*Do not connect pin 9

PARTS:

IC
X

LED 1
X

330 Resistor 8
X

Wire 8
X

19

Align notch on top, inbetween e5 and f5 on the breadboard. The notch indicates where pin 1 is.

Bend legs to 90 angle.

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 I TA ~ 5 L ~ 4 (P W 3 M ~ ~ 2 P O N )
TX RX

L SC A SD EF AR ND G 13

TX

AL O 1 0

RX

G IN 8

13 ~ ~ ~ 9 10 11

12

p.72

Circuit 14: Shift Register

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component:
e5 e6 e7 e8 e9 e10 e11 e12
f5 f6 f7 f8 f9 f10 f11 f12

Image Reference: Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire
GND j21 GND j24 GND +

Component:

Image Reference:
+ a3

IC
c14 c15

LED (5mm)
+ c17 c18

+
c20 c21

j5 GND j6 GND

+ a3
a14 a3

LED (5mm)
+
c23 c24

LED (5mm)
+
h14 h15

Pin 2

j7
j8 GND
a1 4 a3

LED (5mm)
+
h17 h18

LED (5mm)
+
h20 h21

Pin 4 Pin 3

j9 j10
j11 GND f14 GND f17 GND f20 GND f23 GND a23 GND a20 GND a17 GND +4 a1 a3 a8 a3 a9 a3 a10 a3 a11 a3 a7 a3 a6 a3 a5 a3

LED (5mm)
+
h23 h24

LED (5mm)
+

LED (5mm)
a15 a3
GND c23 GND c23 GND c23 GND j15 GND j18

330 Resistor
a18 a3 a21 a3 a24 a3
c24 a3 c24 a3 c24 a3 c24 a3

330 Resistor

330 Resistor

330 Resistor

330 Resistor

330 Resistor

330 Resistor

5V
Jumper Wire
+ GND + a3

+ j10

330 Resistor

GND

Jumper Wire

14
Circuit 2

Arduino Code:
Open Arduino IDE // File > Examples > SIK Guide > Circuit # 14
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

Code to Note:

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. The MSBFIRST parameter specifies the order in which to send the individual bits, in this case we're sending the Most Significant Bit first.

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. 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 off. The RedBoard has several commands, such as bitWrite(), that make this easy to do.

bitWrite(data, desiredPin, desiredState);

What You Should See:


IO RE RE

715 V

You should see the LEDs light up similarly to circuit 4 (but this time, you're using a shift register). If they aren't, make sure you have assembled the circuit correctly and verified and uploaded the code to your board. See the troubleshooting tips below.

SE T

3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L (P 4 W 3 M ~ ~ 2 ) 1 P O N
RX TX

L SC A SD EF AR ND G 13

TX

A 0

LO G

RX 13

IN ~ ~ 9 8

12

~ 10

11

Troubleshooting:
The RedBoard's power LED goes out This happened to us a couple of times, it happens when the chip is inserted backward. If you fix it quickly 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]

Real World Application:


Similar to circuit #4, a scrolling marquee display delivers a message with multiple LEDs. Essentially the same task the shift register achieves here in Circuit #14.

Circuit 2 CIRCUIT #5 #15

LCD
16x2 LCD
VDD DB0 DB1 DB2 DB3 DB4 DB5 DB6

15

5 volt

In this circuit, youll learn about how to use an 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 program your board. In this circuit, youll learn the basics of incorporating an LCD into your project.
PIN 2 PIN 3 PIN 4 PIN 5 PIN 11 PIN 12

DB7

R/W

VSS

RS

VO

GND (Ground)

PARTS:

IC LCD
X X

LED Potentiometer 330 Wire Resistor 1


X

16 8

RedBoard

Wire
X

19

715 V

IO RE F T RE 3. 3V 5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

SE

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ AL ~5 (P 4 W 3 P O N M ~ ~ )
TX

L SC A SD EF AR ND G 13

TX

AL O 2
RX

RX

G IN 8 1 0

13 ~ ~ ~ 9 10 11

12

p.76

Circuit 15: LCD

a b c d e

f g h i

RESET

7-15V

13 RX TX

IOREF

RESET

3.3V

5V

GND

POWER DIGITAL (PWM~)


7 ~6 ~5 4 ~3 2 TX 1 RX 0

GND

SCL SDA AREF GND 13 12 ~11 ~10 ~9 8

VIN

A0

A1

A2

A3

ON

ANALOG IN

A4

A5

ISP

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

a b c d e

f g h i

1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 20 2 1 22 23 24 25 26 27 28 29 30

Component: Component:
j30 j29 j28 j27 j26 j25 j24 j23 j22 j21 j20 j19 j18 j17 j16 j15
b8 b7 b6

Image Reference: Jumper Wire

Image Reference:

LCD Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire Jumper Wire

Pin 3 Pin 4 Pin 5 Pin 11

f18

f19 f20 f25


f26 GND

a3

Pin 12

f27
f29 GND + a3 f30 a3

Potentiometer

Jumper Wire

5V GND
e6 GND + a3 f28 a3 e7 GND e8 GND

+ j10

Jumper Wire

Jumper Wire

Jumper Wire
a3 a3
f16 GND + a3

Jumper Wire
f15 GND

Jumper Wire

Jumper Wire

Jumper Wire

Pin 2

f17 j10

15
Circuit 2

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

Code to Note:

#include <LiquidCrystal.h>

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

lcd.print(hello, world!);

This is the first time youll fire something up on your screen. You may need to adjust the contrast to make it visible. Twist the potentiometer until you can clearly see the text!

What you Should See:


IO RE F T RE 3. 3V SE

715 V

Initially, you should see the words hello, world! pop up on your LCD. Remember you can adjust the contrast using the potentiometer if you cant make out the words clearly. If you have any issues, make sure your code is correct and double-check your connections.

5V GN D GN D VI N
A0 A1 A2 A3 A4 A5

RE

PO

SE

ER

AN IS D 7 IG 6 IT ~ 5 A ~ L 4 W 3 M ~ ~ 2 ) 1 P (P O N
RX TX

L SC A SD EF AR ND G 13

TX

AL 0

RX

O G 8

13

IN ~ ~ 9

12

~ 10

11

Troubleshooting:
The Screen is Blank or Completely Lit? Fiddle with the contrast by twisting the potentiometer. If its incorrectly adjusted, you wont be able to read the text. Not Working At All? Double check the code, specifically that you include the LCD library. Screen Is Flickering Double check your connections to your breadboard and Arduino.

Real World Application:


LCDs are everywhere! From advanced LCDs like your television, to simple notification screens, this is a very common and useful display!

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:

Begin your Journey into Electronics


This kit will guide you through experiments of varying difculty as you learn all about embedded systems, physical computing, programming and more! This kit is perfect for anyone who wants to explore the power of the RedBoard platform.

The SparkFun Inventors Kit teaches basic programming, for which you will need both a computer and an internet connection.

You will also learn to assemble 15 basic physical electronic circuits, but no soldering is required. No previous experience is necessary!

KIT INCLUDES

SparkFun RedBoard Breadboard Instruction booklet Sealed relay Small servo Yellow and red LEDs

RGB LED Temperature sensor DC motor 8-bit shift register Push button switches Potentiometer

Photoresistor Transistors Jumper wires USB cable Signal diodes 10k ohm resistors

330 ohm resistors Piezo buzzer Flex sensor Soft potentiometer Baseplate LCD

SparkFun Electronics, inc. All rights reserved. The SparkFun Inventors kit for the SparkFun RedBoard features, specications, 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 Inventors 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