Hi, I'm Becky Stern,
And today we're going to introduce you to Arduino.
Arduino is a platform that makes it easy to tinker with technology.
This family of microcontroller boards lets
you sense the world around you and control electrical devices.
The word Arduino refers to several layers of the circuit prototyping process:
the hardware, both the official Arduino boards
and the thousands of derivative Arduino compatibles.
The software used to communicate with the hardware is called
an Integrated Development Environment:
The Arduino IDE
The programing language you use is also called
Arduino, and it's based on C++.
And Arduino also refers to the trademark of the Arduino Corporation
that manufactures official boards and maintains
the open source documentation that helps make the ecosystem free and easy to share.
Arduino is a huge global community, which means you can find nearly infinite
amount of inspirational projects, sample code and answers to your questions online.
If you follow along with this series,
you'll do experiments to build up your skills and familiarity with the key
concepts of controlling components with electricity,
as well as coding in the Arduino language.
you can find my recommendations for the parts you'll want to get started
in the description as well as links to circuit simulators you can use
to practice building with Arduino without having to buy anything at all.
The board I recommend starting with is the Arduino Uno;
or compatibles such as the Adafruit Metro,
SparkFun RedBoard or Seeeduino,
make sure you've got the correct USB cable to connect your board to your computer.
It needs to have the right connectors and be a data-capable cable
which can look the same as a charge-only type.
These beginner focused boards have large labels to help
you see what you're plugging in to the header pins along the edges,
which connects to various pins on the microcontroller chip itself,
which is a tiny computer running a program
that we upload to it from the regular computer.
On the board, you'll also find a reset button.
Power indicator led, some LEDs to indicate when the board is sending
and receiving data, and an LED wired to pin 13
for testing without having to plug anything into the board.
The other components support the microcontroller
and make it easy to wire up
and program circuits without a degree in electrical engineering.
You'll also need a solderless breadboard.
This device has metal strips inside and many holes
that allow you to connect components quickly and easily.
I like to connect the breadboard and the Arduino board
with a mounting plate so that my circuits stay together better.
You'll
use some wires to connect to the Arduino.
Either some purpose built breadboard wires or solid core hook of wire works fine too.
Before we get into the software, we can build a simple circuit
with the program that comes on the board from the factory,
which just blinks and led connected to PIN 13.
See a PIN 13 connects to the longer positive leg of the LED
and the negative leg is connected to ground through this resistor,
which helps limit the current to prevent the led from burning out.
We covered LCD basics in a previous episode
if you want to learn more, but for this circuit, a quarter watt
resistor or any value from 100 ohms to 1000 ohms will work great.
I've got five volts and ground from the labeled pins on the Arduino
over here to the bus bars on the solder less breadboard.
These bus bars run the length of the breadboard on either side
so you can easily access power and ground.
for our circuit, it's not strictly necessary to use the ground bus as an intermediary connection
to the board's ground, but it's best practice
to connect your bus bars whenever you're prototyping.
Okay, so once you've built the circuit, which you should always do with the power
disconnected, you can go ahead and plug your board into the computer.
Your new LED
should blink in time with the tiny surface mount led on the board.
If it doesn't double check that your wires are all connected
and that your LED isn't backwards,
the connections are pretty small, so it's super
easy to plug a wire into the wrong row.
Once your LED is blinking, it's time to dig into the program controlling it.
The basic blink example is included in the downloadable
Arduino software, which you'll need to install on your computer.
Open it up and look under
File > Examples > 01 Basics > Blink
All the extra symbols are part of Arduino's syntax, but don't get intimidated.
It takes time to learn and write proper code from scratch.
I'll break it down for you here
and you can always use the examples for reference as you level up.
This first section is a block comment followed by the codes setup,
which is used to set up things your program will need later.
It runs once when the program starts up.
Our Blink sketch setup configures PIN 13 as an output
which prepares the board to send signals to it rather than listen.
The main body of the program is inside the loop.
This part of the code will
execute on repeat so long as the board has power.
The gray text following double slashes are also comments
to make the program easier to understand.
The output command we're going to use is called digitalWrite(),
which is a function that sets a pin HIGH or LOW on or off.
To pause the program, we're using delay(),
which pauses for a number of milliseconds.
One second is 1000 milliseconds.
So to summarize, the program turns and led on and off at one second intervals.
Let's try switching up that interval.
To customize this code, you can just change the delay values
something like 500 milliseconds and like 2000 milliseconds
and then upload the program to the board, make sure the USB cable is plugged in
and you select the board and the port from the tools menu.
If none of your ports are labeled,
try unplugging your board, checking the ports menu then re plugging
your board and checking the ports menu again to see what's changed.
Now click the upload button to transfer the Blink
example code to the Arduino board.
The LED's labeled Tx and Rx will flash to show
that the software is talking to the board and then you'll get a message
that says “Done uploading”.
And moments later our custom blink appears.
If you're uploading to an Arduino compatible, you may need to install
an additional driver before you're able to see the board in your port menu.
Refer to your product documentation to see what's required.
Now that you've got a digital example working, it's time
to talk more about things Arduino can do.
Sure, blinking is great, but it can also tell the LED
to be somewhere in between full on and full off.
We can program fading effects.
But only a few pins on the Arduino are capable of this analog-ish output,
and these pins are labeled on your board with a little squiggle or a mark.
I'm going to unplug there now before making any changes
then unplug the wire connected to pin 13
and plug it into pin nine, which is marked as a PWM pin.
Open up the example in your Arduino software under
File > Examples > 01 Basics > Fade
plug in and upload the sketch to your Arduino board
and observe your LED fade on and off.
The Arduino board is only capable of generating digital signals
HIGH and LOW, but analogWrite() simulates the appearance of brightnesses
between on and off using Pulse Width Modulation, or PWM. The LED flashes on
and off very quickly and your eye interprets a dimmer light.
The ratio of time the LED spends on versus off
determines how bright or dim the LED appears.
Let's look at the code to learn how this fading is achieved,
I've turned on line numbers in the Arduino preferences
in order to be able to better reference the different parts of the code.
Lines 16 through 18 declare three variables used in the program.
The setup configures pin nine 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 fadeAmount, which is 5.
Line 35 uses an if statement to check
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 the brightness
until it reaches or exceeds 255.
Then sets fade amount to -5 and decrements brightness
until it reaches zero or below zero.
The delay() at the end prevents the code from running so fast
that you can't see the effect, and the fast flashing of PWM
is why you can sometimes see LED lighting flicker when you record it
on your camera or phone, depending on your shutter speed.
PWM is also used to allow for color mixing in an
RGB LED: one LED of each color is set to different brightnesses
and when they mix together in a single package can form any color of light.
The last concept I'd like to introduce in this intro to Arduino basics
is a for() loop, also called a counting loop,
which counts from an initial value to an upper limit.
In this program, we're counting from 0 to 255 in increments of five,
just like our LED fading program from earlier, which shows
there's more than one way to write the same program.
You can also wire up a few more LEDs and use a for() loop to animate them.
After the for() loop completes its count, the rest of the main loop executes,
then starts over again.
I know this can all seem pretty overwhelming at first,
but don't forget that you can always look stuff up online when you get stuck.
The Arduino site has an excellent reference section
where you can find explanations and examples of every part of the code
and a community forum where you can get help with your own projects.
I've put links to some resources in the description.
Digi-Key’s got more videos on Arduino to watch while you wait for the next time
when we'll cover inputs and sensors.
If you've got more insight for Arduino beginners,
please leave a comment and we can all learn together.
Check out the playlist with the rest of this series and subscribe
to be sure you don't miss the next one.