Arduino 01
The Basics
How to Use These Presentations
These presentations are meant to introduce people to
the Arduino system. They include theory, layman
descriptions, and activities. Please do the activities, read
the descriptions and attempt to read the theory (usually
embedded as links)
If something doesn’t make sense, read the
next slide. Common questions and
problems are usually placed on the
following slide.
What is Arduino?
Arduino can refer to three things.
- The Arduino Microcontroller (the board)
- The Arduino Programming language
- The Arduino software used to program the
Arduino board.
What is Arduino?
It is also a pub. A
place where the
developers of the
board, some
university students
and their professor, frequently met to discuss
the project.
Why is it Special?
The Arduino website is Arduino.cc
The cc stands for Creative Commons which is what
Wikipedia functions under.
Anyone can use the plans and
software to create or program an
Arduino for free (unless you sell a
new Arduino board in which case
you pay a royalty)
The Arduino Microcontroller
A microcontroller is a programmable chip that
can be programmed to do specific logical
operations such as reading and writing to
sensors and other parts.
It can also be programmed to do
logical operations such as IF
statements, WHILE statements, and
functions.
Why Not Use a Computer for That?
Good question. The Arduino can often be
purchased for as little as $10 Canadian(for just
the chip, not the board) making it perfect to put
into a small project or robot. (Full boards
usually cost $20-30
Canadian)
The Arduino Programming Language
The Arduino board is programmed using the
Arduino programming language and using the
Arduino Integrated Development Environment
(IDE) program.
This language is similar to C or C++ and Java
programmers will find it very simple to learn.
The Arduino IDE
On your Desktop or in your Start menu, you
should find an Arduino Icon.
Open the program and you will be
greeted with a nearly blank text box.
The Arduino IDE
The Arduino IDE’s job is to
interpret codes that you give
it in language you can
understand, and to speak to
the Arduino chip in a
language that it can
understand.
The Arduino IDE
All Arduino Programs have two parts void setup()
and void loop().
Ignore the void part for now and focus on the setup
and loop.
setup will run everything inside that part of the
program(between the { } brackets) once.
loop will run its program over and over again
forever.
Your First Program...Blinking Lights
Your first program will be messing with a blinking light
program.
Select: File -> Examples ->
01. Basics -> Blink
Plug in your Arduino and select:
Tools -> Port -> COM Port x
Select the highest number COM
port
Blink Continued
Your Arduino board has a built in LED on pin 13
so we don’t need to breadboard anything.
Press the upload key to test the first program.
Now, read the program and
then try and make the LED blink on and
off for 2 seconds instead of 1.
Press the upload key to test.
Common Errors
One of the most common errors is a “sync error”
This simply means that the wrong COM port is
selected or your drivers need updating.
The Arduino is not hearing your computer.
Challenge Complete?
Did you succeed? How many times did you try
extending the blink?
If you failed, try again.
Program Parts - pinMode
pinMode(13, OUTPUT);
This command declares if a pin will be an INPUT
or an OUTPUT.
Sensors should always be INPUTS and LEDs and
motors OUTPUTS.
All INPUTS and OUTPUTS must be declared if
you want a program to behave properly.
pinMode(pin, INPUT/OUTPUT) is always in setup.
A Note About Syntax
You may have received a syntax error when
uploading. In this case one of your
lines was probably missing the
semicolon (;).
Spelling and grammar such as this
do count in programming.
Spelling Counts?
Yes, spelling counts. So does capitalization.
You may have noticed that most commands
begin with a lower-case letter, variables will too.
This is important as upper-case will cause a
syntax error and prevent your program from
uploading.
Program Parts - digitalWrite
digitalWrite(13, HIGH);
Digital pins are binary, they can be either
on(HIGH) or off(LOW).
This command tells digital pin 13 to turn on
(HIGH)
digitalWrite(13, LOW); turns it off.
Program Parts - delay
delay(1000);
This command tells the Arduino to pause
between commands, in this case one
second(1000 milliseconds).
Modifying this to read delay(2000) would have
completed the challenge of creating a 2 second
pause.
Comments
Most people can’t write computer code and it is
important for beginners and experts alike to
comment on their code.
Comments are descriptive statements that tell
whoever is reading your code what it is
supposed to do.
//Comments show up in grey in the Arduino IDE
Comments
To add comments or to “comment out” code
place // in the code to comment out everything
to the right of the slashes.
Placing a /* begins a multiline comment. It only
ends when the */ symbol is applied.
Commented text has zero impact on your
program. The Arduino will ignore it. It is only for
you and whoever has to read your code.
Wrapping Up
At this point you should know:
- What an Arduino is.
- How to upload code.
- The basic structure of a program.
- Some basic commands.
- //How to comment your code.