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

PPTX
Basics of arduino uno
PPTX
Arduino Microcontroller
PPTX
Introduction to Arduino
PPTX
Introduction to Arduino
PPTX
Introduction to the Arduino
PPTX
Arduino
PPTX
Arduino Workshop
PPTX
Introduction to Arduino Microcontroller
Basics of arduino uno
Arduino Microcontroller
Introduction to Arduino
Introduction to Arduino
Introduction to the Arduino
Arduino
Arduino Workshop
Introduction to Arduino Microcontroller

What's hot (20)

PPTX
Lesson sample introduction to arduino
PPTX
Ardui no
PPT
Arduino presentation by_warishusain
PDF
Arduino Workshop Day 1 - Basic Arduino
PPTX
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
PDF
Report on arduino
PPTX
Arduino course
PDF
Arduino Workshop Day 2 - Advance Arduino & DIY
PPT
Arduino
PPTX
Introduction to arduino
PPT
Intro to Arduino
PPTX
Seven Segment Display
PPTX
Introduction to Arduino Hardware and Programming
PPTX
Raspberry pi
PDF
Arduino Lecture 1 - Introducing the Arduino
PPS
Arduino Uno Pin Description
PPTX
Switch mode power supply
PDF
Arduino uno
PPT
Shift Registers
PPTX
Introduction to arduino ppt main
Lesson sample introduction to arduino
Ardui no
Arduino presentation by_warishusain
Arduino Workshop Day 1 - Basic Arduino
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Report on arduino
Arduino course
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino
Introduction to arduino
Intro to Arduino
Seven Segment Display
Introduction to Arduino Hardware and Programming
Raspberry pi
Arduino Lecture 1 - Introducing the Arduino
Arduino Uno Pin Description
Switch mode power supply
Arduino uno
Shift Registers
Introduction to arduino ppt main
Ad

Viewers also liked (8)

DOCX
Arduino Full Tutorial
ODP
Intro to Hardware Programming with the Arduino Uno
ODP
Introduction to Arduino
PDF
ITT 18 Practicas Basicas de Arduino
PDF
Curso Arduino práctico 2014
DOCX
Manual basico de practicas con Arduino uno
PDF
20 Magnificos proyectos para ARDUINO
PDF
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
Arduino Full Tutorial
Intro to Hardware Programming with the Arduino Uno
Introduction to Arduino
ITT 18 Practicas Basicas de Arduino
Curso Arduino práctico 2014
Manual basico de practicas con Arduino uno
20 Magnificos proyectos para ARDUINO
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
Ad

Similar to Introduction to Arduino Programming (20)

PPT
Arduino_CSE ece ppt for working and principal of arduino.ppt
PPTX
Arduino Programming Familiarization
PDF
The IoT Academy IoT Training Arduino Part 3 programming
PPT
Arduino-2 (1).ppt
PPT
Arduino-arduino arduino programming hhhh
PPT
Arduin0.ppt
PPTX
Introduction To Arduino-converted for s.pptx
PPTX
Introduction to Arduino with ArduBlock & SparkFun LilyPad
PDF
Arduino reference
PPTX
Introduction to Arduino
PDF
arduinocourse-180308074529 (1).pdf
PPT
Fundamentals of programming Arduino-Wk2.ppt
PPT
Arduino wk2
PPT
13223971.ppt
PDF
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
PPT
Arduino is an open-source electronics platform that has an easy-to-use physic...
PPT
arduino Simon power point presentation.ppt
PPTX
PPTX
Arduino board program for Mobile robotss
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino Programming Familiarization
The IoT Academy IoT Training Arduino Part 3 programming
Arduino-2 (1).ppt
Arduino-arduino arduino programming hhhh
Arduin0.ppt
Introduction To Arduino-converted for s.pptx
Introduction to Arduino with ArduBlock & SparkFun LilyPad
Arduino reference
Introduction to Arduino
arduinocourse-180308074529 (1).pdf
Fundamentals of programming Arduino-Wk2.ppt
Arduino wk2
13223971.ppt
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
Arduino is an open-source electronics platform that has an easy-to-use physic...
arduino Simon power point presentation.ppt
Arduino board program for Mobile robotss

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
ETO & MEO Certificate of Competency Questions and Answers
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
web development for engineering and engineering
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
AgentX UiPath Community Webinar series - Delhi
PPT
Project quality management in manufacturing
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
Embodied AI: Ushering in the Next Era of Intelligent Systems
“Next-Gen AI: Trends Reshaping Our World”
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
ETO & MEO Certificate of Competency Questions and Answers
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
web development for engineering and engineering
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
AgentX UiPath Community Webinar series - Delhi
Project quality management in manufacturing
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
Road Safety tips for School Kids by a k maurya.pptx
Lesson 3_Tessellation.pptx finite Mathematics
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Strings in CPP - Strings in C++ are sequences of characters used to store and...
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...

Introduction to Arduino Programming