SlideShare ist ein Scribd-Unternehmen logo
1 von 43
ARDUINO PROGRAMMING
Working with the Arduino microcontroller
2
Project Idea:
Automated Mini City
2
3
Mini City
• Light sensitive street lights
• Timed Traffic Lights
• Automated Gates using proximity sensor
• Cars that drive the City streets
3
Arduino Programming
USB (Data & Power)
Alternate Power (9V)
Digital I/O (2 – 13) Serial Transfer (0 -1)
Analog Input (0 – 5)
5V / 9V / GND (x2)
Power Source
Jumper
Reset
Compile Upload to controller
Text Output (Serial Data)
Code Editor
Serial Monitor
Arduino
IDE
Window
Arduino Code Basics
• Commands and other information are sent to
LED’s, motors and from sensors through digital
and analog input & output pins
7
Setup - Adding an LED
Arduino Code Basics
Arduino programs run on two basic sections:
void setup() {
//setup motors, sensors etc
}
void loop() {
// get information from sensors
// send commands to motors
}
9
SETUP
• The setup section is used for assigning input
and outputs (Examples: motors, LED’s,
sensors etc) to ports on the Arduino
• It also specifies whether the device is
OUTPUT or INPUT
• To do this we use the command “pinMode”
9
SETUP
void setup() {
pinMode(9, OUTPUT);
}
http://www.arduino.cc/en/Reference/HomePage
port #
Input or Output
11
void loop() {
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
}
LOOP
Port # from setup
Turn the LED on
or off
Wait for 1 second
or 1000 milliseconds
12
TASK 1
• Using 3 LED’s (red, yellow and green) build a
traffic light that
– Illuminates the green LED for 5 seconds
– Illuminates the yellow LED for 2 seconds
– Illuminates the red LED for 5 seconds
– repeats the sequence
• Note that after each illumination period the
LED is turned off!
12
13
TASK 2
• Modify Task 1 to have an advanced green
(blinking green LED) for 3 seconds before
illuminating the green LED for 5 seconds
13
14
Variables
• A variable is like “bucket”
• It holds numbers or other values temporarily
14
value
15
int val = 5;
DECLARING A VARIABLE
Type
variable name
assignment
“becomes”
value
16
Task
• Replace all delay times with variables
• Replace LED pin numbers with variables
16
17
USING VARIABLES
int delayTime = 2000;
int greenLED = 9;
void setup() {
pinMode(greenLED, OUTPUT);
}
void loop() {
digitalWrite(greenLED, HIGH);
delay(delayTime);
digitalWrite(greenLED, LOW);
delay(delayTime);
}
Declare delayTime
Variable
Use delayTime
Variable
18
Using Variables
int delayTime = 2000;
int greenLED = 9;
void setup() {
pinMode(greenLED, OUTPUT);
}
void loop() {
digitalWrite(greenLED, HIGH);
delay(delayTime);
digitalWrite(greenLED, LOW);
delayTime = delayTime - 100;
delay(delayTime);
} subtract 100 from
delayTime to gradually
increase LED’s blinking
speed
Conditions
•To make decisions in Arduino
code we use an ‘if’ statement
•‘If’ statements are based on a
TRUE or FALSE question
20
VALUE COMPARISONS
GREATER THAN
a > b
LESS
a < b
EQUAL
a == b
GREATER THAN OR EQUAL
a >= b
LESS THAN OR EQUAL
a <= b
NOT EQUAL
a != b
IF Condition
asdfadsf
if(true)
{
“perform some action”
}
22
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if(counter < 10)
{
Serial.println(counter);
}
counter = counter + 1;
}
IF Example
23
TASK
• Create a program that resets the delayTime
to 2000 once it has reached 0
23
24
Input & Output
• Transferring data from the computer to an
Arduino is done using Serial Transmission
• To setup Serial communication we use the
following
24
void setup() {
Serial.begin(9600);
}
25
Writing to the Console
void setup() {
Serial.begin(9600);
Serial.println(“Hello World!”);
}
void loop() {}
26
Task
• Modify your traffic light code so that each time
a new LED is illuminated the console displays
the status of the stoplight
• Example
26
Advanced Green
Green
Yellow
Red
Advanced Green
...
IF - ELSE Condition
asdfadsf
if( “answer is true”)
{
“perform some action”
}
else
{
“perform some other action”
}
28
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if(counter < 10)
{
Serial.println(“less than 10”);
}
else
{
Serial.println(“greater than or equal to 10”);
Serial.end();
}
counter = counter + 1;
}
IF - ELSE Example
IF - ELSE IF Condition
asdfadsf
if( “answer is true”)
{
“perform some action”
}
else if( “answer is true”)
{
“perform some other action”
}
30
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if(counter < 10)
{
Serial.println(“less than 10”);
}
else if (counter == 10)
{
Serial.println(“equal to 10”);
}
else
{
Serial.println(“greater than 10”);
Serial.end();
}
counter = counter + 1;
}
IF - ELSE Example
31
BOOLEAN OPERATORS - AND
• If we want all of the conditions to be true we
need to use ‘AND’ logic (AND gate)
• We use the symbols &&
–Example
31
if ( val > 10 && val < 20)
32
BOOLEAN OPERATORS - OR
• If we want either of the conditions to be true
we need to use ‘OR’ logic (OR gate)
• We use the symbols ||
–Example
32
if ( val < 10 || val > 20)
33
TASK
• Create a program that illuminates the green
LED if the counter is less than 100,
illuminates the yellow LED if the counter is
between 101 and 200 and illuminates the
red LED if the counter is greater than 200
33
34
INPUT
• We can also use our Serial connection to get
input from the computer to be used by the
Arduino
int val = 0;void setup() {
Serial.begin(9600); }void loop() {
if(Serial.available() > 0) {
val = Serial.read();
Serial.println(val); }
}
35
Task
• Using input and output commands find the
ASCII values of
#
1
2
3
4
5
ASCII
49
50
51
52
53
#
6
7
8
9
ASCII
54
55
56
57
@
a
b
c
d
e
f
g
ASCII
97
98
99
100
101
102
103
@
h
i
j
k
l
m
n
ASCII
104
105
106
107
108
109
110
@
o
p
q
r
s
t
u
ASCII
111
112
113
114
115
116
117
@
v
w
x
y
z
ASCII
118
119
120
121
122
36
INPUT EXAMPLE
int val = 0;int greenLED = 13;void setup() {
Serial.begin(9600); pinMode(greenLED, OUTPUT);
}void loop() { if(Serial.available()>0) { val = Serial.read();
Serial.println(val); } if(val == 53) {
digitalWrite(greenLED, HIGH); } else {
digitalWrite(greenLED, LOW); }}
37
Task
• Create a program so that when the user
enters 1 the green light is illuminated, 2 the
yellow light is illuminated and 3 the red light
is illuminated
37
• Create a program so that when the user
enters ‘b’ the green light blinks, ‘g’ the green
light is illuminated ‘y’ the yellow light is
illuminated and ‘r’ the red light is illuminated
38
Task
• Light Mode Video
• Create a program that
– when the user enters ‘1’ all lights turn on
– when the user enters ‘2’ all lights flash
– when the user enters ‘3’ lights cycle repeatedly
– when the user enters ‘q’ or ‘e’ the lights turn off
–when + or - is pressed the speed of the LED
increase or decrease
39
BOOLEAN VARIABLES
boolean done = true;
40
Run-Once Example
40
boolean done = false;void setup() { Serial.begin(9600);}void loop() {
if(!done) { Serial.println(“HELLO WORLD”);
done = true; }
}
41
TASK
• Write a program that asks the user for a
number and outputs the number that is
entered. Once the number has been output
the program finishes.
– EXAMPLE:
41
Please enter a number: 1 <enter>
The number you entered was: 1
42
TASK
• Write a program that asks the user for a
number and outputs the number squared
that is entered. Once the number has been
output the program finishes.
Please enter a number: 4 <enter>
Your number squared is: 16
43
Christmas Light Assignment
• Using at least 5 LEDs create a program that
has at least 4 different modes
• Must use if statements and user input to
switch modes
• Marks:
– Creativity [4 Marks]
– Working user input [2 Marks]
– Four Working modes [2 Marks]
– Instructions [1 Mark]
43

Weitere ähnliche Inhalte

Was ist angesagt?

Obstacle detection using ultra sonic sensor
Obstacle detection using ultra sonic sensorObstacle detection using ultra sonic sensor
Obstacle detection using ultra sonic sensorsatyashanker
 
Digital Electronics - Counters
Digital Electronics - CountersDigital Electronics - Counters
Digital Electronics - CountersJayakrishnanJ11
 
Presentation on pneumatic actuator
Presentation on pneumatic actuatorPresentation on pneumatic actuator
Presentation on pneumatic actuatorManish Tiwari
 
Push Button Switches
Push Button Switches Push Button Switches
Push Button Switches Kaleem
 
Application of operational amplifier
Application of operational amplifierApplication of operational amplifier
Application of operational amplifierAhmad Raza
 
Digital frequency meter
Digital frequency meterDigital frequency meter
Digital frequency meteramit parcha
 
Successive Approximation ADC
Successive Approximation ADC Successive Approximation ADC
Successive Approximation ADC AbhayDhupar
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORAnil Yadav
 
Digital storage ocilloscope
Digital storage ocilloscopeDigital storage ocilloscope
Digital storage ocilloscopekajal8899
 
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...MaryJacob24
 
Arduino: On-board components description, IDE and Programming
Arduino: On-board components description, IDE and Programming Arduino: On-board components description, IDE and Programming
Arduino: On-board components description, IDE and Programming Pawan Dubey, PhD
 
Relay Presentation PPT by G@nesh
Relay Presentation PPT by G@neshRelay Presentation PPT by G@nesh
Relay Presentation PPT by G@neshKOMMARINASANTHOSH
 
Water level indicator
Water level indicatorWater level indicator
Water level indicatorImtiaz Uddin
 

Was ist angesagt? (20)

Arduino Uno Pin Description
Arduino Uno Pin DescriptionArduino Uno Pin Description
Arduino Uno Pin Description
 
Buck converter
Buck converterBuck converter
Buck converter
 
Obstacle detection using ultra sonic sensor
Obstacle detection using ultra sonic sensorObstacle detection using ultra sonic sensor
Obstacle detection using ultra sonic sensor
 
Digital Electronics - Counters
Digital Electronics - CountersDigital Electronics - Counters
Digital Electronics - Counters
 
Presentation on pneumatic actuator
Presentation on pneumatic actuatorPresentation on pneumatic actuator
Presentation on pneumatic actuator
 
Push Button Switches
Push Button Switches Push Button Switches
Push Button Switches
 
Application of operational amplifier
Application of operational amplifierApplication of operational amplifier
Application of operational amplifier
 
Digital frequency meter
Digital frequency meterDigital frequency meter
Digital frequency meter
 
Successive Approximation ADC
Successive Approximation ADC Successive Approximation ADC
Successive Approximation ADC
 
Ac fundamentals
Ac fundamentalsAc fundamentals
Ac fundamentals
 
Encoder
EncoderEncoder
Encoder
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTOR
 
Digital storage ocilloscope
Digital storage ocilloscopeDigital storage ocilloscope
Digital storage ocilloscope
 
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
 
Robot arm ppt
Robot arm pptRobot arm ppt
Robot arm ppt
 
Arduino: On-board components description, IDE and Programming
Arduino: On-board components description, IDE and Programming Arduino: On-board components description, IDE and Programming
Arduino: On-board components description, IDE and Programming
 
Relay Presentation PPT by G@nesh
Relay Presentation PPT by G@neshRelay Presentation PPT by G@nesh
Relay Presentation PPT by G@nesh
 
Water level indicator
Water level indicatorWater level indicator
Water level indicator
 
Power supply
Power supplyPower supply
Power supply
 
D Flip Flop
D Flip Flop D Flip Flop
D Flip Flop
 

Ähnlich wie ARDUINO PROGRAMMING: Automated Mini City Project

The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IOT Academy
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdfJayanthi Kannan MK
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3Jeni Shah
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerMujahid Hussain
 
Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5Syed Mustafa
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalTony Olsson.
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalTony Olsson.
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshopatuline
 
32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technologyBharat Biyani
 
Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and RoboticsMebin P M
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for BeginnersSarwan Singh
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/OJune-Hao Hou
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming FamiliarizationAmit Kumer Podder
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptxAadilKk
 

Ähnlich wie ARDUINO PROGRAMMING: Automated Mini City Project (20)

The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
 
Arduino programming
Arduino programmingArduino programming
Arduino programming
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology
 
Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/O
 
Anup2
Anup2Anup2
Anup2
 
arduino.ppt
arduino.pptarduino.ppt
arduino.ppt
 
Arduino based applications part 1
Arduino based applications part 1Arduino based applications part 1
Arduino based applications part 1
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming Familiarization
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptx
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
 

Mehr von HebaEng

MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfMATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfHebaEng
 
Estimate the value of the following limits.pptx
Estimate the value of the following limits.pptxEstimate the value of the following limits.pptx
Estimate the value of the following limits.pptxHebaEng
 
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdflecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdfHebaEng
 
LECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxLECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxHebaEng
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdfHebaEng
 
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdflect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdfHebaEng
 
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxsensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxHebaEng
 
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHomework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHebaEng
 
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggPIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggHebaEng
 
lecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).pptlecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).pptHebaEng
 
math6.pdf
math6.pdfmath6.pdf
math6.pdfHebaEng
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfHebaEng
 
digital10.pdf
digital10.pdfdigital10.pdf
digital10.pdfHebaEng
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfHebaEng
 
Instruction 3.pptx
Instruction 3.pptxInstruction 3.pptx
Instruction 3.pptxHebaEng
 
IO and MAX 2.pptx
IO and MAX 2.pptxIO and MAX 2.pptx
IO and MAX 2.pptxHebaEng
 
BUS DRIVER.pptx
BUS DRIVER.pptxBUS DRIVER.pptx
BUS DRIVER.pptxHebaEng
 
VRAM & DEBUG.pptx
VRAM & DEBUG.pptxVRAM & DEBUG.pptx
VRAM & DEBUG.pptxHebaEng
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptxHebaEng
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptxHebaEng
 

Mehr von HebaEng (20)

MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfMATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
 
Estimate the value of the following limits.pptx
Estimate the value of the following limits.pptxEstimate the value of the following limits.pptx
Estimate the value of the following limits.pptx
 
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdflecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
 
LECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxLECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptx
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
 
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdflect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
 
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxsensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
 
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHomework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
 
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggPIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
 
lecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).pptlecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).ppt
 
math6.pdf
math6.pdfmath6.pdf
math6.pdf
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
 
digital10.pdf
digital10.pdfdigital10.pdf
digital10.pdf
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdf
 
Instruction 3.pptx
Instruction 3.pptxInstruction 3.pptx
Instruction 3.pptx
 
IO and MAX 2.pptx
IO and MAX 2.pptxIO and MAX 2.pptx
IO and MAX 2.pptx
 
BUS DRIVER.pptx
BUS DRIVER.pptxBUS DRIVER.pptx
BUS DRIVER.pptx
 
VRAM & DEBUG.pptx
VRAM & DEBUG.pptxVRAM & DEBUG.pptx
VRAM & DEBUG.pptx
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
 

Kürzlich hochgeladen

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Kürzlich hochgeladen (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

ARDUINO PROGRAMMING: Automated Mini City Project

  • 1. ARDUINO PROGRAMMING Working with the Arduino microcontroller
  • 3. 3 Mini City • Light sensitive street lights • Timed Traffic Lights • Automated Gates using proximity sensor • Cars that drive the City streets 3
  • 4. Arduino Programming USB (Data & Power) Alternate Power (9V) Digital I/O (2 – 13) Serial Transfer (0 -1) Analog Input (0 – 5) 5V / 9V / GND (x2) Power Source Jumper Reset
  • 5. Compile Upload to controller Text Output (Serial Data) Code Editor Serial Monitor Arduino IDE Window
  • 6. Arduino Code Basics • Commands and other information are sent to LED’s, motors and from sensors through digital and analog input & output pins
  • 8. Arduino Code Basics Arduino programs run on two basic sections: void setup() { //setup motors, sensors etc } void loop() { // get information from sensors // send commands to motors }
  • 9. 9 SETUP • The setup section is used for assigning input and outputs (Examples: motors, LED’s, sensors etc) to ports on the Arduino • It also specifies whether the device is OUTPUT or INPUT • To do this we use the command “pinMode” 9
  • 10. SETUP void setup() { pinMode(9, OUTPUT); } http://www.arduino.cc/en/Reference/HomePage port # Input or Output
  • 11. 11 void loop() { digitalWrite(9, HIGH); delay(1000); digitalWrite(9, LOW); delay(1000); } LOOP Port # from setup Turn the LED on or off Wait for 1 second or 1000 milliseconds
  • 12. 12 TASK 1 • Using 3 LED’s (red, yellow and green) build a traffic light that – Illuminates the green LED for 5 seconds – Illuminates the yellow LED for 2 seconds – Illuminates the red LED for 5 seconds – repeats the sequence • Note that after each illumination period the LED is turned off! 12
  • 13. 13 TASK 2 • Modify Task 1 to have an advanced green (blinking green LED) for 3 seconds before illuminating the green LED for 5 seconds 13
  • 14. 14 Variables • A variable is like “bucket” • It holds numbers or other values temporarily 14 value
  • 15. 15 int val = 5; DECLARING A VARIABLE Type variable name assignment “becomes” value
  • 16. 16 Task • Replace all delay times with variables • Replace LED pin numbers with variables 16
  • 17. 17 USING VARIABLES int delayTime = 2000; int greenLED = 9; void setup() { pinMode(greenLED, OUTPUT); } void loop() { digitalWrite(greenLED, HIGH); delay(delayTime); digitalWrite(greenLED, LOW); delay(delayTime); } Declare delayTime Variable Use delayTime Variable
  • 18. 18 Using Variables int delayTime = 2000; int greenLED = 9; void setup() { pinMode(greenLED, OUTPUT); } void loop() { digitalWrite(greenLED, HIGH); delay(delayTime); digitalWrite(greenLED, LOW); delayTime = delayTime - 100; delay(delayTime); } subtract 100 from delayTime to gradually increase LED’s blinking speed
  • 19. Conditions •To make decisions in Arduino code we use an ‘if’ statement •‘If’ statements are based on a TRUE or FALSE question
  • 20. 20 VALUE COMPARISONS GREATER THAN a > b LESS a < b EQUAL a == b GREATER THAN OR EQUAL a >= b LESS THAN OR EQUAL a <= b NOT EQUAL a != b
  • 22. 22 int counter = 0; void setup() { Serial.begin(9600); } void loop() { if(counter < 10) { Serial.println(counter); } counter = counter + 1; } IF Example
  • 23. 23 TASK • Create a program that resets the delayTime to 2000 once it has reached 0 23
  • 24. 24 Input & Output • Transferring data from the computer to an Arduino is done using Serial Transmission • To setup Serial communication we use the following 24 void setup() { Serial.begin(9600); }
  • 25. 25 Writing to the Console void setup() { Serial.begin(9600); Serial.println(“Hello World!”); } void loop() {}
  • 26. 26 Task • Modify your traffic light code so that each time a new LED is illuminated the console displays the status of the stoplight • Example 26 Advanced Green Green Yellow Red Advanced Green ...
  • 27. IF - ELSE Condition asdfadsf if( “answer is true”) { “perform some action” } else { “perform some other action” }
  • 28. 28 int counter = 0; void setup() { Serial.begin(9600); } void loop() { if(counter < 10) { Serial.println(“less than 10”); } else { Serial.println(“greater than or equal to 10”); Serial.end(); } counter = counter + 1; } IF - ELSE Example
  • 29. IF - ELSE IF Condition asdfadsf if( “answer is true”) { “perform some action” } else if( “answer is true”) { “perform some other action” }
  • 30. 30 int counter = 0; void setup() { Serial.begin(9600); } void loop() { if(counter < 10) { Serial.println(“less than 10”); } else if (counter == 10) { Serial.println(“equal to 10”); } else { Serial.println(“greater than 10”); Serial.end(); } counter = counter + 1; } IF - ELSE Example
  • 31. 31 BOOLEAN OPERATORS - AND • If we want all of the conditions to be true we need to use ‘AND’ logic (AND gate) • We use the symbols && –Example 31 if ( val > 10 && val < 20)
  • 32. 32 BOOLEAN OPERATORS - OR • If we want either of the conditions to be true we need to use ‘OR’ logic (OR gate) • We use the symbols || –Example 32 if ( val < 10 || val > 20)
  • 33. 33 TASK • Create a program that illuminates the green LED if the counter is less than 100, illuminates the yellow LED if the counter is between 101 and 200 and illuminates the red LED if the counter is greater than 200 33
  • 34. 34 INPUT • We can also use our Serial connection to get input from the computer to be used by the Arduino int val = 0;void setup() { Serial.begin(9600); }void loop() { if(Serial.available() > 0) { val = Serial.read(); Serial.println(val); } }
  • 35. 35 Task • Using input and output commands find the ASCII values of # 1 2 3 4 5 ASCII 49 50 51 52 53 # 6 7 8 9 ASCII 54 55 56 57 @ a b c d e f g ASCII 97 98 99 100 101 102 103 @ h i j k l m n ASCII 104 105 106 107 108 109 110 @ o p q r s t u ASCII 111 112 113 114 115 116 117 @ v w x y z ASCII 118 119 120 121 122
  • 36. 36 INPUT EXAMPLE int val = 0;int greenLED = 13;void setup() { Serial.begin(9600); pinMode(greenLED, OUTPUT); }void loop() { if(Serial.available()>0) { val = Serial.read(); Serial.println(val); } if(val == 53) { digitalWrite(greenLED, HIGH); } else { digitalWrite(greenLED, LOW); }}
  • 37. 37 Task • Create a program so that when the user enters 1 the green light is illuminated, 2 the yellow light is illuminated and 3 the red light is illuminated 37 • Create a program so that when the user enters ‘b’ the green light blinks, ‘g’ the green light is illuminated ‘y’ the yellow light is illuminated and ‘r’ the red light is illuminated
  • 38. 38 Task • Light Mode Video • Create a program that – when the user enters ‘1’ all lights turn on – when the user enters ‘2’ all lights flash – when the user enters ‘3’ lights cycle repeatedly – when the user enters ‘q’ or ‘e’ the lights turn off –when + or - is pressed the speed of the LED increase or decrease
  • 40. 40 Run-Once Example 40 boolean done = false;void setup() { Serial.begin(9600);}void loop() { if(!done) { Serial.println(“HELLO WORLD”); done = true; } }
  • 41. 41 TASK • Write a program that asks the user for a number and outputs the number that is entered. Once the number has been output the program finishes. – EXAMPLE: 41 Please enter a number: 1 <enter> The number you entered was: 1
  • 42. 42 TASK • Write a program that asks the user for a number and outputs the number squared that is entered. Once the number has been output the program finishes. Please enter a number: 4 <enter> Your number squared is: 16
  • 43. 43 Christmas Light Assignment • Using at least 5 LEDs create a program that has at least 4 different modes • Must use if statements and user input to switch modes • Marks: – Creativity [4 Marks] – Working user input [2 Marks] – Four Working modes [2 Marks] – Instructions [1 Mark] 43