SlideShare ist ein Scribd-Unternehmen logo
1 von 76
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to arduino ppt main
Introduction to  arduino ppt mainIntroduction to  arduino ppt main
Introduction to arduino ppt main
eddy royappa
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
Ahmed Sakr
 

Was ist angesagt? (20)

Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
PPT ON Arduino
PPT ON Arduino PPT ON Arduino
PPT ON Arduino
 
Introduction to arduino ppt main
Introduction to  arduino ppt mainIntroduction to  arduino ppt main
Introduction to arduino ppt main
 
Arduino presentation by_warishusain
Arduino presentation by_warishusainArduino presentation by_warishusain
Arduino presentation by_warishusain
 
Wi-Fi Esp8266 nodemcu
Wi-Fi Esp8266 nodemcu Wi-Fi Esp8266 nodemcu
Wi-Fi Esp8266 nodemcu
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
 
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino Microcontroller
 
Introduction to Arduino and Hands on to Iot
Introduction to Arduino and Hands on to IotIntroduction to Arduino and Hands on to Iot
Introduction to Arduino and Hands on to Iot
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Esp8266 basics
Esp8266 basicsEsp8266 basics
Esp8266 basics
 
Arduino
ArduinoArduino
Arduino
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
Arduino Interfacing with different sensors and motor
Arduino Interfacing with different sensors and motorArduino Interfacing with different sensors and motor
Arduino Interfacing with different sensors and motor
 
Arduino Uno Pin Description
Arduino Uno Pin DescriptionArduino Uno Pin Description
Arduino Uno Pin Description
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
Arduino uno
Arduino unoArduino uno
Arduino uno
 
Arduino and robotics
Arduino and roboticsArduino and robotics
Arduino and robotics
 
Intro to Hardware Programming with the Arduino Uno
Intro to Hardware Programming with the Arduino UnoIntro to Hardware Programming with the Arduino Uno
Intro to Hardware Programming with the Arduino Uno
 
Basics of arduino uno
Basics of arduino unoBasics of arduino uno
Basics of arduino uno
 
Arduino presentation
Arduino presentationArduino presentation
Arduino presentation
 

Andere mochten auch

Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
Akshay Sharma
 

Andere mochten auch (8)

Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino
ArduinoArduino
Arduino
 
ITT 18 Practicas Basicas de Arduino
ITT 18 Practicas Basicas de Arduino ITT 18 Practicas Basicas de Arduino
ITT 18 Practicas Basicas de Arduino
 
Curso Arduino práctico 2014
Curso Arduino práctico  2014Curso Arduino práctico  2014
Curso Arduino práctico 2014
 
Manual basico de practicas con Arduino uno
Manual basico de practicas con Arduino unoManual basico de practicas con Arduino uno
Manual basico de practicas con Arduino uno
 
20 Magnificos proyectos para ARDUINO
20 Magnificos proyectos para ARDUINO20 Magnificos proyectos para ARDUINO
20 Magnificos proyectos para ARDUINO
 
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
Libro de proyectos del kit oficial de Arduino en castellano completo - Arduin...
 

Ähnlich wie Introduction to Arduino Programming

Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
HebaEng
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
Wingston
 

Ähnlich wie Introduction to Arduino Programming (20)

Introduction to Arduino with ArduBlock & SparkFun LilyPad
Introduction to Arduino with ArduBlock & SparkFun LilyPadIntroduction to Arduino with ArduBlock & SparkFun LilyPad
Introduction to Arduino with ArduBlock & SparkFun LilyPad
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and Arduino
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
 
Intro to Arduino Revision #2
Intro to Arduino Revision #2Intro to Arduino Revision #2
Intro to Arduino Revision #2
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
Ardx experimenters-guide-web
Ardx experimenters-guide-webArdx experimenters-guide-web
Ardx experimenters-guide-web
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
 
Arduino course
Arduino courseArduino course
Arduino course
 
Ardx eg-spar-web-rev10
Ardx eg-spar-web-rev10Ardx eg-spar-web-rev10
Ardx eg-spar-web-rev10
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
Arduino Programming for Basic Robotics - University of Moratuwa
Arduino Programming for Basic Robotics - University of MoratuwaArduino Programming for Basic Robotics - University of Moratuwa
Arduino Programming for Basic Robotics - University of Moratuwa
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
 
Arduino experimenters guide hq
Arduino experimenters guide hqArduino experimenters guide hq
Arduino experimenters guide hq
 
Lily pad dev_handout
Lily pad dev_handoutLily pad dev_handout
Lily pad dev_handout
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Arduino experimenters guide ARDX
Arduino experimenters guide ARDXArduino experimenters guide ARDX
Arduino experimenters guide ARDX
 
Arduino-2 (1).ppt
Arduino-2 (1).pptArduino-2 (1).ppt
Arduino-2 (1).ppt
 
Arduin0.ppt
Arduin0.pptArduin0.ppt
Arduin0.ppt
 

Kürzlich hochgeladen

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Introduction to Arduino Programming