♪
[buzzing]
Hi. Welcome to
the Qualcomm Thinkabit Lab.
I hope you'll be excited
to build an LED circuit
and get an Arduino
to get it to blink.
You will need an Arduino.
You will need a breadboard.
Hopefully, you've already
got it color-coded.
You'll need a resistor,
you'll need an LED,
and, of course, you'll need
a red and black wire.
Okay, so,
to make this easier,
let's make sure
we actually label our pieces.
I'd like for you to go ahead
and put a big circle
around your resistor
and write "resistor."
This way you don't forget
what it is.
Next, go ahead and put
a big circle around LED
and label it "LED."
And I want you to know
that LED is an acronym.
It stands for
"light-emitting diode."
Also, use
your observation skills
and notice that our LED
has two different size legs,
and our resistor doesn't.
What does that mean?
It means that our LED
has polarity.
I'll write that word down.
It's a cool word. Polarity.
That means that you have
two opposite ends.
We have a positive side
on our LED. It's the long stick.
Find that and put
a positive symbol next to it.
Then the short stick
will be our negative side.
That's what gives us polarity.
Lastly, make sure you have
a red and black wire.
How do I build
the LED circuit?
To cook a new dish,
what would you need?
A recipe, right?
A recipe lists
the ingredients you need
and how to put it together.
A schematic
is like a recipe.
It tells us how
to build our circuit.
So, let's write this word down.
And I love this word:
 schematic.
It's kind of fun to say.
Schematic. You should
try saying it. Schematic.
All right. What's one thing
all circuits have in common?
Power. So, let's draw
the symbol for power.
Draw a circle.
Have the positive side
and negative side,
a wire coming out
of positive,
and a wire coming out
of negative.
Next thing we need
is a resistor.
Why do we need a resistor?
We don't want
to blow up our LED.
Don't try it and think
you'll see some cool explosion.
It's just gone.
You wasted your LED.
Make sure that doesn't happen
by using a resistor.
We have a wire,
the bulk in the middle,
and then another wire.
And our resistor
looks like that.
There's a wire on this end,
this bulk in the middle,
and this wire here.
Then let's draw a symbol
for an LED.
We have a wire,
the bulk in the middle,
and another wire.
If I left it like that,
it would just be a diode.
To make
a light-emitting diode,
you need a squiggly line
coming out of it.
This is the positive side,
and this is the negative side.
But my schematic
is not complete.
They're not touching
each other,
and an incomplete circuit
will not work.
So let's complete
this circuit
by connecting all the ends
to each other.
To get power, we'll use our
Arduino like a fancy battery.
To do that,
connect your Arduino
using the USB cable
that you have,
and connect that Arduino
to your laptop.
When you've done that
correctly,
you'll notice a green light
on your Arduino.
Don't worry about
other lights.
So long as you have your
green light, you're good to go.
Now let's read our schematic
and build our circuit.
First, we'll create
this positive rail.
Notice I use the color red.
We use red because
we're going to use a red wire.
Also, when building circuits,
you want to color-code
your wires.
It makes it easier
for troubleshooting later.
So take your red wire
and stick it into the power side
of your Arduino
in the 5v hole, okay?
Find 5v,
which stands for five volts,
and take the other end
of your red wire
and put it in the red row
of your breadboard.
When you've done that correctly,
that entire red row
is essentially 5v.
So, take your red wire,
put it in 5v,
and take the other end
and put it in the red row
of your breadboard.
Okay, cool.
Looking at
our schematic again,
notice we have
this negative side too.
I'm using the black marker
because we're gonna use
the black wire.
And we want to create
this whole negative rail.
Also known as ground.
I'd like you
to take your black wire,
find GND of your power--
and it doesn't matter which GND
because they're all the same,
and GND stands for ground--
and take your black wire,
connect GND to the black row.
So now we've taken
the black wire,
and we went from GND
to the black row.
Cool.
Now, this is where you
really want to pay attention
because if you can follow the
logic of this simple circuit,
you could potentially build
any circuit from any schematic.
If you notice,
look at this resistor.
One end of this resistor
is metal-to-metal touching
the positive side
of my power.
So I want to recreate that
in the physical world, right?
I'm gonna take my resistor
and make sure that one end
of my metal piece
is metal-to-metal touching
that 5v that I've created.
To do that,
I take my resistor
and put one end
in the red row.
And when I've done that,
I've just created
this part of the schematic.
Then I'll take
the other end of my resistor
and put it in the blue row.
So I've designated
this side of my resistor,
and I put it
in the blue row.
Cool.
Now, looking
at my schematic
and following the logic
that I've provided so far,
where would my LED go,
and where would the positive
and negative sides of my LED go?
Notice that the positive side
is metal-to-metal touching
the other end of my resistor,
and my negative side of my LED
is metal-to-metal touching
my negative side of the power.
So, take your positive side
of your LED, the long stick,
and put it in the blue row,
and take the negative side,
the short stick,
and put it in the black row.
And you've got
a working LED circuit.
That is a purely electrical
engineering experience.
You should be proud
of yourself.
Now that you've got
your LED going,
wouldn't it be cool if we used
our Arduino to get blinking?
So, before we start working
with our code,
take your red wire
and leave it out of the Arduino.
Leave it hanging there
for a minute.
Now, go ahead and double-click
in Arduino.
It's the same symbol
as on your actual Arduino.
Go ahead and double-click on it,
and whenever you connect
a new Arduino,
make sure you're going
through the right com port.
It's like going through
the right door.
You want your message
to go through the right channel.
To do that, go to
"Tools: Find Port"
and find the com number that's
associated with your Arduino.
Click on it,
and you should be good to go.
Next, go ahead and open up
the blink example.
And the way that you do that
is you go to
"File: Examples, Basics,"
and then click on "Blink."
When you've done that,
expand it
so that you're not distracted
by anything else,
and then upload this code.
To upload it, click on the arrow
pointing right.
Click on that, and when
you hover over the buttons,
it tells you what it does.
Hover over the arrow pointing
right. It says "upload."
In the blue bar, you'll see
that it's uploading code.
Once it says "done uploading,"
take your red wire
and plug it into pin 13.
[buzzing]
If you've got
your LED blinking,
give yourselves
a round of applause
for successfully uploading
an example code.
Let's go through
these lines of code,
'cause I want you to understand
the basics of what's happening.
First, you'll notice
that your code is all gray.
These first lines of code.
Gray lines of code
are just comments,
which are useful when you're
coding with somebody.
When you're pair programming,
sometimes it's hard
to understand
simply by reading the code.
It's nice to have comments
associated with it
so that you can understand
what their intention was
when they were trying
to write their code.
With this LED, we're maybe using
ten lines of code.
It's 25 million lines of code
in a cell phone.
You can imagine
an individual
trying write that code
by themselves.
It would be
physically impossible.
It would take
2,700 years
if you were trying
to write code by yourself.
It requires teamwork,
so comments are important
when coding.
Moving on.
We'll go to our void setup.
So, our void setup
is setting up our board.
It will run through
this code once,
'cause it only needs
to set up once.
Inside our void setup,
it says "pinMode (13, OUTPUT)."
And it's cool.
Not many words in the coding
world are self-explanatory,
but this one is.
It says "pinMode,"
and there's two things
it's looking for.
The pin is what pin
you're addressing.
Is it a coincidence
that our red wire's in 13
and it says 13?
If you upload it after you've
changed that number,
would your circuit
still work?
So, this says "13."
Next, it says "output."
Again, "pinMode."
This is the pin over here,
and this is its mode,
which is an output.
We're outputting information.
We're not inputting information.
As I'm talking to you,
I'm outputting stuff.
If I stopped to listen,
I'm inputting information.
That's the difference there,
and we're only outputting now.
So, we're gonna leave that
as it is.
Going next,
we have our void loop.
This is where
the action happens.
Again, kind of self-explanatory.
It's a loop.
It will go
through these lines of code
over and over again,
like a loop.
Until you unplug it, it will
never stop reading that code.
It will execute
each line at a time.
I'll read each line of code
and act like I'm an Arduino,
or an LED.
The first line:
"digitalWrite (13, HIGH)."
which is high voltage,
meaning the LED turned on.
Next line of code:
"delay (1000),"
which means I can't do anything
for 1,000 milliseconds.
I can't read
the next line of code.
I shouldn't be
talking either.
I'll awkwardly stare at you
for a thousand milliseconds.
Next line of code:
"digitalWrite (13, LOW)."
That means low voltage,
LED could turn off.
Awesome. I can immediately
read the next line of code.
"Delay 1,000 milliseconds."
Again, can't do anything.
All right.
Next, go back up top.
Remember, this is a loop.
It will keep going
over and over again.
So, "digitalWrite 13, high."
High voltage, LED turned on.
"Delay 1,000."
Next line of code:
"digitalWrite 13, low."
Low voltage, LED off.
"Delay 1,000."
What would I need to do if I
wanted my LED to blink faster?
What changes in my code?
I think
it's changing the delay.
So let's experiment
with that.
If I were to decrease my delay
number to, let's say, 250,
I think my LED
is going to blink faster.
But let's test that theory out.
Remember, every time you make
a change, upload your code.
Otherwise, it's only living
on your computer,
and you want it
on your Arduino,
and it's on your Arduino
once it's successfully uploaded.
So, it just got done uploading,
and our LED is blinking faster.
Awesome. You should play around
with some different numbers.
See what happens.
You don't need the same number
on the delays.
Make it blink so fast
that you can't see it
blink anymore.
Try something fun.
Thanks for helping me
build an LED circuit
and using Arduino
to make it blink.
Hope you had fun.
Funding to purchase and make
this educational production
accessible was provided by the
U.S. Department of Education.
PH:1-800-USA-LEARN (V)
or WEB: www.ed.gov.
