Professional Documents
Culture Documents
Mechatronics
Mechatronics
m)
.co
Hands-on Certified Training on
Mechatronics
an
hm
with
Arduino
rre
Training by
Naveed ur Rehman
In assistance with
du
Muhammad Amin Qureshi
ee
Lecture #2
v
na
n(
PLEASE NOTE
ma
http://goo.gl/2xij0V
rR
FB Event Page:
http://goo.gl/z4eWkF
v
Na
1
5/23/2015
m)
.co
Arduino Boards
an
hm
rre
du
ee
You may choose from the variety of Arduino boards
available in market!
v
na
n(
Arduino Boards
ma
Processor: ATmega328
Operating voltage: 5V
eh
Input voltage: 7 – 12 V
CPU Speed: 16 MHz
rR
Analog in: 6
Analog out: 0
Digital I/O: 14
Arduino UNO R3 PWM: 6
du
ee
2
5/23/2015
m)
.co
Arduino Boards
an
Processor: ATmega2560
Operating voltage: 5 V
hm
Input voltage: 7 – 12 V
CPU Speed: 16 MHz
Analog in: 16
rre
Analog out: 0
Arduino Mega 2560 Digital I/O: 54
PWM: 15
du
v ee
Learn more: http://www.arduino.cc/en/Products.Compare
na
n(
Arduino Boards
ma
Processor: AT91SAM3X8E
Operating voltage: 3.3 V
eh
Input voltage: 7 – 12 V
CPU Speed: 84 MHz
rR
Analog in: 12
Analog out: 2
Arduino Due Digital I/O: 54
PWM: 12
du
ee
3
5/23/2015
m)
.co
Arduino Boards
an
Processor: ATmega168/328
Operating voltage: 5 V
hm
Input voltage: 7–9V
CPU Speed: 16 MHz
Analog in: 8
rre
Analog out: 0
Arduino Nano Digital I/O: 14
PWM: 6
du
v ee
Learn more: http://www.arduino.cc/en/Products.Compare
na
n(
Arduino Boards
ma
eh
rR
du
ee
Arduino Yun
Learn more: http://www.arduino.cc/en/Products.Compare
v
Na
4
5/23/2015
m)
.co
Arduino Uno R3
an
hm
rre
du
v ee
Learn more: http://www.arduino.cc/en/Main/ArduinoBoardUno
na
n(
Powering Arduino
ma
eh
rR
5
5/23/2015
m)
.co
Powering, Operating Voltage & LED
an
hm
rre
du
v ee
na
n(
Reference:
eh
Eyes (you can see) and Nose (you can smell) etc.
6
5/23/2015
m)
.co
Arduino: Input and Output (I/O)
an
• Input and output devices work on Signals.
• Signals are the electrical means to transfer information
hm
between sensors (input devices) to Arduino and
Arduino to mechanisms (output devices).
rre
du
v ee
na
n(
Signals
ma
High
eh
Max
du
ee
Min Intermediate
Analog Signals
v
Na
7
5/23/2015
m)
.co
Signals: I/O Devices
an
Input, Digital Output, Digital
hm
rre
Input, Analog
du Output, Analog
v ee
na
n(
Ardunio board.
rR
Arduino Uno!
ee
v
Na
8
5/23/2015
m)
.co
Arduino: Electrical Signals I/O
an
Digital I/O (#0 - #13)
hm
Analog Out ~ (#3,5,6,9,10,11)
rre
du
ee
Digital I/O (#A0 - #A5)
Analog In (#A0 - #A5)
v
na
n(
Digital:
Input: 14 + 06 = 20
rR
Output: 14 + 06 = 20
du
Analog:
Input: = 06
Output: = 06
ee
v
Na
9
5/23/2015
m)
.co
an
hm
rre
du
v ee
na
n(
Arduino Programming
ma
on…
Fix bugs :(
du
10
5/23/2015
m)
.co
Arduino Programming: IDE
an
1. Download the Arduino Software (or IDE):
http://www.arduino.cc/en/Main/Software
hm
2. Install it on your computer
rre
3. Click shortcut icon on Desktop to open IDE
du
v ee
na
n(
1. Open IDE.
2. Connect Arduino board with
Computer using USB cable
eh
You are
3. Click Tools menu (it may
take slightly longer).
rR
about
Selfie the number written
time…!
next to COM.
v
Na
11
5/23/2015
m)
.co
Arduino Programming: Default sketch
an
Global space to declare and define global variables
hm
This is configuration part. It runs on power-up or reset.
rre
du
Things to run repeatedly – almost endlessley!
v ee
na
n(
Arduino Programming
ma
2. Digital Reading
3. Analog Writing
du
4. Analog Reading
ee
Huh!
v
Na
12
5/23/2015
m)
.co
Arduino Programming: Writing & Reading
an
Writing is like sending signal
hm
(or information) to a
mechanism (or output
device)
rre
du
Reading is like receiving
signal (or information) from
a sensor (or input device)
v ee
na
n(
13
5/23/2015
m)
.co
Digital Write: Circuit
an
Step #0: Schematic of circuit
hm
rre
du
v ee
na
n(
For example:
int dpin = 3;
du
or
int dpin = A3;
ee
v
Na
14
5/23/2015
m)
.co
Digital Write: Sketch
an
Step #2: Configure in setup()
Here, we will configure the pin mode i.e. the
hm
device is INPUT or OUTPUT. Use this statement:
pinMode(pin# or pin variable, mode);
rre
pin#: could be like 0 to 13 for digital I/O and A0 to
A5 for analog-in.
du
pin variable: would be the exact name of variable
used in global space to define pin #.
ee
mode: could be either OUTPUT to write date or
INPUT to read data.
v
na
n(
pinMode(3, OUTPUT);
or
du
pinMode(A3, OUTPUT);
or
pinMode(dpin, OUTPUT);
ee
v
Na
15
5/23/2015
m)
.co
Digital Write: Sketch
an
Step #3: Play in loop()
In loop() you can actually send the data (or signal).
hm
As we are dealing with “Digital” signals, we can
write either HIGH (ON) or LOW (OFF).
rre
A statement used to write the digital data is:
digitalData(pin# or pin variable, state);
du
state: it should be either HIGH or LOW.
ee
v
na
n(
should write:
rR
digitalWrite(3, HIGH);
or
du
digitalWrite(A3, HIGH);
or
digitalWrite(dpin, HIGH);
ee
v
Na
16
5/23/2015
m)
.co
Digital Write: Sketch
an
int dpin = 3;
void setup() {
hm
// put your setup code here, to run once:
pinMode(dpin,OUTPUT);
rre
}
void loop() {
du
// put your main code here, to run repeatedly:
digitalWrite(dpin,HIGH);
ee
}
v
na
n(
17
5/23/2015
m)
.co
Arduino Programming: Delay
an
The delay statement gives a pause of given
milliseconds in loop().
hm
delay(milliseconds);
rre
For a delay of 1 second, write:
delay(1000);
du
v ee
na
n(
int dpin = 3;
void setup() { Any
// put your setup code here, to run once:
eh
pinMode(dpin,OUTPUT);
}
idea,
what
rR
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(dpin,HIGH); will
du
delay(1000);
digitalWrite(dpin,LOW); happen
delay(1000);
?
ee
}
v
Na
18
5/23/2015
m)
.co
Arduino Programming: Digital Write
an
Making an Arduino circuit:
LED switching On and Off
hm
rre
du
v ee
na
n(
16 May to 14 Jun, 15
eh
du
Thank You!
We’ll love to hear from you!!
ee
http://goo.gl/z4eWkF
v
Na
19