Arduino Wearable Projects - Sample Chapter
Arduino Wearable Projects - Sample Chapter
ee
Sa
m
pl
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
$ 44.99 US
28.99 UK
P U B L I S H I N G
This book is intended for readers who are familiar with the
Arduino platform and want to learn more about creating
wearable projects. No previous experience in wearables is
expected, although a basic knowledge of Arduino will help.
Tony Olsson
multiple design fields with the core being physical prototyping and wearable
computing. His research includes haptic interactions and telehaptic communication.
Olsson has a background in philosophy and traditional arts, but later shifted his
focus to interaction design and computer science. He is also involved in running
the IOIO laboratory at Malm University.
Besides his work at the university, he also works as a freelance artist/designer and
author. Prior to this publication, Olsson published two books based on wearable
computing and prototyping with Arduino and Arduino-based platforms.
Preface
Preface
Almost 10 years have passed since I picked up my first Arduino board. At the time, I
was an interaction design student at Malm University. At the front of the classroom
that day, there was a bearded Spaniard talking, rather claiming, that he could teach
us all about electronics and how to do programming for microprocessors, all in 1
week. Of course, since I knew nothing about electronics and never thought I would
learn anything about it, I did not believe him.
The Spaniard had a completely new approach to teaching, which I had never
encountered before. He wanted to teach us, not by books and lectures, but by doing
things. One of my classmates pointed out that most of us did not know anything
about electronics, so how are we supposed to do anything with it? The Spaniard
replied that it does not matter, you can do things without knowing what you are
doing, and by doing them, you will learn.
After 15 minutes, we all had connected a small lamp to our Arduino boards, and
we had managed to program the lamp so that it would turn itself on and off. What
baffled me was not only what we had achieved in such little time, but also that parts
of what was going on actually made sense. We were learning by doing.
The bearded Spaniard was actually David Cuartielles, who together with Massimo
Banzi, just 1 year before, invented the Arduino board. Soon after they invented it,
Tome Igoe and David Mellis joined the team, and as they say, the rest is history. But
I still remember that day, as if it was yesterday, when I looked down at my blinking
light and something sparked inside me. I wanted to learn and do more. Then David
gave me the second valuable lesson, that the best way to learn more is to share your
knowledge with others, and he put me in a position where I was able to do so. Again
I was skeptical, since I had no knowledge to speak of, but again the lesson followed,
even if you only know a little, it is enough to help those that know nothing yet.
Preface
Soon after, I found out about a field called wearable computing. The idea was
to design and apply a technology to the human body in different ways, and it
all sounded as wonderfully crazy as the idea that you could learn electronics and
programming without any prior knowledge of how to do so. With inspiration from
Arduino and its team members, I leaped headfirst into the field. In this new field, I
found new inspiration in the works of Steve Mann and Leah Buechley. Mann, now a
professor at the University of Toronto, developed his own wearable computer in the
80s and had mostly done so on his own. Buechley, also a professor at MIT, had taken
the Arduino board and developed a new prototyping platform, which is specialized
for a wearable context. Both seemed to have done this against all the odds. Again, I
was inspired, and started to develop my own wearable devices, teaching others how
to do the same. Eventually, I collected enough know-how on things that I started
to write them down. When I started to share my writing, I found out how truly
amazing the Arduino community is a world-wide group of people that share a
love for making things with electronics.
It's safe to say that if it had not been for all these people, I probably would never
have written any of my books, so I would like to extend my thanks to all. I would
also like to thank you for picking up this book. You might be a novice or an expert,
but I do hope it will not matter. This book is based on the idea that anyone can learn
anything by the simple principle of actually "doing." If you are already an expert,
then you know there is always something to learn from "doing" things in a new way.
So, I hope you will gain some new knowledge and inspiration from the projects we
created in this book, and I wish you all the best in your creating endeavors.
Do check out "Soldering with David Cuartielles" on my YouTube channel at
https://www.youtube.com/watch?v=Mg01HFjsn6k.
Preface
Chapter 4, LED Glasses, teaches you to create a pair of programmable LED glasses.
These glasses will be covered by LEDs in the front, which will be programmable
to display different patterns and shapes. The reader will also be introduced to the
construction of a pair of sunglasses.
Chapter 5, Where in the World Am I?, focuses on the making of a wrist-worn GPS
tracking device. The information will be displayed on a small LCD screen. This
chapter also includes instructions and tips on how to create a casing containing
the components so that the device can be worn on the wrist.
Chapter 6, Hands-on with NFC, deals with NFC technology and servomotors and
how they can be combined into a smart door lock. This chapter also includes how
to design around NFC tags and make wearable jewelry that will work as a key for
the lock.
Chapter 7, Hands-on BLE, deals with low-powered Bluetooth technology and how it
can be implemented into wearable projects. This chapter introduces the Blend Micro
board and how it can be used to create projects that connect to your mobile phone.
Chapter 8, On the Wi-fly, introduces you to the Wi-Fi Particle Core board and its web
IDE. This chapter also talks about how to connect to online services.
Chapter 9, Time to Get Smart, focuses on the creation of a smart watch, which connects
to the Internet and uses online services to create custom notifications to be displayed
on a small OLED screen.
The online chapter (Chapter 10), Interactive Name Tag, expands upon Chapter 7,
Hands-on BLE, which deals with small screens, and shows you how to interact
with them over Bluetooth in order to make an interactive name tag. This chapter
is available at https://www.packtpub.com/sites/default/files/downloads/
ArduinoWearableProjects_OnlineChapter.pdf.
LED Glasses
In this chapter, we will look at how to create a pair of LED glasses. In essence,
these glasses are an LED matrix. A matrix is an arrangement of LEDs in columns
and rows, where we take advantage of the polarity of the LEDs so we can control
30 LEDs separately using only 15 pins on the Arduino board. The LED matrix has
been around for many years and is still used today in some screen technologies. For
example, digital bus signs are usually made by implementing an LED matrix, where
each individual LED acts like a pixel.
In this chapter you will also learn a little bit about how to create your own glasses and
soldering techniques. We will also have a look at some more advanced programming,
where we will be implementing some simple animation for you to build upon.
The materials needed are:
Wires
A soldering iron
3 mm MDF
220 resistors
[ 57 ]
LED Glasses
The design of the glasses is very simple yet fits the purpose. The design consists
of three main pieces, the front and two side frames. The two smaller pieces are
used for added support when connecting the frames to the front panel. The frames
can be simply glued to the corners of the front panel, while the two small pieces are
glued to the inside corners on each end, as shown in Figure 3.2. The design template
can be used to cut the pieces out from any material you like, but I recommend a
sturdy material of at least 3 mm thickness. Plastic materials would also work for this
project, or you could even make the frames out of cardboard, which can easily be cut
by hand.
[ 58 ]
Chapter 4
The glasses presented in this chapter were cut from 3 mm MDF using a laser
cutter. I don't expect most readers to have their own laser cutter, but many bigger
cities today have something called hacker spaces or Fab Labs, and some even
have them in their city's libraries. The concept of Fab Labs was developed by the
Massachusetts Institute of Technology, building on the idea of hacker spaces, which
are locations that offer access to different fabrication tools and equipment where
different people come to work on projects. Hacker spaces are usually a place where
people interested in electronics and programming meet to share ideas and work on
projects. Fab Labs are more oriented toward fabrication, not just digital entity, and
are open to the public. If you haven't checked already, I suggest you investigate
whether there is a hacker space or Fab Labs close by since you now have the perfect
excuse to head over for a visit.
If you choose to modify the design, remember to keep the size of the holes at 5 mm
since this is the size of the LEDs we will be using. You can swap these LEDs for the
smaller 3 mm ones if you like, but I would not recommend LEDs bigger than 5 mm
since these might complicate the design.
[ 59 ]
LED Glasses
[ 60 ]
Chapter 4
Arduino is fast, even faster than the human eye, so we will use this speed to our
advantage in order to give the impression of lighting up many LEDs at the same
time. As I said, we can't technically light up more than one LED at once in the
matrix but we can switch between them so fast that the human eye will perceive it
as more than one LED being on. But before we get to this part, we need to connect
everything, and this means it is time to turn on the soldering iron.
Before we start soldering, we need to place the LEDs in the right order. A good
idea is to check that all your LEDs work before soldering them. By connecting the
LEDs one by one to a 3.3V coin cell battery, or using the power that goes from your
Arduino to a breadboard, you can easily do this. If you are using a breadboard, don't
forget to add a 220 resistor.
If you cut 5 mm holes, the LEDs should fit nicely. If they are a bit loose don't worry,
as once they are soldered together everything will be held in place. To create the
matrix, we need to solder the LEDs into rows and columns. In Figure 3.4 you can see
how I have prepared the LEDs for soldering by bending the legs of the LEDs into the
desired rows and columns. All the negative legs (the shorter ones) will be soldered
in horizontal lines, and then the positive legs (the longer ones) will be soldered in
vertical lines. Make sure that you bend the positive lines over the negative lines
so they do not come into contact with one another. If they do, the matrix will not
work as it is supposed to. If you want, you can cover up your lines using some tape
needed. This is done by placing a small piece of tape in between the legs of the LEDs
so they do not touch one another.
[ 61 ]
LED Glasses
Once you are done, we can move on and add the wiring and the resistors that will
connect to our Arduino board. Figure 3.5 shows a close-up of the resistors connected
straight to the positive column in the glasses, and the wires connected to the other side
of the resistors. The idea is to place the Arduino board on the inside of either the left or
right frame. Before you cut your wires, measure the distance between the row and the
location of the Arduino board where it will be placed on the inside of the side frame.
Make sure you add some extra length before you cut them because it is better to have
wires that are too long than too short.
[ 62 ]
Chapter 4
Now is also a good time to put the JST female connector in place as shown in Figure
3.6. JST connectors are fairly standard connector for batteries, and in this project we
will be using a very small 3.7V battery with a male JST connector. You can place the
JST connector anywhere you like, but I found a good spot where the front panel meets
the frame just under the supporting piece of MDF. Make sure you leave enough space
on the back side of the connector to fit the power cable that connects to the Arduino
board. To keep the JST connector in place, use some glue:
When you have added the wires to all the positive columns, you can add three
cables for the negative rows, again ensuring you make them long enough to
reach the Arduino board. You don't need resistors on these lines since these will
act as our GND channels.
Once you have all the LEDs, resistors, and wires in place, it is time to connect
everything to the Arduino board. In this chapter, we are using the Trinket board
from Adafruit, but you could also use an Arduino micro board, which is very similar
in size. These boards are some of the smallest Arduino boards that offer most of the
functionality of a standard Arduino board.
[ 63 ]
LED Glasses
Soldering all the wires in place might be tricky. I started by gluing the board to
the inside of the frame and then soldering the wires one by one. I would suggest
that you place them where they fit best. You can always switch the layout in the
code later on. In Figure 3.7 you will see what it might look like once all the wires
are connected:
Take your time soldering all the wires in place. I admit that even someone with
good soldering skills might find this project a bit tricky since it requires some
unconventional soldering. I call this type of solder action "soldering" since you
usually end up with something that looks like it came from a movie. Usually, you
solder components on a flat surface, but with wearable projects like this one you
need to be a bit creative when it comes to soldering things together. Eventually you
will end up with an inside that is as impressive as the outside.
[ 64 ]
Chapter 4
Next, we will move on to the programming side, and this is where we get to see the
glasses in action. For the programming part, we will power the glasses via the USB
cable, and once we are done we will add a battery, then you will be ready to head
out into the night to impress everyone.
Figure 3.8: The FTDI serial to USB converter and the Trinket board
Normally, you solder male pins to the end of the Trinket board that connects to the
FTDI converter, but in this case we want to keep the Trinket board as flat as possible
and we don't want sharp pins on the inside of the glasses that might hurt your eyes. So
the trick is to just attach the male pin headers to the FTDI converter and hold it in place
while programming the Trinket board. Once in a while there will be glitches in the
connection and the upload will fail. This is probably due to the FTDI not connecting
properly to the Trinket board. However, this is not a big problem since you can just
start the upload over again while making sure the pins have a good connection.
[ 65 ]
LED Glasses
Now let's make a sketch that checks that all of the LEDs light up. In order to do
so, we will loop through the LEDs one by one to see that everything works as it is
supposed to. The Trinket is programmed as a normal Arduino. Uno board, so make
sure you select this type in the board menu Upload the following code and check
the LEDs in front of the glasses:
/*Collect all the positive columns pins in one array. You need to make
sure that these pins correspond to the direction you have placed the
columns in the glasses*/
int powerPin[]={
3,4,5,6,8,9,14,16,17,18,19};
/*Collect all the negative row pins in one array. Again make sure they
are added in the same order corresponding to the glasses*/
int gndPins[]={
10,11,12};
void setup(){
/*In order for the matrix to work we need to be able to control
our gnd lines in the matrix. The trick is to use all pins as output.
When we turn the gnd pins HIGH we will be able to block the ground
connection*/
for(int i=0; i<20;i++){
pinMode(i,OUTPUT);
}
//Turn all the gnd pins HIGH in order to keep all LEDs off
for(int j=0;j<3;j++){
digitalWrite(gndPins[j],HIGH);
}
}
void loop(){
//Run the function
looper();
}
void looper(){
/*In this function we run through all the LEDs using two for loops
starting by opening a gnd connection*/
for(int i=0; i<11;i++){
digitalWrite(powerPin[i],HIGH);
//Once a gnd pin is accessible we turn on one of the LEDs
for(int j=0;j<3;j++){
digitalWrite(gndPins[j],LOW);
delay(50);
digitalWrite(gndPins[j],HIGH);
delay(50);
[ 66 ]
Chapter 4
}
digitalWrite(powerPin[i],LOW);
}
//Loop everything backwards
for(int i=10; i>=0;i--){
digitalWrite(powerPin[i],HIGH);
for(int j=3;j>=0;j--){
digitalWrite(gndPins[j],LOW);
delay(50);
digitalWrite(gndPins[j],HIGH);
delay(50);
}
digitalWrite(powerPin[i],LOW);
}
}
Making a pattern
In the next code example, we will implement some pattern designs. These patterns
are stored in arrays that correspond to the layout of the LEDs in the glasses. We can
draw our patterns in code and later loop through the array and activate the LEDs.
When the code is formatted as it is in the next sketch, we get a visual repetition of
the pattern. A 0 in the array represents a turned off LED in the same position in the
matrix and a 1 represent an LED that is turned HIGH:
/*Collect all the positive columns pins in one array. You need to make
sure that these pins correspond to the direction you have placed the
columns in the glasses*/
int powerPin[]={
19,18,17,16,14,9,8,6,5,4,3};
/*Collect all the negative row pins in one array. Again make sure they
are added in the same order corresponding to the glasses*/
int gndPins[]={
[ 67 ]
LED Glasses
12,11,10};
//This is a two dimensional array that holds the pattern
int pattern[3][11] = {
{1,1,1,1,0,0,0,1,1,1,1 },
{0,1,1,0,0,0,0,1,0,0,1 },
{0,1,1,0,0,0,0,1,1,1,1 }
,
};
//Variable to store the refresh rate on the led display
int refreshRate=200;
void setup(){
//Declare all pins as outputs
Serial.begin(9600);
for(int i=0; i<20;i++){
pinMode(i,OUTPUT);
}
//turn all the gnd ports High to keep them blocked
for(int j=0;j<3;j++){
digitalWrite(gndPins[j],HIGH);
}
}
void loop(){
//Run the pattern function
displayPattern();
}
/*Function that runs through all the positions in the pattern array*/
void displayPattern()
{
for (byte x=0; x<3; x++) {
for (byte y=0; y<11; y++) {
int data =pattern[x][y];
//If the data stored in the array is 1 turn on the led
if (data==1) {
digitalWrite(powerPin[y],HIGH);
digitalWrite(gndPins[x],LOW);
delayMicroseconds(refreshRate);
digitalWrite(powerPin[y],LOW);
digitalWrite(gndPins[x],HIGH);
}
//If it is something else turn the led off
else {
[ 68 ]
Chapter 4
digitalWrite(powerPin[y],LOW);
digitalWrite(gndPins[x],HIGH);
}
}
}
}
[ 69 ]
LED Glasses
In my beginner Arduino classes, the Knight Rider example is a classic. This example
is inspired by the 80s hit show Knight Rider with David Hasselhoff. To be more precise,
the example is inspired by the robotic car featured in the show, which is called Kit. In
the front of Kit there is a small LED display that shows a bouncing light effect. This is
the effect we will recreate on the front of the glasses.
The code example is fairly simple and does the same thing as the test sketch, but
instead of lighting up only one LED at a time we will light up an entire column.
We will move the light column from left to right and once we hit the end of the
glasses, we will move the column back again:
int powerPin[]={
19,18,17,16,14,9,8,6,5,4,3};
int gndPins[]={
12,11,10};
int refreshRate=200;
void setup(){
for(int i=0; i<20;i++){
pinMode(i,OUTPUT);
}
//
for(int j=0;j<3;j++){
digitalWrite(gndPins[j],HIGH);
}
}
void loop(){
nightrider();
}
//
void nightrider()
{
/*Instead of starting to loop through the columns we loop through
the row*/
for(int i=0; i<11; i++){
/*Then we loop through the column
for(int j=0; j<3; j++){
/*In order to perceive that the column is lit we need to loop it a few
times*/
for(int k=0; k<50; k++){
/*Then we light the column
[ 70 ]
Chapter 4
digitalWrite(powerPin[i],HIGH);
digitalWrite(gndPins[j],LOW);
delayMicroseconds(refreshRate);
digitalWrite(powerPin[i],LOW);
digitalWrite(gndPins[j],HIGH);
}
}
}
/*Once we have reached the end of the glasses we do the same thing
backward*/
for(int i=11; i>0; i--){
for(int j=3; j>0; j--){
for(int k=0; k<50; k++){
digitalWrite(powerPin[i],HIGH);
digitalWrite(gndPins[j],LOW);
delayMicroseconds(refreshRate);
digitalWrite(powerPin[i],LOW);
digitalWrite(gndPins[j],HIGH);
}
}
}
}
Once your code is done, upload it to the board and enjoy. In order to show off your
new glasses, we need to finish up the circuit by attaching the battery to the glasses so
you can walk around with them (since being forced to be connected to a USB ports at
all times might not look as cool). Any battery between 3-5V will work for this project,
and the more amperes the battery has, the longer the glasses will stay on. However,
large ampere batteries are also bigger. The smallest lithium battery I have found is the
3.7V 150mAh battery, which I recommend. There are smaller ones with less amperes
but this type will still fit your glasses and give you enough power to keep the glasses
on long enough for you to impress a few people.
Before you connect the battery, you need to solder wires from the JST connector to
the board. The pins for external power on the Trinket board are marked BAT+ for
the positive connection. Next to this pin there is a pin marked with only a G for
the ground connection. This connection is connected to the negative side of the JST
connector. In order to figure out which pin is which on the JST connector, check with
the battery cables. Usually, these cables are red and black; the red one is the positive
and the black one is the ground. The design of the glasses should leave enough space
on the inside of the frames to place a small battery. Figure 3.9 shows what it might
look like. I recommend gluing the battery in place using hot glue, but be careful
not to heat the battery for too long or it might explode. This might sound scary,
but you would need to heat it for some time before it explodes. However, I always
recommend caution when combining heat and batteries.
[ 71 ]
LED Glasses
As you might have noticed by now, visibility is limited in these glasses and it has to
be fairly dark for the light to be visible, so be careful when using them. You can still
look cool while keeping safe.
In Figure 3.10 you will find my co-worker Johannes at the university showing
off the finished glasses. Unfortunately, pictures do not show the full effect of
animating the LEDs, but hopefully you will be close to finishing your pair by the
time you read this.
[ 72 ]
Chapter 4
Summary
In this chapter, you learned how to create an LED matrix in a pair of custom-made
LED glasses. The principles behind the LED matrix are the same as in any matrix that
you might use in another project. On the code side, we had a look at some pattern
designs and how to generate animations. This chapter introduces the basic concepts,
but as you progress you can build upon this knowledge and develop your own
patterns and animations.
In this chapter, we also had a look at what the custom casings looks like when cut
using a laser cutter. If you do not have access to a laser cutter don't worry, as you can
still achieve the same results using cutting tools and materials such as plastic, wood,
or cardboard if you like. The only difference is that it might take a bit longer to cut.
The material for the frame also gives you a lot of personalization options, so I
recommend you test a few materials before you decide.
The remaining projects will also implement laser-cut designs, but remember that
the casings for all the projects in this book are just examples of how it can be done.
I encourage you to develop your own designs since it is more fun to personalize
your creations, and let the designs in this book act as inspiration.
[ 73 ]
www.PacktPub.com
Stay Connected: