Arduino Class
Arduino Class
Arduino Class
ARDUINO CLASS
4 Lessons Beginner Level
This class will introduce you to the Arduino world. You'll learn the basics, build your rst project, and
so much more. Each lesson builds on your skills, infusing new knowledge and techniques along the
way.
You'll start simple with exercises that demonstrate basic breadboard wiring and coding inputs and
outputs. Then you'll level up to soldering and coding addressable NeoPixel LED strip and start
planning your own projects with your fun new hobby.
This class will launch your Arduino journey and give you the skills and con dence to take on almost
any Arduino project you may nd or create in the future.
Wa nt t o s e e a n Arduino proje ct ha ppe n in re a l-t ime ? Check out a full video of my
webinar on creating an Easy In nity Mirror, on the Instructables Facebook page!
If you've made an awesome project that uses Arduino, try writing an Instructable about it and enter
it in an Instructables contest to win some great prizes!
Class Author:
bekathwia
Becky Stern has authored hundreds of tutorials in everything from wearable electronics to knitting. Before joining Instructables as
a content creator, Becky worked as a senior video producer for MAKE Magazine and then as the director of wearable electronics
at Adafruit Industries. She lives in New York City and enjoys riding her motorcycle, making YouTube videos, and collecting new
hobbies. Her work has been featured by VICE, the BBC, The Late Show with Stephen Colbert, Engadget, CNN, Business
Insider, Forbes, and Science Friday.
Lesson 3: Input/Output
Now that you've got the basics, let's add some
interactivity and learn about inputs! This lesson walks you
through using pushbuttons, the serial monitor, analog
inputs with a potentiometer, and using small motors.
Have you ever wanted to tinker with technology? Arduino exists to help
creative people and techno-beginners build projects with electronics. As a
platform, it fast-tracks users to success by helping ease the setup burden and
learning curve usually associated with electrical engineering and computer
science.
Arduino is the best way to get started with microcontroller programming and
building your own circuits that sense and react to the world around them. In
this class, we'll get creative with electronics and get comfortable with the
concepts you'll use to launch your long and fruitful Arduino journey.
The name Arduino de nes several layers of your experience:
s o f t w a r e - used to compose your programs and communicate with the
hardware, called an integrated development environment (Arduino IDE)
ha r d w a r e - refers to the boards themselves (e.g. Arduino Uno)
p r o g r a mmi n g l a n g ua g e - the Arduino programming language is based on C
t r a d e ma r k - Other brands may manufacture Arduino-compatible hardware, but
only some boards are o cial, and owning their trademark provides some unique
protections. For instance, it allows the hardware and software to remain open
source.
Early on, you'll do breadboard experiments to increase your familiarity with key
concepts of electricity, components, and coding in the Arduino language.
Then you'll acquire a variety of skills for building and programming, including
soldering, understanding the power requirements of your Arduino projects,
installing code libraries, and controlling a strip of addressable LEDs. You will
graduate with the con dence to take on in nite Arduino projects in the future!
This lesson is a complete list of the supplies you'll need to complete this class.
To make it a bit easier to get everything at once, I've created an Adafruit
wishlist containing most of the components and tools. To get started with the
bare minimum, you can complete most of the core exercises with the contents
of the Adafruit Arduino Uno Budget Pack. If you're using a di erent kit, some
of the components may di er from those shown in the photos throughout this
class. You may also complete this entire class virtually, for free, using Tinkercad
Circuits!
For the basic exercises:
To complete the Skills Infusion lesson (here's a great toolkit with almost
everything you need):
Soldering iron and solder
1 meter of 60/m RGBW NeoPixel strip
Small needlenose pliers
Flush diagonal cutters
Wire strippers
Multimeter (optional but very handy)
Tweezers
Third hand tool
Desoldering braid or solder sucker
Solderless breadboard - This device has strips of metal inside and many holes
that allow you to connect components quickly and easily. A mounting plate is
recommended, to keep the breadboard and Arduino Uno together. You'll
connect to the Arduino with wires (breadboard wires are great but you can
also use solid core hookup wire).
Soldering tools - The Skills Infusion lesson teaches you how to connect wires to
LED strip with a soldering iron, which heats the components enough to ow
solder (an easy melting alloy) between them. Any basic iron will do! Wire
strippers remove insulation to expose the conductor inside, pliers and
tweezers help you position components, and a third hand tool helps keep
everything steady. Flush snips do a great job trimming excess wires and
component leads after soldering. Wear protective eyewear when soldering and
clipping wires, and solder in a well-ventilated area.
The Arduino IDE (software for composing code and sending it to your board)
runs on Windows, Mac OS X, and Linux. Head to the download page and click
the option that best describes your system. While the software is downloading,
connect your Arduino board to your computer with a USB A to B cable ( at to
boxy, typically used for printers). The green LED next to the label ON should
turn on, and the orange LED next to the label L should begin blinking.
Depending on your operating system, your software installation procedure
will vary. On Windows, run the installer, which will also install the necessary
drivers (provided your Arduino board is plugged in). On OS X, drag the
Arduino app into your Applications folder (no drivers necessary). For more help
with Windows if the installation doesn't go smoothly, refer to Arduino's
detailed instructions. If you prefer not to download software, most of the class
can also be completed using the Arduino Web Editor.
Open the Arduino application and load up the rst code example by selecting
File -> Examples -> 01.Basics -> Blink.
Now click the Upload button to transfer the Blink example code to the Arduino
board. The LEDs labeled RX and TX will ash, and the software will show a
message "Done uploading." Moments later the LED labeled L will begin
blinking as it did when you rst plugged it in.
Congratulations, you're ready to begin the next lesson, where we'll dig into the
code you just uploaded, as well as build your rst few LED circuits and discover
how to control them using basic Arduino programming concepts.
If your port doesn't appear, or you get an error when trying to upload, refer to
Arduino's detailed troubleshooting guide, which covers many other common
issues.
Arduino History
The Arduino Uno we'll use in this class is the agship development board of
the Arduino brand, and it is the latest iteration in a long line of boards with a
mission to make it easier for non-engineers to use.
Other boards with specialized functions have been released in the Arduino
product line. Need more inputs and outputs? Use an Arduino Mega. Want a
smaller circuit board and USB keyboard functionality? Use an Arduino Micro.
And so forth. O cial Arduino boards are all natively supported by the Arduino
software.
Roll up your sleeves and let's dig in! In this lesson, we'll conduct some basic
breadboard experiments to introduce you to the basic Arduino concepts and
work ow.
Supplies
Solderless breadboards are for prototyping circuits quickly and easily. You can
think of it as akin to a dry-erase board, great for speedy brainstorming and
experimentation. Breadboards allow you to connect components using multi-
port metal sockets. The conductive parts of the breadboard allow electrons to
ow between the things you plug into it.
The rst circuit we'll build on the solderless breadboard connects a red LED to
the Arduino Uno board. Let's start out slowly, with one wire connection at a
time. Follow along with the same colored wires to make it easier on us both.
Double check that your USB cable is disconnected before doing any wiring to
your board. Grab a red wire and plug one end into the pin marked 5V on the
Arduino board. Plug the other end of the red wire into the breadboard rail
marked with a red line— this will be your power bus.
Connect another blue wire from any pin on your ground rail to another
horizontal row on your breadboard (row 18 shown above).
Now grab a 1K resistor (stripes are brown-black-red-gold), and plug one of its
wire leads (doesn't matter which) into the same row as the blue wire. Resistors
all look similar, except for the stripes used to indicate their value.
ht t ps://player.vimeo.com/video/192704 689
Another way to guess the polarity of an LED is by looking inside the lens at the
anvil (bigger piece of metal) and post (smaller piece of metal). The anvil is
usually the cathode, but as you can see in the above video, not all LEDs
observe the same polarity conventions. The only way to be totally certain of its
polarity is to test it. To learn more in-depth about resistors and LEDs, check out
the LEDs lesson in the Instructables LEDs & Lighting Class.
Plug in your USB cable and the LED should immediately start to blink! It's
programmed to blink whatever's connected to pin 13. That includes the
onboard LED you saw in your software setup as well as the one you just wired
up.
If your LED isn't blinking, unplug your USB cable, then reverse your LED and
replug your USB; maybe the LED was just plugged in backwards (which won't
damage it, but won't light it up, either). Or perhaps one of your other wires or
resistor aren't connected correctly. Double check your connections against the
diagram of the circuit:
ht t ps://www.t inkercad.com/embed/heWjQPZNfIg?zoom=false
You'll use the Arduino IDE to manipulate programs like this one and send
them to your Arduino board to run. You've already loaded this sketch onto
your Arduino board in the software setup from the previous lesson, but a
refresher can't hurt: you can nd this sketch and many other examples used in
this class through the Arduino software menu (File -> Examples -> Basics ->
Blink).
Example sketches make great starting points for experimentation and your
own projects down the line. These examples are invaluable to your Arduino
learning experience; use them! It's common to make lots of typos when writing
your rst code, which can cause confusing errors. The examples come in handy
is when you want to x up your own not-working code (called de bug g ing ).
Comparing your work to de nitive examples of working code can be one
helpful strategy to help debug your code.
Let's take a closer look at the elements of this basic Arduino sketch. First up is a
little note:
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
Next up is a v a ria ble declaration. You can think of a variable as a bucket for
some information. Variables, like buckets, have sizes and shapes to hold
di erent kinds of information. Variables also have names, like a mandatory
label on the bucket. This line of code de nes a variable of type int , which
means integer. Remember back to primary school math class, when you might
have learned that integers are whole numbers (positive or negative). So we
have a bucket that can hold an integer. It's label is led but could just as easily
be "MyLEDPin" or any single word (letters and numbers only, case sensitive)
because this part of the variable declaration is up to you. I strongly advise
using descriptive names for your variables so you can keep track of what your
program is doing!
As the comment suggests, anything between this line and the closing curly
brace } is part of the s e t up , a section of code that runs once per session.
Code inside the setup executes one time when your board rst powers up, or
when you press the Arduino's reset button.
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
Pins 0-13 on your Arduino board are digital i/o pins, which means they can be
either inputs or outputs. pinMode(); is a f unct io n , a shorthand way to refer to
subset of commands "under the hood," so to speak. Arduino shows you it
recognizes certain elements of code by changing its text color. If ever a
keyword isn't changing color as you type it in Arduino, you probably have a
misspelling, capitalization error, or other typo. These pieces of information
passed to functions are called a rg um e nt s . Since the variable led will serve up
its contents anytime you type it, the pin number passed to pinMode(); is 13, and
the state is OUTPUT. This sets up pin 13 to control an LED, and the curly brace
closes the setup.
// the loop routine runs over and over again forever:
void loop() {
This is the main part of an Arduino sketch, where actions like checking input
pins and controlling output pins usually happen. Everything between this line
and its closing curly brace } will occur on repeat until the board loses power.
First up in the loop is a function called digitalWrite(); , which takes two pieces of
information: a pin number, and a HIGH (on) or LOW (o ) state. These pieces of
information passed to functions are called a rg um e nt s . Since the variable led
will serve up its contents anytime you type it, the pin number passed to
digitalWrite(); is 13, and the state is HIGH (on). This line of code causes the LED in
delay(); is another one of Arduino's built-in functions. It pauses the program for
an amount of time, written in m illis e co nds . This line of code pauses the
program for 1000ms, or one second.
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
This line pauses the program for one second, and the curly brace signi es the
end of the loop, which begins again immediately. So to summarize, the
program turns an LED on and o at one second intervals. Let's try switching
up that interval. Modify the number of milliseconds in one or both of your
delay(); statements. For instance you could create a more uneven blink:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for two seconds
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a half second
}
Try uploading your modi ed blink sketch to your Arduino board. Did it behave
as you expected it would?
Well done! That was a lot of information. It's ok if you don't quite understand
every little thing yet. Like learning any language, the Arduino programming
language has its own syntax and structure you must navigate, which will
become more familiar with regular practice. The most important thing to
remember is that you can work with code without knowing everything about
programming. As you go through the exercises in this class, I encourage you to
leave a window open loaded with the Arduino language reference page, which
describes each element and provides sample usage.
Now that you've got the basic idea of how to control a single LED, let's add
some more! Grab the rest of your red LEDs and 1K resistors. Unplug your
Arduino from USB/power if it wasn't already. It's smart to disconnect power
any time you are changing your circuit.
Connect the two pairs of rails on your solderless breadboard: plug a wire
connecting both power buses (red, +) and another wire connecting both
ground buses (blue, -). This is a commonly used con guration, since now you
can easily access power and ground on both edges of the breadboard. Bend
the leads of your resistors to 90 degrees and trim the ends to about a quarter
inch (6mm) from the bend.
Arduino Class: Page 28
You don't technically have to bend and trim your resistors, but they sure do
tidy up your breadboard. Replace the resistor on your breadboard with a tidier
one and see what a huge di erence it makes in the legibility of your circuit.
And you're less likely to create an accidental short circuit this way, too.
Let's add the new LEDs to the thus-far-unused half of the breadboard. Start by
connecting a tidy resistor from ground (sockets along the blue line) to a row of
the breadboard. Plug a red LED into the breadboard, connecting its shorter
(negative) lead at the same row as the resistor.
Add the remaining resistors and LEDs in the same pattern. Remember that
resistors can plug in either orientation, but LEDs have po la rit y and only light
up when electricity ows in one particular direction through them.
Move the yellow wire from Arduino pin 13 to pin 7. Connect another yellow
wire from Arduino pin 6 to the positive lead of the next neighboring LED.
ht t ps://www.t inkercad.com/embed/6XeW1sjPzXN?zoom=false
Click OK if you see a prompt to put the program in its own folder. If your
resulting le has all the code bunched up on one line, you are probably using
an old version of Arduino, and should update to the latest version. If you
prefer, you may also select and copy the code from the module above and
paste it into a new (blank) Arduino sketch (File -> New, then replace the default
contents with the code you copied from above).
Arduino Class: Page 29
Plug in and upload the code to your Arduino Uno board. You may have to
select your port again from the tools menu after replugging. Let's learn how
to code a light sequence by taking a closer look at the program elements:
/*
For Loop Iteration
The circuit:
* LEDs from pins 3 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This rst part is just a long comment. You already learned about single line
comments, and now you know about multi-line comments, signi ed with a /*
to start and */ to stop.
int timer = 200; // The higher the number, the slower the timing.
A variable is declared! It's an integer called "timer", and this line sets it equal to
200. As you may have noticed, most lines of Arduino programs end with a
s e m ico lo n . When writing and modifying your own Arduino sketches, watch
out for missing semicolons as they will cause compiling errors that will trip you
up.
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 3; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
You'll notice that there will usually be more than one way to accomplish the
same tasks with Arduino programming. Coding is similar to making things in
your workshop: you tend to use whatever tools you have. So lets use a for loop
for something fun... animation!
void loop() {
The loop starts out with the same f o r lo o p as earlier, incrementing from the
lowest pin number to the highest. Inside the for loop, it turns on the LED at
thisPin , pauses for 200ms (set earlier as timer), then turns that LED o before
looping again with the next LED.
// loop from the highest pin to the lowest:
for (int thisPin = 7; thisPin >= 3; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
The next part of the code is another for loop, but this one starts at the highest
pin and uses thisPin-- , which means the same thing as thisPin = thisPin - 1 (itself minus
one), and exits the loop when thisPin is no longer >= 3 (greater than or equal to
three, aka 2). The nal closing curly brace closes the main loop. So this program
lights up each LED in order, then reverses the order and lights them up again.
Download
https://www.instructables.com/ORIG/FAL/YLM1/J1V7XOEX/FALYLM1J1V7XOEX.ino
…
Turning LEDs on and o is great and all, but now let's make an LED fade in and
out gradually using a function called analogWrite(); . Unplug your USB cable and
remove all but the rst LED from your breadboard, and move its yellow wire
connection to Arduino pin 9.
ht t ps://www.t inkercad.com/embed/bo3zmg7hInW?zoom=false
Plug in and upload the sketch to your Arduino Uno board and observe your
LED fade on and o .
Lines 16 through 18 declare three variables used in the program. The setup
con gures pin 9 as an output on line 23. On line 29, the function analogWrite(); sets
pin 9 to whatever the variable brightness is at the given time. On line 32,
brightness is incremented by 5 ( fadeAmount ). Line 35 uses an if s t a t e m e nt to
check if brightness using comparison operators. If brightness is less than or
equal to <= zero, or || greater than or equal to >= 255. If the statement is true,
the code inside is executed, otherwise it's just skipped. So this code increases
brightness until it reaches or exceeds 255, then sets fadeAmount to -5 and
decrements brightness until it reaches zero (or dips below zero). The delay at
the end prevents the code from running so fast that you can't see the e ect.
Try changing the value of fadeAmount and upload the code to your board.
How does changing this variable a ect the appearance of the fading?
The Arduino board is only capable of generating digital signals (HIGH and
LOW ), but analogWrite(); simulates the appearance of brightnesses between
on and o using puls e w idt h m o dula t io n ( PW M ) . The LED ashes on and
o very quickly, and your eye interprets a dimmer light. The ratio of time the
LED spends on vs. o determines how bright or dim the LED appears. Only
certain pins are capable of PWM, and they are labeled on the board with
squiggles ~ next to the pin number. PWM can also be used to control the
speed of a DC motor, which we'll do in a later lesson.
RGB LEDs
Arduino Class: Page 33
Additive (light-based) color has three primary colors: red, green, and blue.
Simultaneously controlling the brightness of one LED of each of these colors
can create almost any color of light. Color changing LEDs like those used in the
nal project work the same way, but the LEDs are all together in a very small
package called an RGB LED . Let's build our own RGB LED from three 5mm
LEDs in your kits. In the Adafruit kit recommended for this class, these three
LEDs have clear lenses, so we'll have to plug them in to determine which LED is
which. LEDs with clear lenses can be any color! If you're using a di erent kit,
just nd one red, one green, and one blue LED (clear or colored lens). Unplug
your USB cable and swap out the red LED for one of the clear-lens LEDs, then
plug the USB back in.
What color is the LED? If you nd the red one on the rst try, set it aside and
repeat the process to determine the color of the the other two LEDs.
ht t ps://www.t inkercad.com/embed/jTfaA3ssc6S
The unfamiliar part of this code is the function setColor(); . It's a custom function,
de ned below the loop() has ended.
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
A f un c t i o n d e n i t i o n declares a name, and what type of arguments the function will take,
which you can think of as the con gurable settings you'll want to change each time you execute
the code it contains. In this simple function, three integer values are written to the three LED
pins using analogWrite(); .
setColor(255, 255, 0); // yellow
Each time this function is called in the main loop, the program executes the
code in the function before continuing through the main loop. In this case, the
arguments are used as the brightnesses of each LED. The scale for brightness
is 0-255 because each color is de ned using one byte, which allows for 256
distinct patterns.
ht t ps://www.t inkercad.com/embed/bclfJGFygLR?zoom=false
So far you've learned to control LEDs with code, which is one use of Arduino's
o ut put s . This lesson builds on outputs by adding input s . Your Arduino
board can be programmed to listen to electrical signals and take actions based
on those inputs. We'll put together a digital input circuit with a s w it ch , and
an analog input circuit with a po t e nt io m e t e r (variable resistor).
Supplies
Digital Input
First, connect the LED to Arduino pin 13 like you did in your rst circuit, with a
wire from pin 13 to the positive lead of your LED, and a 1K resistor connecting
the LED's negative lead to ground.
Next, plug in the pushbutton so that it straddles the center dividing line of
your breadboard. It should click into place snugly. Connect the 10K resistor
from one lead of the switch to the breadboard's 5V power rail. Connect a wire
to this same row and plug it into Arduino pin 2.
Arduino Class: Page 38
Connect the switch's diagonal lead to ground.
You can nd this example in the Arduino software by navigating to File ->
Examples -> 02.Digital -> Button. Open it on your computer, and upload it to
your Arduino Uno board. The LED should light up, but turn o whenever you
press the pushbutton.
command is executed. If not, the code contained inside the else { is executed
instead: digitalWrite(ledPin, LOW); . If statements can exist alone, or with one or more else
statements.
Upload the updated sketch to your Arduino Uno board, and check that the
button now turns the LED on instead of o .
Arduino pins have built-in pull-up resistors on many of the pins (tiny ones,
inside the chip just for this purpose), and you can access one by enabling it in
the setup:
pinMode(buttonPin, INPUT_PULLUP);
Change this line of code in your sketch and remove the resistor from your
circuit. Upload the code; its behavior should remain the same.
ht t ps://www.t inkercad.com/embed/f8aWEyOM4 IE
Analog Input
You can get the code from the Tinkercad Circuits module as you have for
previous lessons, or nd the example by navigating to File -> Examples ->
03.Analog -> AnalogInOutSerial.
Plug in your USB cable and upload the sketch to your Arduino Uno board.
Open the serial monitor and observe it and the LED as you twist the
potentiometer.
The values read by the analog input are printed in the rst column, and the
brightness values applied to the LED are printed in the second column.
ht t ps://www.t inkercad.com/embed/7l0BoHp3X7A
Power up your board and see what e ect turning the knob has on the speed of
the motor (use a piece of tape to make it easier to see the motor shaft
spinning).
The motor recommended for this circuit draws less than 250mA, but a larger
one could require more power than your computer's USB port can deliver. To
power bigger motors, lots of LEDs, and other circuits that use more power,
you'll need to use an external power supply, such as an AC adapter or battery
pack. Additionally, for any larger of a motor, you'd also need a larger transistor.
We'll learn how to calculate your circuit's power needs in the next lesson, but
by popular request, here's the same motor circuit powered by an external 6V
battery pack (separate power rails, common ground):
ht t ps://www.t inkercad.com/embed/9rJr3EylTCw
In this lesson, we'll cover a few important concepts you'll need to understand
to create your own Arduino projects. We'll get up to speed on soldering, code
libraries, addressable LEDs, organizing code with functions, and calculating
the power requirements of your projects.
Supplies
Soldering
A third hand tool helps immensely when it comes to stabilizing your work,
especially as you're learning to hold the iron steady. I tend to avoid ca eine
around workshop time, too. I like to put a little bit of heat shrink tubing over
the jaws of my third hand tool, to soften its bite.
Cut a piece of your NeoPixel strip 19 pixels long, using your ush diagonal
cutters to clip straight across the middle of the copper pads. Remove it from
the silicone sheathing and identify the input— the arrow markings on the
strip point away from it. Clip the input end it into your third hand tool with the
back of the strip facing you. Tin the center copper pad by touching your
soldering iron to it, then applying a small amount of solder. Move your tip
around the copper pad to spread the bead of solder around.
Now that your two components are tinned, it will be easier to solder them
together. Pick up a your white wire in one hand and your soldering iron in the
other. Hold the tinned wire end to the tinned copper pad, and reheat the two
components at the same time. The solder on each should ow together, if it
doesn't, you may need to apply some more. Remove your iron before letting
go of the wire, so the solder has a chance to cool, securing the wire in place. If
you nd it di cult or too hot to hold the wire with your ngers, use a pair of
tweezers or pliers.
Flip over your NeoPixel strip and similarly tin and solder wires to the other two
copper pads (red wire for 5V, black wire for GND). It doesn't really matter which
side of the copper pad you solder to, but alternating sides gives your solder
joints a little more elbow room. Trim any excess wire protruding from the
copper pad. Now you're ready to plug the strip into your breadboard and get
the LEDs glowing (we'll do that next)!
Practice your soldering skills again by attaching wires to two diagonal leads of
a pushbutton. Tin the wires and the pushbutton leads, then reheat them to
allow the solder to ow. Set this pushbutton aside for the nal project.
In your Arduino software, navigate to Sketch -> Include Library -> Manage
Libraries...
When the Library Manager opens, search for "NeoPixel" in the upper right
eld. Optionally select a version of the library from the dropdown menu, and
click the "Install" button. Now you're all set to use the NeoPixel library in your
Arduino sketches! You can use the library manager to install all kinds of fun
extensions to the Arduino programming language that help you interface
with sensors, motors, and more.
Take a close look at your pixel strip. Each pixel contains a very small RGB LED,
which can theoretically create any color of light. However, generating pure
white poses a challenge for RGB LEDs and often leaves users disappointed in
the tinted or poorly mixed quality of light produced. For this reason, the RGBW
strip includes a white LED inside its package as well.
Now that our NeoPixel strip has wires attached to it, let's connect it to the
breadboard. The 5V wire (red) goes to your breadboard's power bus, and the
ground wire (black) goes to the breadboard's ground bus. Connect the data
wire (white) to Arduino pin 6.
ht t ps://www.t inkercad.com/embed/jZpGsoNCnuT
#define PIN 6
#define NUM_LEDS 19
#define BRIGHTNESS 50
The rst section instantiates the NeoPixel strip and sets up the con gurable
bits of the program like the pins connected to the NeoPixel strip and button,
the number of pixels, and global brightness level. #define statements are similar
to variable declarations, but are used for information that does not change
while the program is running. They take up less memory than regular variable
declarations.
void setup() {
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
strip.show(); is used any time you want the pixels to change. Setting the pixel colors
and showing the latest changes are broken up into two separate commands.
whiteOverRainbow(20,75,5);
pulseWhite(5);
// fullWhite();
// delay(2000);
rainbowFade2White(3,3,1);
}
The main loop just calls other functions. Let's take a closer look at colorWipe(); ,
de ned just below the main loop, and takes two arguments: a color
( strip.Color(r, g, b, w) ), and a speed value.
The function de nition starts with what type of data the function will re t urn ,
or send back to the main program. In this case the function returns nothing,
so the word v o id is used at the start of the de nition. Next is the name of the
function, which is up to you. Then in parentheses are the arguments the
function takes, in this case a 32 bit unsigned integer called "c" and an 8 bit
unsigned integer called "wait." Inside the function, these lo ca l v a ria ble s are
used to reference the information you passed to it from the main loop (or from
another function). The function itself steps through all the pixels in the strip
(using a for loop and a NeoPixel function called strip.numPixels(); ), coloring and
showing each one before moving to the next. The other functions in the RGBW
strandtest program work the same way, and use clever color math to achieve
stunning light patterns.
You can easily modify colorWipe(); to start coding up your own unique
animation. Try copying the whole function de nition, and change the name of
the function (or copy and paste this snippet just after the closing curly brace
of your main loop).
Then start playing around with the code. Say I want to light up a random pixel
in the strip instead of lighting them up in order. I could use Arduino's built-in
random(); function to pick a pixel, which generates a random number between
the two arguments:
strip.setPixelColor(random(0,strip.numPixels()), c);
It's quite likely you want to create Arduino projects that will function for some
time while enduring repeated movement or exposure to the elements.
Designing durability into a circuit requires some forethought of potential
failure modes, often only discovered through repeated prototyping and
improvement upon prior failure. Here are some tips on design and
construction for durability. Remember to read and follow manufacturers'
instructions and safety procedures when using any hazardous materials.
Pro t e ct t he po w e r s upply - The most important part of your circuit to
keep safe is the battery and power connections. A short circuit here could trip
a circuit breaker, permanently damage components, or cause a re.
Arduino Class: Page 59
St ra in re lie f - Remember that your circuit has both mechanical and
electrical connections. Sometimes they are one in the same, like the Arduino's
USB and power ports. However it's always a great idea to add mechanical
connections to your projects to prevent wires from tugging on their solder
joints. You can use zip ties to secure wires, and most circuit boards have
mounting holes for use with screws or hand sewing. For connections that will
bend repeatedly, use stranded wire instead of solid-core.
Kno w y o ur a dhe s iv e s - Using the right glue for the job is critical for your
circuit's durability! For instance, few things will actually stick to the silicone
sheathing that comes around LED strip. Only certain silicone adhesives will
provide a weatherproof seal in this case. Permatex 66B is my favorite for
NeoPixel strip's silicone sheathing. Any adhesive should be tested to check that
it bonds to both surfaces. Hot melt glue was convenient for the in nity mirror
project in this class, but it stinks for durability. Instead I highly recommend
E6000 craft adhesive, or its cousin Quick Hold. These take longer to dry but
stick to everything (except silicone) and dry clear and exible. To learn more
about adhesives, check out our Glue class!
Hum idit y & m o is t ure - It's important to protect your circuit from water,
which will cause shorts. If you're thinking of making an electronic costume, for
instance, did you consider that your evaporating sweat could be a factor?
Where will your circuit be located and what humidity/water conditions can you
expect there? Generally you can think of using coverings and coatings to
address this issue. You can nd completely waterproof enclosures for your
projects, cover your circuit with waterproof fabric, and use waterproof
adhesives to seal up any openings. I often use clear nail polish to protect bare
components on costumes/wearables. Clear spray paint is also a good option,
however I'm not a big fan of the new hydrophobic coatings like NeverWet.
They were designed for things like the circuit board inside your phone, and
don't function well outside that context because of their extreme physical
fragility, sensitivity to sunlight, and highly toxic nature.
However water is not a circuit's nemesis! If the battery/power supply is
removed, most circuits won't be damaged by water, so long as they dry out
before being plugged back in (and weren't left a long time to corrode).
Exceptions exist for components that water can get inside, like microphones.
But generally, it's ok to hand wash your Arduino projects after unplugging the
power and removing any batteries.
UV a nd t e m pe ra t ure uct ua t io n e xpo s ure - Over time, many plastics,
adhesives, and other protective materials break down when exposed to
sunlight. Wire sheathings may become brittle and crack open. Coatings may
break down and fail. Think about the temperatures your circuit is likely to
experience, too. Most batteries' lives are shortened by exposure to high or low
temperatures, for instance. Check the datasheets for your components to
learn their operating temperature ranges.
This is just the tip of the durability iceberg, folks. There are whole elds of
study devoted to the topic, in mechanical engineering, industrial design, and
materials science just to name a few. However for most projects, a bit of E6000
and some zip ties really go a long way towards keeping your projects alive.
If you completed all the lessons in this class, you're now ready to take on
countless Arduino projects, including your own designs. Don't know where to
start? Try my Easy In nity Mirror with Arduino Gemma. You may also nd many
of the early code examples to be great starting points when building your own
sketches. For your next class, consider Internet of Things, Electronics, Wearable
Electronics, or Robots, which will all deepen your understanding of some of
the concepts from this class.
Here are some projects from the Instructables community to help inspire your
next creation:
Have you made a project with Arduino you'd like to share? Please consider
writing an Instructable about it, and enter it in one of our frequent contests.
Thank you so much for taking my Arduino class! If you enjoyed your
experience, consider sharing it with a friend. And I'd like to receive your
feedback either way, so I can improve this and future classes.