SlideShare a Scribd company logo
Arduino Programming
(C) 2014 James Lewis
james@baldengineer.com
1
Arduino Langauge
2
Machine Language
(Binary Code)
Assembly
(Readable Code)
C / C++
(Readable Code)
C++
Libs
C++
Libs
C++
Libs
“Arduino”
Arduino Langauge
3
Machine Language
(Binary Code)
Assembly
(Readable Code)
C / C++
(Readable Code)
C++
Libs
C++
Libs
C++
Libs
“Arduino”
Hello World (Blink)
4
Hello World (Blink)
5
Variable
Hello World (Blink)
6
Comments
Hello World (Blink)
7
Comments
Good Comment:
// Blue LED for Activity Indicator
Bad Comment:
// Pin 13
Hello World (Blink)
8
Functions
Hello World (Blink)
9
Functions
Hello World (Blink)
10
Instruction
Hello World (Blink)
11
Instruction
Hello World (Blink)
12
FunctionCall
Hello World (Blink)
13
Arguments
Hello World (Blink)
14
IDE Tools Menu
15
IDE Tools Menu
16
IDE Tools Menu
17
IDE Tools Menu
18
Arduino IDE
19
Type Stuff Here
Compiler Output
Arduino IDE
20
Type Stuff Here
Compiler Output
Serial Monitor
Arduino IDE
21
Type Stuff Here
Compiler Output
Serial MonitorVerify & Upload
Arduino IDE
22
Type Stuff Here
Compiler Output
Serial MonitorVerify & Upload
Board & Serial Port
Blink Exercise
• Load the Blink Example and
program it to your board

• Change the values of delay()
to see how it affects the
behavior
23
Check the correct board and serial port are selected in the tools menu!
Hello World
Serial Example
24
Serial objects
25
Serial objects
26
Enables Serial
Baud
Rate
Serial objects
27
Variables
Strings
Control Characters
Print
and Println
Serial objects
28
Variables
Strings
Control Characters
Print
and Println
NOTE: Strings and Variables Can’t be used on the same line
Hello World (Serial)
• Load up the serial code to the
right

• Exercise:
• Change the 2000 in delay
into a variable.
• Print value of variable on
same line as “Hello World”
29
Variables
30
How Much Memory is
in your Arduino?
31
Variable Types
32
Bits Unsigned Range Signed Range
byte 8 0 to 255 N/A
char 8
0 to 255
‘A’..’b’..’X’
N/A
int 16 0 to 65535 -32,767 to 32,766
long 32 0 to 4,294,967,295
-2,147,483,648 to
2,147,483,647
float 32 ±3.4028235E+38 n/a
double 32 n/a n/a
Variable Do and Don’t
• DO Use Descriptive Names
• “BlueLED”, “ActivityIndicator”
• DON’T Use Bad Names
• “Integer”, “Pin13”
• DO Stick to a naming convention
• Variables are Case Sensitive!
• DON’T use same name for Local and Global Variables
33
Variable Scope
34
Variable Scope
35
Global
Variable Scope
36
Global
Local to loop()
Variable Don’t!
37
Variable Don’t!
38
Variable Don’t!
39
analogReadings[]
arrays
40
0 1 2 3 4 5
analogReadings[]
arrays
41
0 1 2 3 4 5
Size
Elements
analogReadings[]
arrays
42
0 1 2 3 4 5
Size
Elements
arrays are 

0-index based. 

So last element

is always 

“1 less”

than the size!
Pin Functions
43
pinMode()
44
Analog
(A0..A5)
Digital
(0..13)
INPUT
Digital Input,
Pull-Up Off
Digital Input,
Pull-Up Off
INPUT_PULLUP
Digital Input,
Pull-Up On
Digital Input,
Pull-Up On
OUTPUT Digital Output Digital Output
Analog Pins can be used as Digital Pins
pinMode(INPUT, Ax) isn’t necessary for analogRead()
digitalRead() & digitalWrite()
45
Pull-Up Resistor
46
INPUTs almost always need a Pull-Up or Pull-Down
pinMode(INPUT_PULLUP) Turns on the Internal Pull-Up Resistor
http://www.baldengineer.com/tutorials/arduino-pull-ups/
I/O Exercise
• Objective: Understand Inputs
and Outputs

• Exercise: “Fix” the random
LED
47
analogRead()
48
Analog
Signal
Convert
Digital
Value
10-bits, stored as 8-bits
Values 0 to 1023
Voltage
0v to 5v
5 volts
1023 Steps
= 4.887mV per Step
Calling analogRead() on an Analog Pin,
automatically converts to Input
analogWrite()
49
analogWrite() isn’t Analog (Except on the Due)
Uno Pins: 3, 5, 6, 9, 10, 11
Actual AnalogPulse Width Modulation (PWM)
Analog Exercise
• Connect Pin 6 to Analog 0

Run this code

• Then, disconnect from Pin 6 

While Running the Code
50
Remember to open the Serial Monitor!
Analog Exercise
• Connect Pin 6 to Analog 0

Run this code

• Then, disconnect from Pin 6 

While Running the Code
51
Remember to open the Serial Monitor! A0, A1, A2..A5 are integers!
functions()
52
Functions
Getting Data Back
Functions
Getting Data Back
Tip: The Arduino IDE, doesn’t require “prototyping”
Functions
Getting Data Back
Return Type
Arguments
“Return”
FunctionName
Functions
Returning Nothing
56
Return Type
If the function doesn’t return anything, declare it as void
Function Exercise
• “Re-Write” the built-in Blink
Example to use a Function
• Exercise: add a “argument” to
adjust the delay time
57
Control Structures
58
if-statements
59
if-statements
60
if-statements
61
if-statements
62
control operators
63
== Equal to
>

>=
Greater than
(or equal)
<
<=
Less Than
(or equal)
!= Not Equal to
|| OR
&& AND
| Bitwise OR
& Bitwise AND
#1 if-statement mistake
64
#1 if-statement mistake
65
= != ==
for() loop example
66
for() loop
67
for() loop
68
Control Variable
for() loop
69
Control Variable
Condition
for() loop
70
Control Variable
Condition
Increment
Array and For Exercise
• Use an Array and two for-
loops to read analog inputs,
then display then

• Notice the difference in
brackets between the two
loops
71
while() loop
72
while() loop
73
Condition
while() loop
74
Condition
Loop conditions are same as “if conditions”
while() and Serial
• This program echoes
whatever is on the serial buffer
back out
75
76
More information?

Visit

baldengineer.com

More Related Content

What's hot (20)

PPTX
Wi-Fi Esp8266 nodemcu
creatjet3d labs
 
PPT
Arduino
vipin7vj
 
PPTX
Arduino
Jerin John
 
PPT
Intro to Arduino
avikdhupar
 
PPTX
PPT ON Arduino
Ravi Phadtare
 
PPTX
Ardui no
Amol Sakhalkar
 
PPTX
Lesson sample introduction to arduino
Betsy Eng
 
PPTX
Basics of arduino uno
Rahat Sood
 
PPTX
Introduction to Node MCU
Amarjeetsingh Thakur
 
PDF
Introduction to Microcontroller
Pantech ProLabs India Pvt Ltd
 
PPTX
microcontroller vs microprocessor
sobhadevi
 
ODP
Introduction to Arduino
Richard Rixham
 
PPTX
Introduction to Arduino
Omer Kilic
 
PDF
Introduction to arduino
Jawaher Abdulwahab Fadhil
 
PPTX
Introduction to arduino ppt main
eddy royappa
 
PPTX
Microcontroller presentation
xavierpaulino
 
PPS
What is Arduino ?
Niket Chandrawanshi
 
PPT
Embedded System Presentation
Prof. Erwin Globio
 
PPT
basic-analog-electronics
ATTO RATHORE
 
PDF
Arduino IDE
Mrunal Deshkar
 
Wi-Fi Esp8266 nodemcu
creatjet3d labs
 
Arduino
vipin7vj
 
Arduino
Jerin John
 
Intro to Arduino
avikdhupar
 
PPT ON Arduino
Ravi Phadtare
 
Ardui no
Amol Sakhalkar
 
Lesson sample introduction to arduino
Betsy Eng
 
Basics of arduino uno
Rahat Sood
 
Introduction to Node MCU
Amarjeetsingh Thakur
 
Introduction to Microcontroller
Pantech ProLabs India Pvt Ltd
 
microcontroller vs microprocessor
sobhadevi
 
Introduction to Arduino
Richard Rixham
 
Introduction to Arduino
Omer Kilic
 
Introduction to arduino
Jawaher Abdulwahab Fadhil
 
Introduction to arduino ppt main
eddy royappa
 
Microcontroller presentation
xavierpaulino
 
What is Arduino ?
Niket Chandrawanshi
 
Embedded System Presentation
Prof. Erwin Globio
 
basic-analog-electronics
ATTO RATHORE
 
Arduino IDE
Mrunal Deshkar
 

Viewers also liked (7)

DOCX
Arduino Full Tutorial
Akshay Sharma
 
ODP
Intro to Hardware Programming with the Arduino Uno
Vui Nguyen
 
PDF
ITT 18 Practicas Basicas de Arduino
El Gfe Davidson
 
PDF
Curso Arduino práctico 2014
Jose Antonio Vacas
 
DOCX
Manual basico de practicas con Arduino uno
Ramiro Hernandez Michua
 
PDF
20 Magnificos proyectos para ARDUINO
dave
 
PDF
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
Tino Fernández
 
Arduino Full Tutorial
Akshay Sharma
 
Intro to Hardware Programming with the Arduino Uno
Vui Nguyen
 
ITT 18 Practicas Basicas de Arduino
El Gfe Davidson
 
Curso Arduino práctico 2014
Jose Antonio Vacas
 
Manual basico de practicas con Arduino uno
Ramiro Hernandez Michua
 
20 Magnificos proyectos para ARDUINO
dave
 
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
Tino Fernández
 
Ad

Similar to Introduction to Arduino Programming (20)

DOCX
Lab Manual Arduino UNO Microcontrollar.docx
RashidFaridChishti
 
PPTX
Introduction to Arduino with ArduBlock & SparkFun LilyPad
Brian Huang
 
PPTX
Arduino Workshop
atuline
 
PDF
NSTA 2013 Denver - ArduBlock and Arduino
Brian Huang
 
PDF
SPARKNaCl: A verified, fast cryptographic library
AdaCore
 
PPTX
Arduino board program for Mobile robotss
VSARAVANAKUMARHICETS
 
PDF
Intro to Arduino Revision #2
Qtechknow
 
PPTX
Arduino Workshop (3).pptx
HebaEng
 
PDF
Ardx experimenters-guide-web
Jhonny Wladimir Peñaloza Cabello
 
PDF
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
PPTX
Arduino course
Ahmed Shelbaya
 
PDF
Ardx eg-spar-web-rev10
stemplar
 
PPTX
Arduino Slides With Neopixels
sdcharle
 
PPTX
Introduction to the Arduino
Wingston
 
PDF
Arduino Programming for Basic Robotics - University of Moratuwa
Abarajithan Gnaneswaran
 
PDF
Arduino: Arduino starter kit
SANTIAGO PABLO ALBERTO
 
PDF
Arduino experimenters guide hq
Andreis Santos
 
PDF
Lily pad dev_handout
Khuê Phạm
 
KEY
Intro to Arduino
Qtechknow
 
PPTX
Introduction to Arduino Microcontroller
Mujahid Hussain
 
Lab Manual Arduino UNO Microcontrollar.docx
RashidFaridChishti
 
Introduction to Arduino with ArduBlock & SparkFun LilyPad
Brian Huang
 
Arduino Workshop
atuline
 
NSTA 2013 Denver - ArduBlock and Arduino
Brian Huang
 
SPARKNaCl: A verified, fast cryptographic library
AdaCore
 
Arduino board program for Mobile robotss
VSARAVANAKUMARHICETS
 
Intro to Arduino Revision #2
Qtechknow
 
Arduino Workshop (3).pptx
HebaEng
 
Ardx experimenters-guide-web
Jhonny Wladimir Peñaloza Cabello
 
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
Arduino course
Ahmed Shelbaya
 
Ardx eg-spar-web-rev10
stemplar
 
Arduino Slides With Neopixels
sdcharle
 
Introduction to the Arduino
Wingston
 
Arduino Programming for Basic Robotics - University of Moratuwa
Abarajithan Gnaneswaran
 
Arduino: Arduino starter kit
SANTIAGO PABLO ALBERTO
 
Arduino experimenters guide hq
Andreis Santos
 
Lily pad dev_handout
Khuê Phạm
 
Intro to Arduino
Qtechknow
 
Introduction to Arduino Microcontroller
Mujahid Hussain
 
Ad

Recently uploaded (20)

PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PDF
Digital water marking system project report
Kamal Acharya
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PDF
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PDF
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PPTX
UNIT 1 - INTRODUCTION TO AI and AI tools and basic concept
gokuld13012005
 
PPT
Testing and final inspection of a solar PV system
MuhammadSanni2
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
Final Major project a b c d e f g h i j k l m
bharathpsnab
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
Digital water marking system project report
Kamal Acharya
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
UNIT 1 - INTRODUCTION TO AI and AI tools and basic concept
gokuld13012005
 
Testing and final inspection of a solar PV system
MuhammadSanni2
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
Final Major project a b c d e f g h i j k l m
bharathpsnab
 

Introduction to Arduino Programming