Basic Arduino Workshop
Basic Arduino Workshop
WORKSHOP
By :
Yogi Hamdani S.T., B.Eng.
[email protected]
Workshop Content
Introduction to Arduino
Arduino Programming (hands-on)
System Development
3/10/2016
INTRODUCTION TO
ARDUINO
What is Arduino?
Microcontroller board contains on board
power supply, USB port to communicate with
PC, and microcontroller chip.
Open source hardware
INPUT FROM
SENSORS
3/10/2016
PROCESSING IN
MICROCONTROLLER
OUTPUT TO
ACTUATORS
Arduino Boards
3/10/2016
Arduino Mega
54 digital input/output pins
(of which 14 can be used as PWM outputs)
16 analog inputs
USB connection
3/10/2016
Analog / Digital
All physical quantities are analog.
Analog quantity takes any value between its
minimum and maximum value.
(in Arduino 0-255 / 8 bits)
Digital quantity takes specific levels of value
with specific offset / on-off condition.
(in Arduino 0-1)
3/10/2016
ARDUINO
PROGRAMMING
Program Download
http://arduino.cc/en/Main/Software
Programming Platform
Integrated
Development
Environment (IDE)
C language
programming
3/10/2016
3/10/2016
10
Program Structure
3/10/2016
11
Program Structure
3/10/2016
12
Program Structure
3/10/2016
13
Upload Program
1. Check Connection
Click Tool ->
Select Board,
Select Port
Check on bottom
2. Click Upload
3/10/2016
14
3/10/2016
15
3/10/2016
16
Operators
Math Operators: (+,-,*,/,%,^)
example:
int x = 5;
int y = 7;
int z = x + y;
3/10/2016
17
IF Statement
Example 1:
if(condition 1)
{
do something;
}
3/10/2016
Example 2:
if(condition 1)
{
do something;
}
else
{
do something;
}
Example 3:
if(condition 1)
{
do something;
}
else if(condition 2)
{
do something;
}
else
{
do something;
}
18
Loop Statement
For
example:
for(int i=0; i<x; i++)
{
do something;
}
3/10/2016
While
example:
while(condition)
{
do something;
}
Do while
example:
do
{
do something;
}
while(condition)
19
Serial Monitor
3/10/2016
20
Exercise
Turn LED ON when switch is pressed.
Print status to serial monitor.
Ground Pin
Digital Pin
3/10/2016
21
Wiring
3/10/2016
22
Programming
3/10/2016
23
Program Code
int LED = 12;
int Switch = 8;
void setup()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);
pinMode(Switch,INPUT);
}
3/10/2016
void loop()
{
digitalWrite(LED,LOW);
if(digitalRead(Switch) == HIGH)
{
Serial.println("ON");
digitalWrite(LED,HIGH);
}
Serial.println("OFF");
delay(500);
}
24
Questions ???
SYSTEM DEVELOPMENT
(Reverse Parking Sensor System)
How it works?
1. Sensors are activated and sense the distance.
2. Controller process the data.
3. Notify driver with buzzer / LED.
3/10/2016
27
Equipments
INPUT:
- Switch
- Ping Sensor
3/10/2016
OUTPUT:
- Buzzer
- LED
28
Input Analysis
1. System is activated by switch.
2. Ping sensor send ultrasonic wave via trigger pin.
3. If hit an object, the reflected wave may be received
through echo pin.
3/10/2016
29
Ping Sensor
3/10/2016
30
Input Analysis
4. Ping sensor gives time duration (in s) between
transmission and receiving reflected wave.
5. Analyze time duration into distance measurement.
3/10/2016
31
pulseIn Function
int echo = 8
int time_duration;
void setup()
{
pinMode(echo, INPUT);
}
void loop()
{
time_duration = pulseIn(echo, HIGH);
}
3/10/2016
32
Output Requirement
1. Buzzer rings more intense as distance is closer.
2. LED blinks / turns on longer as distance is closer.
3. Give information about distance via serial monitor.
Distance Left
>= 20 cm
Buzzer
Not Ring
Ring A
Ring B
Ring C
Ring D
3/10/2016
ON
ON
ON
ON
Blink
Blink
ON
ON
33
PROGRAMMING
PLAY TIME