sfe sik redboard guide version3.0 online
TRANSCRIPT
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
1/84
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54~
32
10
TX RX 13
3.3V5VGN
DGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
SIK GUIDEYour guide to the SparkFun Inventors Kit for the SparkFun RedBoard
EF
T
7
~6
~5
TX DIGITAL(PWARDUINOL
ANGUAGEDEVELOPMENTPLATFORM
Version 3.0
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
2/84
e SparkFun Inventor's Guide is your map for navigating thewaters of beginning embedded electronics. is booklet contains
all the information you will need to explore the 15 circuits of theSparkFun Inventor's Kit for Educators. At the center of thismanual 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 andexperiments. Now enough talking - let's get inventing!
www.sparkfun.com
Welcome to the SparkFun Inventors Guide
Table of Contents
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
3/84
What is the RedBoard platform? 1
Download Arduino Software (IDE) 3
Install Drivers 4
Identify Your Hardware 7
Download SIK Guide Code 8
The World Runs on Circuits 9
Inventory of Parts 11
13
15
17
24
28
32
36
40
44
48
52
Section 2: Getting Started with Circuits
Section 1: Getting Started
RedBoard
Breadboard
Circuit #1 - Your First Circuit: Blinking a LED
Circuit #3 - RGB LED
Circuit #4 - Multiple LEDs
Circuit #5 - Push Buttons
Circuit #6 - Photo Resistor
Circuit #7 - Temperature Sensor
Circuit #8 - A Single Servo
Circuit #9 - Flex Sensor
56Circuit #10 - Soft Potentiometer
60Circuit #11 - Piezo Element
64Circuit #12 - Spinning a Motor
68Circuit #13 - Relay
72Circuit #14 - Shift Register
76Circuit #15 - LCD
Circuit #2 - Potentiometer
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
4/84
We live in a unique time where we have access to resources
that allow us to create our own solutions and inventions. eDIY revolution is composed of hobbyists, tinkerers andinventors who would rather craft their own projects than letsomeone do it for them.
www.sparkfun.com
The DIY Revolution
What is the RedBoard platform?
FPO
FPO
e RedBoard in your hand (or on your desk) is yourdevelopment platform. At its roots, the RedBoard isessentially a small portable computer. It is capable oftaking inputs (such as the push of a button or a readingfrom a light sensor) and interpreting that information tocontrol various outputs (like a blinking LED light or anelectric motor).
at's where the term "physical computing" is born -this board is capable of taking the world of electronicsand relating it to the physical world in a real and tangible
way. Trust us - this will all make more sense soon.
A Computer for the Physical World
RedBoard
// SparkFun RedBoard
e SparkFun RedBoard is one of a multitude ofdevelopment boards based on the ATmega328. It has 14digital input/output pins (6 of which can be PWMoutputs), 6 analog inputs, a 16 MHz crystal oscillator, aUSB connection, a power jack, an ISP header, and a resetbutton. Dont worry, youll learn about all these later.
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
5/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
6/84
In order to get your RedBoard up and running, you'll need todownload the newest version of the Arduino software first from
www.arduino.cc (it's free!). is software, known as the ArduinoIDE, will allow you to program the board to do exactly what you
want. Its like a word processor for writing programs. With aninternet-capable computer, open up your favorite browser andtype in the following URL into the address bar:
Access the Internet
Download the Arduino IDE (Integrated Development Environment)
user
Windows
Mac OS X
Linux: 32 bit, 64 bit
N
W
S
ENW
SW
SE
NE
arduino.cc/en/main/software
Choose the appropriate Operating System installation package for your computer.
DownloadClick on your appropriate computeroperating system next to the + sign.
Windows
Mac OS X
source
Linux: 32 bit, 64 bit
1
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
7/84
// Connect your RedBoard to your Computer
Use the USB cable provided in the SIK kit to connect the RedBoard toone of your computers USB inputs.
// Install Arduino DriversDepending on your computers operating system, you will need to follow specificinstructions. Please go to https://learn.sparkfun.com/tutorials/how-to-install-ftdi-driversfor specific instructions on how to install the FTDI drivers onto your RedBoard.
23
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10
~9
8
7~6
~54
~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
8/84
1 2 3 5 6
7
8
9
4
Open the Arduino IDE software on your computer. Poke around and get to knowthe interface. We arent going to code right away, this is just an introduction. isstep is to set your IDE to identify your RedBoard.
// Open the Arduino IDE:
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
9/84
// The three most important commands for this guide are seen below:
GUI (Graphical User Interface)
Verify: Compiles and approves your code. It will catch errors in syntax (like missing semi-colons or parenthesis). //See Diagram Below1
Upload: Sends your code to the RedBoard. When you click it, you should see the lights on your board blink rapidly.//See Diagram Below2
New: This buttons opens up a new code window tab.3
Open: This button will let you open up an existing sketch.//See Diagram Below4
Save: This saves the currently active sketch.5
Serial Monitor: This will open a window that displays any serial information your RedBoard is transmitting. It is very useful for debugging.6
Code Area: This is the area where you compose the code for your sketch.8
Message Area: This is where the IDE tells you if there were any errors in your code.9
Sketch Name:This shows the name of the sketch you are currently working on.7
Verify
Upload
Open
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
10/84
File Edit Sketch Tools Help
Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor
Arduino UnoArduino 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/ ATmega328LilyPad 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
Programmer
Burn Bootloader
BoardSerial Port
// Select your board: Arduino Uno
Select the serial device of the RedBoard from the Tools |
Serial Port menu. is is likely to be com3 or higher(COM1 and COM2 are usually reserved for hardwareserial ports). To find out, you can disconnect yourRedBoard and re-open the menu; the entry thatdisappears should be the RedBoard. Reconnect the
board and select that serial port.
Select the serial device of the RedBoard from the Tools> Serial Port menu. On the Mac, this should be
something with /dev/tty.usbmodem or/dev/tty.usbserialin it.
http://www.arduino.cc/playground/Learning/Linux
Tools Help
Auto FormatArchive Sketch
Fix Encoding & Reload
Serial Monitor
com 1
com 12Programmer
Burn Bootloader
Board
Serial Port
Tools Help
Auto Format
Archive Sketch
Fix Encoding & Reload
Serial Monitor
/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
Programmer
Burn Bootloader
Board
Serial Port
//SelectyourSerialDevice
4
Note:Your SparkFun RedBoard and the
Arduino UNO are interchangeablebut you wont find the RedBoard
listed in the Arduino Software.
Select Arduino UNO instead.
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
11/84
Type in the following URL to download the code:
Download Arduino Code (For use with the circuits in this guide)
sparkfun.com/sikcode
5
Unzip the file SIK Guide Code. Itshould be located in your browsersDownloadsfolder. Right click thezipped folder and choose unzip.
Copy the SIK Guide Code folder into Arduinosfolder named examples.
Copy the SIK Guide Code folder intoArduinos folder named examples.
WHATS NEXT? Read on to learn more about getting started with circuits. en you can start on your first circuit on page 17!
Unzip the file SIK Guide Code. Itshould be loacted in your browsersDownloadsfolder. Right click thezipped folder and choose unzip.
Find Arduino in your applicationsfolder. Right click(ctrl + click) onArduino. Select Show PackageContents.
http://www.arduino.cc/playground/Learning/Linux
//CopySIKGuideCodeintoExamp
leslibraryinArduinof
older
ProgramsStart arduino examples
Contents
Resources
Java
examplesArduino
Move to Trash
Open
Show Package Contents
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
12/84
Everywhere you look, you'll find circuits. e cellphone in your pocket, the computer that controlsyour car's emissions system, your video gameconsole - all these things are chock full of circuits.In this guide, you'll experiment with some simplecircuits and learn the gist of the world of embedded
electronics.
The World Runs on Circuits:
Getting Started with Circuits
A circuit is basically an electrical loop with a starting point and an
ending point - with any number of components in between.Circuits can include resistors, diodes, inductors, sensors of all sizesand shapes, motors, and any other handful of hundreds ofthousands of components.
Circuits are usually divided into three categories - analog circuits,digital circuits, or mixed-signal circuits. In this guide, you willexplore all three sets of circuits.
What is an Electrical Circuit?
// Simple and Complex Circuits
In this guide, you will be primarily exploringsimple circuits - but that doesn't mean you can'tdo amazing things with simple tools! When you'vefinished the SIK, your knowledge of circuits willenable you to explore amazing projects andunleash the power of your imagination.
a b c d e f g h i1
2
3
4
5
6
7
8
9
10
11
12
13
14
1516
17
18
19
20
21
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
10
11
12
13
14
1516
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
13/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
14/84
Inventory of Parts
* ACTUAL SIZE
(1N4148)
Diode
x2
x1
Piezo Element
Various Colors
Jumper Wire
x30
Push Button
x2x1
DC Motor
x1
DC Motor
x1
Potentiometer
(Light Emitting Diode)
x10 x10 x1
LED (5mm) +-
330 Resistor
x25* ACTUAL SIZE
10K Resistor
x25* ACTUAL SIZE
(TMP36)
x1
Temp. Sensor
FRONT
BACK
(P2N2222AG)
x2
Transistor
P2N2
222A
A18
FRONT
BACK
x1
Photo Resistor
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
15/84
Standard Solderless
Breadboard
a b c d e f g h i1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2021
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
10
11
12
13
14
15
16
17
18
19
2021
22
23
24
25
26
27
28
29
30
Standard Solderless (Color may vary)
Breadboard
a b c d e f g h i1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2021
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
10
11
12
13
14
15
16
17
18
19
2021
22
23
24
25
26
27
28
29
30
SparkFun RedBoardFlex Sensor
x1
Soft Potentiometer
x1
Servo
x1
Relay
x1
x1
x1
LCD
x1
(IC)
Integrated Circuit
x1
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
16/84
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11~10
~9
8
7
~6
~5
4
~3
2
10
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
1
2
8
6
9
7
4 3 5
10
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
17/84
// Pins Diagram
SparkFun RedBoard
RFU- This pin is reserved for future use.11
Power In (Barrel Jack) - Can be used with either a 9V or 12V wall-wart or battery.1
Power In (USB Port) - Provides power and communicates with your board when plugged into your computer via USB.2
LED (RX: Receiving) - This shows when the FTDI chip is receiving data bits from the microcontroller. This happens when the microcontroller issending data bits back to the computer.3
LED (TX: Transmitting) - This shows when the FTDI chip is transmitting data bits to the microcontroller. This happens when themicrocontroller is receiving this data from the computer.
4
LED (Pin 13: Troubleshooting) - This LED is incorporated into your sketch to show if your program is running properly.5
Pins (ARef, Ground, Digital, Rx, Tx) - These various pins can be used for inputs, outputs, power, and ground.// See Diagram Below6
LED (Indicates RedBoard is ON) - This is a simple power indicator LED.7
Reset Button- This is a way to manually reset your RedBoard, which makes your code restart.8
Pins (Analog In, Power In, Ground, Power Out, Reset) - These various pins can be used for inputs, outputs, power, and ground. //See Diagram10
ICSP Pins (Uploading Code without Bootloader) - This is for "In-Circuit Serial Programming," used if you want to bypass the bootloader.9
Power Out
Reset
IOREF
Power Out
Ground
Ground
Power In
Analog
Analog
Analog
Analog
Analog
Analog
Ground
ARef
SDA
SCL
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
Digital
TX - Out
RX - In
10
11
6
= PWM/Analog out compatible (i.e. )
The header pins are one of the most important parts for putting our
example circuits together. Take a moment and locate the input/output
ports of your RedBoard.
RFU
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
18/84
a b c d e f g h i1
2
3
4
56
7
8
9
10
11
12
13
14
15
1617
18
19
20
21
22
23
24
25
26
27
28
29
30
a b c d e f g h i
1
2
3
4
56
7
8
9
10
11
12
13
14
15
1617
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.
1
2
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
19/84
Power:
Each + sign runs power anywhere in the
vertical column.
Ground:
Each - sign runs to ground anywhere in the
vertical column.
Horizontal Rows:
Each of these rows numbered 1-30 are
comprised of five horizontal sockets.
Components placed in the same row will be
connected in a circuit when power is running.
Vertical Connection (+ Power and - Ground) - Power bus// See Diagram Below1
Horizontal Connection (a-e & f-j)// See Diagram Below)2
Hows it all connected?
View of the inside
f g h ia b c d e1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1617
18
19
20
21
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
10
11
12
13
14
15
1617
18
19
20
21
22
23
24
25
26
27
28
29
30
Breadboard
Above the breadboard
CONNECTED!
LED
Making a Connection:
Inside the breadboard
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
20/84
How It Works:
ASSEMBLE WRITE UPLOAD
Peel scker off back of
breadboard and sck into place.
Make sure the text on the RedBoard and
breadboard are facing up so you can read them.
a b c d e f g h i1
2
3
45
6
7
8
910
11
12
1314
15
16
17
1819
20
21
2223
24
25
26
2728
29
30
a b c d e f g h i
1
2
3
45
6
7
8
910
11
12
1314
15
16
17
1819
20
21
2223
24
25
26
2728
29
30
Screw the RedBoard down and into place.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6
~5
4~3
21
0
TX R
X 13
3.3V5VGNDG
NDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
Connect the USB cable.
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
CIRCUIT #1 - Your First Circuit
Your RedBoard runs on 5V. is is the power that will be supplied from your computer via USB andwill be the driving force behind any components you use in your circuits. By plugging your RedBoardinto 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 thebarrel jack. e on-board voltage regulator can handle anything from 7 to 15VDC.
IOREF
RESET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
21/84
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
PART
S: LED
1X
Wire
3X
330
Resistor
1X This secon lists the parts you
will need to complete the circuit.
Circuit 2
LEDs (light-emitting diodes) are small, powerful lights
that are used in many different applications. To start offthe SIK, we will work on blinking an LED. at's right- it's as simple as turning a light on and off. It mightnot seem like much, but establishing this importantbaseline will give you a solid foundation as we worktoward more complex experiments.
Blinking an LED
1
Each circuit begins with a brief descripon
of the what you are pung together and
the expected result.
This is a schemac of your circuit.
This is an illustraon of how the
completed circuit should look. It is not
necessary to use the black holder for the
RedBoard and breadboard, but we
recommend it for the first me inventor!
Components like resistors need to have
their legs bent into 90 angles in order to
correctly fit the breadboard sockets. You
can also cut the legs shorter to make them
easier to work with on the breadboard.
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
22/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circu
it1:Blink
inganLED
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 9 10111
213
14
1516171
81920
21
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 101112131415161718192
021
22
23
24
25
26
27
28
29
30
LED:Makesuretheshortleg,
markedwithflatside,
goe
sinto
thenegaveposion(-
).
330Re
sistor:Thecolorbanding
shouldreadorange-or-
ange-brown-gold.
Thecompo-
nentlegscangoineitherhole.
JumperWire:Alljumperwires
workthesame.Theyareusedto
connecttw
opointstogether.This
guidewillsho
wthewireswithdifferent
coloredinsula
onsforclarity,
butusing
differentcombinaonsofcolorsis
completelyac
ceptable.
FlatEdge
ShortLeg
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
23/84
Component:
Im
ageRe
ference:
LED(5mm)
+
-
+
-
c2
c3
JumperW
ire
Pin13
e2
330
Res
istor
a3
GND
a3
JumperW
ire
GND
JumperW
ire
5V
5V
+
5VontheRedBoardconnectstotherowmarked+onthebreadboard.
Pin13ontheRedBoardconnectstosockete2onthebreadboard.
GNDontheRedBoardshouldbeco
nnectedtotherowmarked-onthebreadboard.
Resistorsareplacedinbreadboardso
cketsonly.The-symbolrepresentsan
ysocketinitsvercal
columnonthePowerbus.
Breadbo
ard:Thewhitebackground
representsaconnecontoa
breadbo
ardsocketspecifiedbya
leer-nu
mbercoordinatesuchas
e2.Thes
ecoordinatesaremerely
sugges
onsthatalignwiththe
graphicimage.
RedBoard:Theredbackground
representsaconnecontooneof
theRedBoardheaderpins.
ComponentslikeLEDsareinsertedintothebreadboardsocketsc2(longleg)c3(shortleg).Steps
highlightedwithayellowwarningtrianglerepresentapolarizedcomponent.
Payspecialaenonto
thecomponentsmarkingsindicang
howtoplaceitonthebreadboard.
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
24/84
Open Up the Arduino IDE software on your computer. Coding in the Arduinolanguage will control your circuit. Open the code for Circuit 1 by accessing the SIKGuide Code you downloaded and placed into your Examples folder earlier.
Open Your First Sketch:
File Edit Sketch Tools Help
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
Page Setup
Print
New
Open...
Sketchbook
Examples
Close
Save
Save As...
Upload
Upload Using Progammer
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 #13Circuit #14
Circuit #15
Circuit #1
/* Blink
Turns on an LED on for one second,then off for one second, repeatedly.This example code is in the public domain.
*/
void setup() {// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT);}
void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second}
// Circuit #1
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
25/84
Verify
Upload
// The result of a completed circuit with correct code after verified and uploaded.
is compiles your code. e IDE changes it from text into instructions the computercan understand.
is sends the instructions via the USB cable to the computer chip on the RedBoard. eRedBoard will then begin running your code automatically.
IOR
EFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~10~
98
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
26/84
Circuit 2
Arduino Code:
1
Troubleshooting:
LED Not Lighting Up?LEDs will only work in one direction. Try taking it out andtwisting it 180 degrees (no need to worry, installing itbackward does no permanent harm).
Program Not Uploadingis happens sometimes, the most likely cause is a confusedserial 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 getback to you as soon as we can: [email protected]
You should see your LED blink on and off. Ifit isn't, make sure you have assembled thecircuit correctly and verified and uploaded thecode to your board or see the troubleshootingtips below.
Before you can use one of the RedBoard's pins, you need to tell the
RedBoard whether it is an INPUT or OUTPUT. We use a built-in
"function" called pinMode() to do this.
When you're using a pin as an OUTPUT, you can command it to be
HIGH (output 5 volts), or LOW (output 0 volts).digitalWrite(13, HIGH);
pinMode(13, OUTPUT);
Code to Note:
Real World Application:
Almost all modern flat screen televisions and monitorshave LED indicator lights to show they are on or off.
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 1
What you Should See:
This is where you will find the
Arduino code for each circuit.
Remember to Verify and
Upload your code.
See if your circuit is complete
and working in this secon.
Begin to understand how the
Arduino code works. See below.
IOREFRESET
RESET
7-15V
SCLSDAAREFGN
D13
12~11~
10~9
8
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGN
DGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
This is a secon dedicated to the most
common mistakes made while assembling
the circuit.
Here you will find examples of the circuit
you just completed in the real world.
Many of the theories in these circuits areused in things you use everyday!
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
27/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
28/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit2:Potentiometer
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 910
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
1 2 3 4 5 6 7 8 910
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
29/84
Component:
Im
ageReference:
Potentiometer
e6
JumperWire
e8
JumperWire
JumperWire
GND
JumperWire
5V
Pin
13
j20
JumperWire
GND
JumperWire
5V
5V
+
+
-
+
-
h20
h21
LED(5mm)
330
Resistor
j21
+
JumperWire
A0
e7
+
a6
a7
a8
IfyoulookcloselyatyourRedBoard,you'llseesomepinsla
beled"DIGITAL",
andsomelabeled"ANALO
G".What'sthedifference?
Manyofthedevicesyou'll
interfaceto,suchasLEDsandpushbuttons,have
onlytwopossiblestates:on
andoff,orasthey'reknowntotheRedBoard,
"HIGH"(5volts)and"LO
W"(0volts).edigitalpinson
anRedBoardare
greatatgettingthesesignalstoandfromtheoutsideworld,
andcanevendo
trickslikesimulateddimm
ing(byblinkingonandoffreally
fast),andserial
communications(transferr
ingdatatoanotherdevicebyencodingitaspatterns
ofHIGHandLOW).
Buttherearealsoalotofthingsouttherethataren'tjust"on"or"off".
Temperaturelevels,contro
lknobs,etc.a
llhaveacontinuou
srangeofvalues
betweenHIGHandLOW
.Forthesesituations,t
heRedBoardofferssixanalog
inputsthattranslateaninp
utvoltageintoanumberthatran
gesfrom0(0volts)
to1023(5volts).eanalogpinsareperfectformeasuring
allthose"real
world"values,andallowyoutointerfacetheRedBoardtoallkindsofthings.
DigitalversusAnalog
:
DIGITAL
0volts
0
5volts
1023
toor
ANALOG
HIGH
on
5volts
LOW
off
0volts
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
30/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
31/84
Circuit 2
PARTS:
p.10
IC
1X
330
Resistor
8X
LED
8X
You know whats even more fun than a blinking
LED? Changing colors with one LED. RGB, orred-green-blue, LEDs have three different color-emit-ting diodes that can be combined to create all sorts ofcolors. In this circuit, youll learn how to use an RGBLED to create unique color combinations.Depending on how bright each diode is, nearly anycolor is possible!
RGB LED
PARTS:
CIRCUIT #3
3
p.28
Potentiometer
1X
TransistorP2N2222AG
1X
Wire
6X
330
Resistor
3X
LED
1X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
red
commongreen
blue
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
32/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit3:RGBLED
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 910
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
1 2 3 4 5 6 7 8 910
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
*Thelongestleadisthecommon(gnd).
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
33/84
Component:
Im
ageReference:
e7
e11
5V
330
Resistor
g4
e4
e7
e11
5V
330
Resistor
g6
e6
e7
e11
5V
330
Resistor
g7
e7
RGBLED(5mm)
JumperWire
GND
JumperWire
5V
5V
+
JumperWire
Pin
9
h4
JumperWire
Pin
10
h6
JumperWire
Pin
11
h7
e5
JumperWire
We'veseenthattheArduinocanreadanalogvoltages(voltagesbetween0and
5volts)usingtheanalogR
ead()function.IsthereawayfortheRedBoardto
outputanalogvoltagesaswell?
eanswerisno...andye
s.eRedBoarddoesnothaveatrueanalogvoltage
output.But,becausetheRedBoardissofast,itcanfakeit
usingsomething
calledPWM("Pulse-WidthModulation").epinson
theRedBoardwith
~nexttothemarePWM
/Analogoutcompatible.
eRedBoardissofastth
atitcanblinkapinonandoffalmost1000times
persecond.P
WMgoesonestepfurtherbyvaryingtheam
ountoftimethat
theblinkingpinspendsH
IGHvs.t
hetimeitspendsLOW
.Ifitspendsmost
ofitstimeHIGH,a
LED
connectedtothatpinwillappearbright.I
fit
spendsmostofitstimeLOW,t
heLEDwilllookdim.Becausethepinis
blinkingmuchfasterthan
youreyecandetect,t
heRedBoardcreatesthe
illusionofa"true"analog
output.
Theshockingtruthb
ehindanalogWrite():
90%9
0%
50%
50%
0.5
V
2.5
V
4.5
V
LOW(0volts)
HIGH(5volts)
LOW(0volts)
HIGH(5volts)
LOW(0volts)
HIGH(5volts)
10%
10%
a4
a5
a6
a7
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
34/84
Many electronics such asvideogame consoles use RGBLEDs to have the versatilityto show different colors in
the same area. Often timesthe diffent colors representdifferent states of workingcondition.
Circuit 2
Arduino Code:
3
Troubleshooting:
LED Remains Dark or Shows Incorrect ColorWith the four pins of the LED so close together, itssometimes easy to misplace one. Double check eachpin is where it should be.
Seeing Rede red diode within the RGB LED may be a bit brighterthan the other two. To make your colors more balanced,use a higher Ohm resistor. Or adjust in code.
analogWrite(RED_PIN, redIntensity);to
analogWrite(RED_PIN, redIntensity/3);
You should see your LED turn on,but this time in new, crazy colors! If itisn't, make sure you have assembledthe circuit correctly and verified anduploaded the code to your board orsee the troubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 3
What you Should See:
A for() loop is used to step a number across a range, and repeatedly runscode within the brackets {}. Here the variable "x" starts a 0, ends at 767,
and increases by one each time ("x++").
for (x = 0; x < 768; x++)
{}
e RedBoard is very very fast, capable of running thousands of lines ofcode each second. To slow it down so that we can see what it's doing,
we'll often insert delays into the code. delay() counts in milliseconds;
there are 1000 ms in one second.
delay(sensorValue);
"If / else" statements are used to make choices in your programs. e statement
within the parenthesis () is evaluated; if it's true, the code within the first brackets {}
will run. If it's not true, the code within the second brackets {} will run.
if (x
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
35/84
So you have gotten one LED to blink on and off
fantastic! Now it's time to up the stakes a little bit byconnecting EIGHT LEDS AT ONCE. We'll also giveour RedBoard a little test by creating various lightingsequences. is circuit is a great setup to start practicing
writing your own programs and getting a feel for theway RedBoard works.
Along with controlling the LEDs, youll learn about acouple programming tricks that keep your code neatand tidy:
for() loops - used when you want to run a piece ofcode several times
arrays[ ] - used to make managing variables easier bygrouping them together
Multiple LEDs
p.32
PARTS: LED
8X
Wire
10X
330
Resistor
8X
CIRCUIT #4
4
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PW
M~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
36/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit4:MultipleLEDs
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 910
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
1 2 3 4 5 6 7 8 910
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
37/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
38/84
Circuit 2
Arduino Code:
4
Troubleshooting:
Some LEDs Fail to LightIt is easy to insert an LED backwards. Check the LEDsthat aren't working and ensure they the right wayaround.
Operating out of sequenceWith eight wires it's easy to cross a couple. Double checkthat the first LED is plugged into pin 2 and each pinthere after.
Starting AfreshIts easy to accidentally misplace a wire without noticing.Pulling everything out and starting with a fresh slate isoften easier than trying to track down the problem.
is is similar to circuit number one, butinstead of one LED, you should see all theLEDs blink. If they aren't, make sure youhave assembled the circuit correctly andverified and uploaded the code to your boardor see the troubleshooting tips below.
Code to Note:
Real World Application:
Scrolling marquee displays are generally used to spreadshort segments of important information. ey are builtout of many LEDs.
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 4
What you Should See:
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGN
DGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
When you have to manage a lot of variables, an "array" isa handy way to group them together. Here we're creating
an array of integers, called ledPins, with eight elements.int ledPins[] = {2,3,4,5,6,7,8,9};
Computers like to do the same things each time they run. But sometimesyou want to do things randomly, such as simulating the roll of a dice. e
random() function is a great way to do this.
See http://arduino.cc/en/reference/randomfor more information.
index = random(8);
You refer to the elements in an array by their position.
e 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".
digitalWrite(ledPins[0], HIGH);
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
39/84
Circuit 2
PARTS: Wire
19X
IC
1X
330
Resistor
8X
LED
8X
Circuit 2
Up until now, weve focused solely on outputs. Now
were going to go to the other end of spectrum andplay around with inputs. In this circuit, well belooking at one of the most common and simpleinputs a push button. e way a push button works
with RedBoard is that when the button is pushed, thevoltage goes LOW. e RedBoard reads this andreacts accordingly. In this circuit, you will also use apull-up resistor, which keeps the voltage HIGH whenyou're not pressing the button.
Push Buttons
PARTS: Wire
7X
CIRCUIT #5
5
Push Button
2X
LED
1X
330
Resistor
1X
10K
Resistor
2X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PW
M~)
ON
ISP
TX
RX
p.10
p.36
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
40/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit5:PushButtons
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 9 10111
213
14
1516171
81920
21
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 101112131415161718192
021
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
41/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
42/84
e buttons we used here are similar to the buttons inmost video game controllers.
Circuit 2
Arduino Code:
5
Troubleshooting:
Light Not Turning One pushbutton is square, and because of this it is easy toput it in the wrong way. Give it a 90 degree twist and seeif it starts working.
UnderwhelmedNo worries, these circuits are all super stripped down tomake playing with the components easy, but once youthrow them together the sky is the limit.
You should see the LED turn onif you press either button, and offif you press both buttons. (See thecode to find out why!) If it isn't
working, make sure you haveassembled the circuit correctlyand verified and uploaded thecode to your board or see thetroubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 5
What You Should See:
e digital pins can be used as inputs as well as outputs.Before you do either, you need to tell the RedBoard
which direction you're going.
pinMode(button2Pin, INPUT);
Because we've connected the button to GND, it will read LOW when
it's being pressed. Here we're using the "equivalence" operator ("==")
to see if the button is being pressed.
if (button1State == LOW)
To read a digital input, you use the digitalRead()
function. It will return HIGH if there's 5V present at the
pin, or LOW if there's 0V present at the pin.
button1State = digitalRead(button1Pin);
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~10~
98
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
43/84
Circuit 2
So youve already played with a potentiometer, which
varies resistance based on the twisting of a knob. Inthis circuit, youll be using a photo resistor, whichchanges resistance based on how much light thesensor receives. Since the RedBoard cant directlyinterpret resistance (rather, it reads voltage), we use avoltage divider to use our photo resistor. is voltagedivider will output a high voltage when it is getting alot of light and a low voltage when it is not.
Photo Resistor
PARTS: Wire
6X
CIRCUIT #6
6
LED
1X
330
Resistor
1X
Photo Resistor
1X
10K
Resistor
1X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
p.40
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
44/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit6:PhotoResistor
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 9 1011121
31415161718192
021
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 1011121
31415161718192
021
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
45/84
Component:
Im
ageReference:
+
-
+
-
h20
h21
LED(5mm)
PhotoResistor
j1
JumperWire
j6
+
JumperWire
JumperWire
GND
JumperWire
5V
5V
+
330Resistor(sensor)
j21
+
10K
Resistor
i1
i5
JumperWire
A0
j5
f5
f6
JumperWire
Pin
9
j20
Manyofthesensorsyou'lluse(potentiometers,photoresistors,etc.)areresistors
indisguise.eirresistancechangesinproportiontowhateverthey'resensing
(lightlevel,temperature,sound,etc.).
eRedBoard'sanalogin
putpinsmeasurevoltage,notre
sistance.Butwecan
easilyuseresistivesensors
withtheRedBoardbyincludingthemaspartofa
"voltagedivider".
Avoltagedividerconsists
oftworesistors.e"top"resistoristhesensoryou'll
beusing.e"bottom"oneisanormal,fixedresistor.W
henyouconnectthe
topresistorto5volts,and
thebottomresistortoground.evoltageatthe
middlewillbeproportion
altothebottomresistorrelative
tothetotalresistance
(topresistor+bottomresistor).W
henoneoftheresistors
changes(asitwill
whenyoursensorsensesthings),t
heoutputvoltagewillchangeaswell!
Althoughthesensor'sresistancewillvary,t
heresistivesensors(flexsensorlight
sensor,softpot,andtrimpot)intheSIKarearound10Koh
ms.Weusuallywant
thefixedresistortobeclosetothisvalue,sousinga10Kr
esistorisagreatchoice
forthefixed"bottom"resistor.Pleasenotethefixedresistorisn'tnecessarilythe
bottomresistor.Wedoth
atwiththephotodiodeonlysothatmore
light=morevoltage,butitcouldbeflippedandwe'dgettheoppositeresponse.
Measuringresistivesensors:
PIN3
5
volts
GND
(ground)(-)
PinA0
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
46/84
A street lamp uses a light sensor to detect when to turnthe lights on at night.
Circuit 2
Arduino Code:
6
Troubleshooting:
LED Remains Darkis is a mistake we continue to make time and timeagain, if only they could make an LED that worked bothways. Pull it up and give it a twist.
It Isn't Responding to Changes in LightGiven that the spacing of the wires on the photo-resistoris not standard, it is easy to misplace it. Double check itsin the right place.
Still Not Quite WorkingYou may be in a room which is either too bright or dark.Try turning the lights on or off to see if this helps. Or ifyou have a flashlight near by give that a try.
You should see the LED grow brighteror dimmer in accordance with howmuch light your photoresistor isreading. If it isn't working, make sureyou have assembled the circuitcorrectly and verified and uploadedthe code to your board or see thetroubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 6
What You Should See:
When we read an analog signal using analogRead(), it will bea number from 0 to 1023. But when we want to drive a
PWM pin using analogWrite(), it wants a number from 0 to
255. We can "squeeze" the larger range into the smaller range
using the map() function.
lightLevel = map(lightLevel, 0, 1023, 0, 255);
Because map() could still return numbers outside the "to"
range, we'll also use a function called constrain() that will
"clip" numbers into a range. If the number is outside the
range, it will make it the largest or smallest number. If it is
within the range, it will stay the same.
lightLevel = constrain(lightLevel, 0, 255);
IOREFRESET
RESET
7-15V
SCLSDAAREFGN
D13
12~11~
10~9
8
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PW
M~)
ON
ISP
TX
RX
Seehttp://arduino.cc/en/reference/map for more info.
Seehttp://arduino.cc/en/reference/constrain for more info.
Parametersmap(value, fromLow, fromHigh, toLow, toHigh)
Parametersconstrain(x, a, b)
x:the number to constrain, all data typesa: the lower end of the range, all data typesb:the upper end of the range, all data types
value:the number to mapfromLow:the lower bound of the value's current rangefromHigh:the upper bound of the value's current rangetoLow: the lower bound of the value's target rangetoHigh: the upper bound of the value's target range
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
47/84
Circuit 2
A temperature sensor is exactly what it sounds like a
sensor used to measure ambient temperature. isparticular sensor has three pins a positive, a ground,and a signal. is is a linear temperature sensor. Achange in temperature of one degree centigrade is equalto a change of 10 millivolts at the sensor output. eTMP36 sensor has a nominal 750 mV at 25C (aboutroom temperature). In this circuit, youll learn how tointegrate the temperature sensor with your RedBoard,and use the Arduino IDEs serial monitor to display thetemperature.
Temperature Sensor
CIRCUIT #7
7
p.44
PART
S: Wire
5X
Temp. Sensor
1X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGN
DGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PW
M~)
ON
ISP
TXRX
FRONT
BACK
When youre building the circuit be careful notto mix up the transistor and the temperaturesensor, theyre almost identical. Look forTMP on the body of the temperature sensor.
SIGNAL
+V
GND
SIGNAL
GND
+V
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
48/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
49/84
TemperatureSensor
f5
f7
f6
Component:
Im
ageRe
ference:
j5
JumperW
ire
j7
JumperW
ire
JumperW
ire
GND
JumperW
ire
5V
5V
+
JumperW
ire
A0
j6
+
iscircuitusestheArduin
oIDE'sserialmonitor.Toopenthis,firstuploadthe
programthenclickthebuttonwhichlookslikeamagnifyingglassinasquare.In
orderfortheserialmonitor
tooperatecorrectlyitmustbeset
tothesamebaud
rate(speedinbitspersecon
d)asthecodeyou'rerunning.iscoderunsat9600
baud;ifthebaudratesettin
gisnot9600,changeitto9600.
Openingyourserialm
onitor:
1
2
3
+V
SIGN
AL
GND
-
+
VOUT
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
50/84
Building climate control systems use a temperature sensorto monitor and maintain their settings.
Circuit 2
Arduino Code:
7
Troubleshooting:
Nothing Seems to Happenis program has no outward indication it is working. Tosee the results you must open the Arduino IDE's serialmonitor (instructions on previous page).
Gibberish is Displayedis happens because the serial monitor is receiving data ata different speed than expected. To fix this, click thepull-down box that reads "*** baud" and change it to"9600 baud".
Temperature Value is UnchangingTry pinching the sensor with your fingers to heat it up orpressing a bag of ice against it to cool it down.
You should be able to read thetemperature your temperaturesensor is detecting on the serialmonitor in the Arduino IDE. If itisn't working, make sure you haveassembled the circuit correctly andverified and uploaded the code toyour board or see the troubleshoot-ing tips below.
Code to Note:
Real World Application:
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 7
What You Should See:
Before using the serial monitor, you must call Serial.begin() toinitialize it. 9600 is the "baud rate", or communications speed. When
two devices are communicating with each other, both must be set to
the same speed.
Serial.begin(9600);
Serial.print() will print everything on the same line. Serial.println() will
move to the next line. By using both of these commands together, you
can create easy-to-read printouts of text and data.
Serial.println(degreesF);
e Serial.print() command is very smart. It can print out almost
anything you can throw at it, including variables of all types,
quoted text (AKA "strings"), etc.
See http://arduino.cc/en/serial/printfor more info.
Serial.print(degreesC);
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6~
54
~32
10
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM
~)
ON
ISP
TXRX
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 22.75 deg F: 72.96
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 22.75 deg F: 72.96
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 22.75 deg F: 72.96
voltage: 0.73 deg C: 22.75 deg F: 72.96
voltage: 0.73 deg C: 23.24 deg F: 73.84
voltage: 0.73 deg C: 22.75 deg F: 72.96
voltage: 0.73 deg C: 23.24 deg F: 73.84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
51/84
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54
~3
21
0
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
Circuit 2
Servos are ideal for embedded electronics applications
because they do one thing very well that motors cannot they can move to a position accurately. By varying thepulse width of the output voltage to a servo, you can movea servo to a specific position. For example, a pulse of 1.5milliseconds will move the servo 90 degrees. In this circuit,youll learn how to use PWM (pulse width modulation)to control and rotate a servo.
A Single Servo
PART
S: Wire
8X
CIRCUIT #8
8
p.48
Servo
1X
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
52/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circu
it8:A
Single
Servo
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 910
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
1 2 3 4 5 6 7 8 910
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
53/84
Component:
Im
ageRe
ference:
Servo
e5
e7
e6
JumperW
ire
JumperW
ire
JumperW
ire
e6
e7
e5
5V
JumperW
ire
Pin
9
a7
JumperW
ire
JumperW
ire
JumperW
ire
JumperW
ire
GND
b5
+
a6
+
eArduinodevelopmentenv
ironmentgivesyouaveryusefulsetofbuilt-incommandsfor
doingbasicinputandoutput,
makingdecisionsusinglogic,solvingmathproblems,etc.
ButtherealpowerofArduino
isthehugecommunityusingitandtheirwillingnesstoshare
theirwork.
Librariesarecollectionsofnew
commandsthathavebeenpackagedtogethertomakeiteasy
toincludetheminyoursketch
es.Arduinocomeswithahandfulofusefullibraries,suchas
theservolibraryusedinthisexample,thatcanbeusedtointerfacetomoreadvanced
devices(LCDdisplays,steppermotors,ethernetports,etc.)
Seehttp://arduino.cc/en/reference/librariesforalistofthestanda
rdlibrariesand
informationonusingthem.
Butanyonecancreatealibrary,andifyouwanttouseanewsensor
oroutputdevice,
chancesarethatsomeoneouttherehasalreadywrittenonethatinterfacesthatdevicetothe
RedBoard.ManyofSparkFun
'sproductscomewithArduinolibraries,andyoucanfind
evenmoreusingGoogleandtheArduinoPlaygroundathttp://ardu
ino.cc/playground/.
WhenYOUgettheRedBoard
workingwithanewdevice,consider
makingalibraryforit
andsharingitwiththeworld!
Tousealibraryinasketch,se
lectitfromSketch>ImportLibrary.
Afterimportingthelibraryintoyourcode,youwillhaveaccesstoanumberofpre-written
commandsandfunctions.Mo
reinformationonhowtousethestan
dardlibraryfunctions
canbeaccessedat:http://ardu
ino.cc/en/Reference/Libraries.
Expandy
ourhorizon
s
usingL
ibraries:
File
Edit
Sketch
Tools
Help
EEPROM
Ethernet
Firmata
LiquidC
rystal
SDServo
Softwa
reSerial
SPI
Steppe
r
Wire
Verify
/Compile
Show
SketchFolder
AddF
ile...
Impo
rtLibrary
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
54/84
Circuit 2
Arduino Code:
8
Troubleshooting:
Servo Not TwistingEven with colored wires it is still shockingly easy to plug aservo in backward. is might be the case.
Still Not WorkingA mistake we made a time or two was simply forgettingto connect the power (red and brown wires) to +5 voltsand ground.
Fits and StartsIf the servo begins moving then twitches, and there's aflashing light on your RedBoard, the power supply youare using is not quite up to the challenge. Using a walladapter instead of USB should solve this problem.
You should see your servo motor move tovarious locations at several speeds. If themotor doesn't move, check yourconnections and make sure you haveverified and uploaded the code, or see thetroubleshooting tips below.
Code to Note:
Real World Application:
Robotic arms you might see in an assembly line or sci-fimovie probably have servos in them.
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 8
What You Should See:7~
6~5
4~3
21
0
.
TAL(PWM~)
ON
TXRX
#include is a special "preprocessor" command that inserts a library (or anyother file) into your sketch. You can type this command yourself, or
choose an installed library from the "sketch / import library" menu.#include
e servos in this kit don't spin all the way around, but they can be commandedto 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.
servo1.write(180);
e servo library adds new commands that let you control a servo. To
prepare the Arduino to control a servo, you must 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).
Servo servo1;
servo1.attach(9);
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
55/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
56/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 910
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
1 2 3 4 5 6 7 8 910
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Circu
it9:Flex
Sensor
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
57/84
Ithappenstoeveryone-you
writeasketchwhichsuccessfullycompilesanduploads,
butyoucan'tfigureoutwhy
it'snotdoingwhatyouwantitto.
Largercomputers
havescreens,keyboards,and
micethatyoucanusetodebugyourcode,buttiny
computersliketheRedBoardhavenosuchthings.
ekeytovisibilityintoam
icrocontrollerisoutput.iscanbealmostanything,
includingLEDsandbuzzers,butoneofthemostusefultoolsis
theserialmonitor.
Using
Ser
ial.pr
int()andpr
intln(),youcaneasilyoutputhuma
n-readabletextand
datafromtheRedBoardtoawindowbackonthehostcomputer.isisgreatfor
yoursketch'sfinaloutput,butit'salsoincrediblyusefulfordebugging.
Debuggingyoursket
chesusingtheSerialMon
itor:
Component:
Im
ageRe
ference:
i20
i24
Servo
e1
e3
e2
e1
JumperW
ire
i19
JumperW
ire
h24
+
JumperW
ire
h24
+
JumperW
ire
h24
+
JumperW
ire
JumperW
ire
JumperW
ire
JumperW
ire
JumperW
ire
e2
JumperW
ire
e3
JumperW
ire
Flex
Sensor
h19
h20
10K
Res
istor
j20
A0
b1
+
a2
+
a3
Pin
9
5V
5V
+
GND
Andifyourunthecodeagain,you'llseethe
outputyouwanted:
for
(x=
1
;
x Examples > SIK Guide > Circuit # 10
What You Should See:
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6~5
4~3
21
0
TX RX 13
3.3V5VGN
DGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PW
M~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
63/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
64/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit11:PiezoElements
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 9 10111
213
14
1516171
81920
21
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 101112131415161718192
021
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
65/84
Component:
Im
ageReference:
PiezoElement
+
-
f9
f7
JumperWire
Pin
9
j9
i7
JumperWire
GND
JumperWire
Arduinocontainsawealthofbuilt-infunctionsthatareusefulforallkindsofthings.
(Seehttp://arduino.cc/en/referenceforalist).Butyoucanalsoeasilycreateyour
ownfunctions.F
irst,weneedtodeclareafunction.Here'sasim
pleexamplenamed
"add,"whichaddstwonumberstogetherandreturnstheresult.Let'sbreakitdown.
Yourfunctionscantakeinvalues("parameters"),andreturnav
alue,asthisonedoes.
Ifyou'llbepassingparamete
rstoyourfunction,putthem(and
theirtypes)inthe
parenthesesafterthefunctionname.Ifyourfunctionisnotusin
ganyparameters,just
useanemptyparenthesis()afterthename.
Ifyourfunctionisreturning
avaluefromyourfunction,putthetypeofthereturn
valueinfrontofthefunctionname.eninyourfunction,whenyou'rereadyto
returnthevalue,putinareturn(value)statement.Ifyouwon'tbereturningavalue,
put"void"infrontofthefunctionname(similartothedeclarationforthesetup()
andloop()functions).
Whenyouwriteyourownfunctions,youmakeyourcodeneaterandeasiertore-use.
Seehttp://arduino.cc/en/re
ference/functiondeclarationform
oreinfomationabout
functions.
Creatingyourown
fu
nctions:
intadd(intparameter1
,intparameter2)
{
intx;
x=parame
ter1+parameter2;
return(x);
}
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
66/84
Many modern megaphones have settings that use a loudamplified buzzer. ey are usually very loud and quitegood at getting peoples attention.
Circuit 2
Arduino Code:
11
Troubleshooting:
No SoundGiven the size and shape of the piezo element it is easy tomiss the right holes on the breadboard. Try doublechecking its placement.
Can't ink While the Melody is PlayingJust pull up the piezo element whilst you think, uploadyour program then plug it back in.
Feeling Let Down and Desertede code is written so you can easily add your own songs.
You should see - well, nothing!But you should be able to hear asong. If it isn't working, makesure you have assembled thecircuit correctly and verified anduploaded the code to your boardor see the troubleshooting tipsbelow.
Code to Note:
Real World Application:
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 11
What You Should See:
IOREFRESE
T
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54
~3
21
0
TX RX 13
3
.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
Up until now we've been working solely with numerical data, butthe 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.
char notes[] = "cdfda ag cdfdg gf ";
char names[] = {'c','d','e','f','g','a','b','C'};
One of Arduino's many useful built-in commands is the tone()
function. is function drives an output pin at a certain
frequency, making it perfect for driving buzzers and speakers. If
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() ).
tone(pin, frequency, duration);
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
67/84
IOREFRESET
RESET
7-15V
SCLSDAAREFGND
1312~
11~10~
98
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGNDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PW
M~)
ON
ISP
TX
RX
Circuit 2
Remember before when you played around with a servo
motor? Now we are going to tackle spinning a motor.is requires the use of a transistor, which can switch alarger amount of current than the RedBoard can. Whenusing a transistor, you just need to make sure itsmaximum specs are high enough for your use. etransistor we are using for this circuit is rated at 40V maxand 200 milliamps max perfect for our toy motor!When the motor is spinning and suddenly turned off, themagnetic field inside it collapses, generating a voltagespike. is can damage the transistor. To prevent this, weuse a "flyback diode", which diverts the voltage spikearound the transistor.
Spinning a Motor
PARTS: Wire
6X
CIRCUIT #12
12
1X
DC Motor
1X
Diode1N4148
p.64
TransistorP2N2222AG
1X
When youre building the circuit be careful notto mix up the transistor and the temperaturesensor, theyre almost identical. Look forP2N2222A on the body of the transistor.
330
Resistor
1X
P2N2
222A
FRONT
BACK
COLLECTOR
BASE
EMITTER
EMITTER
BASE
COLLECTOR
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
68/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit12:SpinningaMotor
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 910
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
1 2 3 4 5 6 7 8 910
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
69/84
Component:
Im
ageReference:
TransistorP2N2222AG
a1
a3
a2
JumperWire
JumperWire
Pin
9
j2
JumperWire
JumperWire
JumperWire
5V
JumperWire
GND
Diode1N4148
a3
GND
b7
b11
e7
e11
e7
e11
DCMotor
5V
330
Resistor
g2
e2
e1
a7
+
+
e3
d11
Atthispointyou'reprobablystartingtogetyourownideasforcircuitsthatdofun
things,orhelpsolvearealproblem.Excellent!Herearesometipsonprogrammingin
general.
Mostofthesketchesyouwritewillbealoopwithsomeorallofthesesteps:
1.Performsomesortofinput
2.Makesomecalculations
ordecisions
3.Performsomesortofou
tput
4.Repeat!(Ornot!)
We'vealreadyshownyouho
wtouseabunchofdifferentinputsensorsandoutput
devices(andwestillhaveafewmoretogo).Feelfreetomakeu
seoftheexamplesin
yourownsketches-thisisthewholeideabehindthe"OpenSource"movement.
It'susuallyprettyeasytopullpiecesofdifferentsketchestogether,justopenthemin
twowindows,andcopyand
pastebetweenthem.
isisoneof
thereasonswe've
beenpromoting"goodprogramminghabits".ingslikeusing
constantsforpin
numbers,andbreakingyour
sketchintofunctions,makeitmucheasiertore-useyour
codeinnewsketches.Forex
ample,ifyoupullintwopiecesofcodethatusethesame
pin,youcaneasilychangeoneoftheconstantstoanewpin.(D
on'tforgetthatnot
allofthepinssupportanalogWrite();thecompatiblepinsarem
arkedonyourboard.)
Ifyouneedhelp,t
herearein
ternetforumswhereyoucanaskquestions.Try
Arduino'sforumatarduino
.cc/forum,andSparkFun'satforum.sparkfun.com.
Whenyou'rereadytomove
tomoreadvancedtopics,takealoo
katArduino's
tutorialspageatarduino.cc/en/tutorial.ManyofSparkFun'sm
oreadvanced
productswereprogrammed
withArduino,(allowingyoutoeasilymodifythem),or
haveArduinoexamplesforthem.Seeourproductpagesforinfo.
Finally,w
henyoucreatesom
ethingreallycool,considersharing
itwiththeworldso
thatotherscanlearnfromyourgenius.Besuretoletusknowon
https://www.sparkfun.com
/project_c
allssowecanputiton
ourhomepage!
Putt
ing
italltogether:
P2N2
222A
COLLECT
OR
BASE
EMITTER
E
B
C
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
70/84
Circuit 2
Arduino Code:
12
Troubleshooting:
Motor Not SpinningIf you sourced your own transistor, double check withthe data sheet that the pinout is compatible with aP2N2222AG (many are reversed).
Still No LuckIf you sourced your own motor, double check that it willwork with 5 volts and that it does not draw too muchpower.
Still Not WorkingSometimes the RedBoard will disconnect from thecomputer. Try un-plugging and then re-plugging it intoyour USB port.
e DC Motor should spin if you haveassembled the circuits components correctly,and also verified/uploaded the correct code. Ifyour circuit is not working check thetroubleshooting section below.
Code to Note:
Real World Application:
Radio Controlled(RC) cars use Direct Current(DC)motors to turn the wheels for propulsion.
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 12
T
SCLSDAAREFGND
1312~
11~10~
98
7~6~5
4~32
10
TX RX 13
.
IN
A0A1
A2A3
A4A5
WER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
What You Should See:
e RedBoard's serial port can be used to receive as well as send data.Because data could arrive at any time, the RedBoard stores, or
"buffers" data coming into the port until you're ready to use it. e
Serial.available() command returns the number of characters that the
port has received, but haven't been used by your sketch yet. Zero
means no data has arrived.
while (Serial.available() > 0)
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.
speed = Serial.parseInt();
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
71/84
Circuit 2
PARTS:
CIRCUIT #5
5
p.10
IC
1X
LED
8X
Circuit 2
In this circuit, we are going to use some of the lessons we
learned in circuit 12 to control a relay. A relay is basicallyan electrically controlled mechanical switch. Inside thatharmless looking plastic box is an electromagnet that,when it gets a jolt of energy, causes a switch to trip. Inthis circuit, youll learn how to control a relay like a pro giving your RedBoard even more powerful abilities!
Relays
PARTS:
CIRCUIT #13
13
p.68
TransistorP2N2222AG
1X
Relay
1X 1X
Diode1N4148
Wire
14X
330
Resistor
2X
LED
2X
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.
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TXRX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
72/84
IOREF
RESET
RESET
7-
15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9 8 7
~6
~5 4
~3 2 1 0
TX
RX13
3.
3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER ANALOG IN
DIGITAL (PWM~)
ON
ISP
TX
RX
Circuit13:Relays
a
b
c
d
e
f
g
h
i
1 2 3 4 5 6 7 8 9 1011121
3141516171
81920
21
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 101112131415161718192
021
22
23
24
25
26
27
28
29
30
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
73/84
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
74/84
Garage door openers use relays to operate. You might beable to hear the clicking if you listen closely.
Circuit 2
Arduino Code:
13
Troubleshooting:
LEDs Not LightingDouble-check that you've plugged them in correctly. elonger lead (and non-flat edge of the plastic flange) is thepositive lead.
No Clicking Sounde transistor or coil portion of the circuit isn't quiteworking. Check the transistor is plugged in the right way.
Not Quite Workinge included relays are designed to be soldered rather thanused in a breadboard. As such you may need to press it into ensure it works (and it may pop out occasionally).
When youre building the circuit be careful not to mix upthe temperature sensor and the transistor, theyre almostidentical.
You should be able to hear therelay contacts click, and see thetwo LEDs alternate illuminatingat 1-second intervals. If youdon't, double-check that youhave assembled the circuitcorrectly, and uploaded thecorrect sketch to the board. Also,see the troubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE// File > Examples > SIK Guide > Circuit # 13
What You Should See:
When we turn on the transistor, which in turn energizes the
relay's coil, the relay's switch contacts are closed. is 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);
e relay has an additional contact called NC (Normally Closed).
e NC pin is connected to the COM pin when the relay is OFF.
You can use either pin depending on whether something shouldbe normally on or normally off. You can also use both pins to
alternate power to two devices, much like railroad crossing
warning lights.
digitalWrite(relayPin, LOW);
IOREFRESET
RESET
SCLSDAAREFGND
1312~
11~10
~9
8
7~6
~5
4~3
21
0
TX RX 13
3.3V5VGN
DGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
IOREFRESET
RESET
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54~
32
10
TX RX 13
3.3V5VG
NDGNDVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
-
8/13/2019 SFE SIK RedBoard Guide Version3.0 Online
75/84
Circuit 2
Shift Register
PARTS: Wire
19X
CIRCUIT #14
14
p.72
Now we are going to step into the world of ICs (integrated
circuits). In this circuit, youll learn all about using a shiftregister (also called a serial-to-parallel converter). e shiftregister will give your RedBoard an additional eight outputs,using only three pins on your board. For this circuit, youllpractice by using the shift register to control eight LEDs.
IC
1X
330
Resistor
8X
LED
8X
IOREFRESET
RESET
7-15V
SCLSDAAREFGND13
12~11~
10~9
8
7~6~
54~
32
10
TX RX 13
3.3V5VGNDGN
DVIN
A0A1
A2A3
A4A5
POWER
ANALOGIN
DIGITAL(PWM~)
ON
ISP
TX
RX
Bend legs to 90 angle.
Align notch on top,
inbetween e5 and f5 o