You are on page 1of 61

Qrio Level 1

Session 4: Arduino
Software
Before Starting
With
ARDUINO
Electronic Cautions
 Two sources of power
 Connection at the first
 No resistors for LEDs
 Multiple grounds
 Close soldering iron
 Short circuit
Arduino Programing is one
of the International
Language Codes Most used
Worldwide!
Now!
Before anything, you need to download the
Arduino Program. So to do that,
you can go to:
http://www.arduino.cc/en/software
And you can install it easily!
After installing the program,
let’s try and open it.

Now let’s see what it looks like!


The Code and the
The Langauge of the
functions in the
Code we use is the
program is called a
‘C++ Language’
‘Sketch’
The functions we write, what exactly do
they mean?
A function is basically
like a little machine
created out of code.

You build it and call its


name when you need it.

Then it performs exactly


as was written in it.
What are the basics in Arduino Programming?
We have 2 main parts in the code:
1. Setup()
2. Loop()
The code can’t be
done without these
two functions:
Setup() Loop()

Function Function

It is mandatory It is mandatory

Runs only once when It loops from the start when


the sketch starts we reach its end

We use it to: It executes the code per


-initialize variables, pin modes order and forever unless
-start using libraries we stop the program
Brief Review
void setup(): It’s called when a sketch starts.
Use it to initialize variables, pin modes, start using
libraries, etc. it will only run once, after each powerup or
reset of the Arduino board.
____________________________

void loop(): It initializes and sets the initial values. It does


precisely what its name suggests, and loops consecutively,
allowing the program to change and respond.
____________________________
Fast Review
What is the definition of INPUT?
What about the OUTPUT?
Let’s know more about «setup()» function
Example:
Let’s try having a LED and
connect it to pin 13.
Is the LED an Input
or an Output?
GREAT! Pin Number All Letters
It’s an output so this is how it Only M is Capitalized
capitalized
should be defined in the code
with its pin number!
pinMode!
pinMode(pin, mode) is used to introduce the connected
components to the Arduino Uno.

pinMode(pin, mode)

The Arduino pin ‘INPUT’ or


number to be ‘OUTPUT’
specified
Let’s know more about «loop()» function

digitalWrite!
digitalWrite!

‘0’ or ‘1’
LOW or HIGH

OUTPUT
digitalWrite!
digitalWrite(pin, value) is a command written in ‘loop()’

‘pin’: stands for the pin whose mode you wish to set
‘value’: stands for High (‘1’) or Low(‘0’)
For a LED, High means
to turn it On while Low
means to turn it Off.
Only W is Pin Number All Letters
capitalized Capitalized

NEVER
FORGET that after
each command we
should have a semi
colon!! « ; »
Another function we use in «loop()» ?

digitalRead!
digitalRead!

‘0’ or ‘1’
LOW or HIGH

INPUT
digitalRead!
‘digitalRead(pin)’ is a command written in ‘loop()’.
It reads the value from a specified digital pin,
either HIGH or LOW.

‘pin’: the Arduino pin number you want to read.


digitalWrite digitalRead

Digital

Output Input
Now, Let’s try the example ‘Blink’!

First, you need to open the program

ARDUINO IDE
Then on top of the
Program,
tap on ‘File’.
In the examples,
you can find the
code
of example
‘Blink’.
Verify

The code of
‘Blink’ will open
up
After the ‘Verify’, there might be
an error in the code or no error
Now let’s connect the
Arduino Uno
to the Laptop!
To make sure that the
Arduino Uno is
connected to the
laptop, on the top of
the program, press on
‘Tools’ and check the
‘Board’ and ‘Port’ as
shown.
Now, after
making
sure that
everything
is well done,
press on
‘Upload’
Check the Result
on your
Arduino Uno!
LED

EVERYTHING
IS
FINE
Example: let’s try to make a LED turn ON
First, the LED has a polarity!
The longer leg is to be
connected to the pin(+) _ +
While the shorter leg needs
to be connected to the
ground(-)
Otherwise, it won’t turn On!
CODING
SAVE YOUR CODE
How to save your work?
1-First, go to your
desktop.
Press right click
then create a ‘new
folder’.
2- Name it ‘Arduino Examples’

New Folder name:


‘‘Class Name + Group Name’’
3- Then, in the Arduino
Program, press on
File  Save as
4- Press on Desktop then on Arduino Examples.
Press open.
Then change the ‘File
name’ according to the
code you’re writing in
the sketch.
Example: ‘LED on’
5- Now tap
‘Save’.
And it’s done!
VERIFYING
CONNECTING
THE CIRCUIT
CONNECTING
THE ARDUINO
TESTING
Example
Make a blinking LED
connected to pin number 13
with ON and OFF time = 1s
The LED turns ON for 1s
then OFF for 1s.
Blinking time is 1s=1000ms.
LED On Delay 1s

Delay 1s LED Off


How Do We Determine
Time In Coding!!?
delay!
It pauses the program for the amount of time (in
milliseconds) specified as parameter.
Syntax: ‘delay(time in ms);’

So for blinking LED,


the delay command is
Code of Blinking LED
The Result
Do you know that we can use variables too?

variable!
Name Type

Value
For example, this statement creates a variable
int pin = 13;
Everything written after ‘//’
are comments. Comments are
Type lines in the program that are
(int = integer) Name Value used to inform yourself or
others about the way the
program works. They are
ignored by the compiler
We write the declaration of
variable before the
setup()!
Connectthe LED
to pin 13 to see the result!
Evaluation Time!

1- What’s void setup() for?


2- What’s void loop() for?
3- What’s digitalWrite? digitalRead?
Discover the Mistakes No Resistor

Pin
number 8
SEE YOU NEXT WEEK

You might also like