SlideShare a Scribd company logo
Welcome
to Robotics
Lab Rules
Uniform
Attendance
Class Schedule
Smart Parking
Assistant
Engr. Hassan Mehmood Khan
Robotics Lab Incharge
List of Components
• Arduino UNO
• Breadboard
• Ultrasonic sensor
• LED Traffic Light Module
• Connecting Wires
• Programming Cable
• 9V Battery
• Connecting wires and clips
Arduino UNO
Digital I/O pins – input and output
pins (0 -13) of which 6 of them (3, 5, 6,
9, 10 and 11) also provide PWM (Pulse
Width Modulated) output by using the
analogWrite() function.
Pins (0 (RX) and 1 (TX)) are also used to
transmit and receive serial data.
The microcontroller development
board that will be at the heart of your
projects. It’s a simple computer, but
one that has no way for you to
interact with it yet. You will be
building the circuits and interfaces for
interaction, and telling the
microcontroller how to interface with
other components.
Digital IO
• The digital inputs and outputs (digital I/O) on
the Arduino are what allow you to connect
sensors, actuators, and other ICs to the
Arduino .
• Learning how to use the inputs and outputs will
allow you to use the Arduino to do some really
useful things, such as reading switch inputs,
lighting indicators, and controlling relay
outputs.
• Unlike analog signals, which may take on any
value within a range of values, digital signals
have two distinct values: HIGH (1) or LOW (0).
You use digital signals in situationswhere the
input or output will have one of those two
values. For example, one way that you might
use a digital signal is to turn an LED on or off.
Breadboard
A board on which you can build electronic circuits.
It’s like a patch panel, with rows of holes that allow
you to connect wires and components together.
Versions that require soldering are available, as well
as the solder-less type used here.
Ultrasonic Distance Sensor
RGB LED Module
•Size: 56 * 21 * 11mm
•Color: red, yellow green
•LED: 5mm * 3
•Brightness: Normal
brightness
•Voltage: 5V
•Input: Digital signal output
•Interface: common
cathode red yellow-green
control
Traffic Light Project
Wiring Diagram
Functions
• The Arduino functions
associated with digital
signals that we will be
using are:
• pinMode()
• digitalRead()
• digitalWrite()
pinMode (pin_number, mode)
Because the Arduino digital I/O pins can be used for
either input or output, you should first configure the
pins you intend to use for digital I/O with this
function. pin is the number of the pin you wish to
configure. mode must be one of three values: INPUT,
OUTPUT. (third value we will not discuss here)
digitalWrite(pin_number,value)
This function writes a digital value to a
pin. pin specifies which Arduino pin the digital value
will be written to, and value is the digital value to which
the pin is set. Value must be either HIGH or LOW.
digitalRead(pin_number)
This function reads a digital value from a pin. pin is the
number of the digital I/O pin you want to read. This
function returns one of two values: HIGH or LOW.
Programming
int red = 2;
int yellow = 3;
int green = 4;
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow,
OUTPUT);
pinMode(green, OUTPUT);
}
void loop(){
// green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
// turn off yellow, then turn red on for 5
seconds
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
// red and yellow on for 2 seconds (red is
already on though)
digitalWrite(yellow, HIGH);
delay(2000);
// turn off red and yellow, then turn on green
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(3000);
Programming
• The program consists of four distinct steps:
• Green on, yellow off
• Yellow off, red on
• Yellow on, red on
• Green on, red off, yellow off
• These four steps replicate the process used in real traffic
lights. For each step, the code is very similar. The
appropriate LED gets turned on or off using digitalWrite.
This is an Arduino function used to set output pins to HIGH
(for on), or LOW (for off).
Circuit Diagram
Programming
int trigPin = 2; // Trigger
int echoPin = 3; // Echo
int LED_Red = 10; // Red LED
int LED_Yellow = 8; // Yellow LED
int LED_Green = 9; // Green LED
long duration, cm, inches;
void setup()
{
//Serial Port begin
Serial.begin (9600);
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LED_Red, OUTPUT);
pinMode(LED_Yellow, OUTPUT);
pinMode(LED_Green, OUTPUT);
digitalWrite(LED_Red, LOW);
digitalWrite(LED_Yellow, LOW);
digitalWrite(LED_Green, LOW);
}
Programming
void loop() {
// The sensor is triggered by a HIGH
pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand
to ensure a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a
HIGH pulse whose duration is the time
(in microseconds) from the sending of
the ping to the reception of its echo off
of an object.
duration = pulseIn(echoPin, HIGH);
// Convert the time into a distance
cm = (duration/2) / 29.1; // Divide
by 29.1 or multiply by 0.0343
inches = (duration/2) / 74; // Divide
by 74 or multiply by 0.0135
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
if(cm<10)
{
digitalWrite(LED_Red, HIGH);
digitalWrite(LED_Yellow, LOW);
digitalWrite(LED_Green, LOW);
}
if((cm<20) && (cm>10))
{
digitalWrite(LED_Red, LOW);
digitalWrite(LED_Yellow, HIGH);
digitalWrite(LED_Green, LOW);
}
if(cm>20)
{
digitalWrite(LED_Red, LOW);
digitalWrite(LED_Yellow, LOW);
digitalWrite(LED_Green, HIGH);
}
delay(250);
}
Simulation
THANK YOU
Ad

More Related Content

Similar to Lecture2- Smart Parking Assistant using Arduino (20)

Arduino
ArduinoArduino
Arduino
LetzkuLetz Castro
 
Arduino اردوينو
Arduino اردوينوArduino اردوينو
Arduino اردوينو
salih mahmod
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptx
AadilKk
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
sdcharle
 
Arduino . .
Arduino             .                             .Arduino             .                             .
Arduino . .
dryazhinians
 
Introduction to Arduino - Basics programming
Introduction to Arduino - Basics programmingIntroduction to Arduino - Basics programming
Introduction to Arduino - Basics programming
KishoreKumarKAsstPro
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
Qtechknow
 
Arduino_Beginner.pptx
Arduino_Beginner.pptxArduino_Beginner.pptx
Arduino_Beginner.pptx
shivagoud45
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
Wingston
 
LinnStrument : the ultimate open-source hacker instrument
LinnStrument : the ultimate open-source hacker instrumentLinnStrument : the ultimate open-source hacker instrument
LinnStrument : the ultimate open-source hacker instrument
Geert Bevin
 
Arduino board program for Mobile robotss
Arduino board program for Mobile robotssArduino board program for Mobile robotss
Arduino board program for Mobile robotss
VSARAVANAKUMARHICETS
 
Arduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagramArduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagram
ArifatunNesa
 
ArduinoSectionI-slides.ppt
ArduinoSectionI-slides.pptArduinoSectionI-slides.ppt
ArduinoSectionI-slides.ppt
Lam Hung
 
introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfintroductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdf
HebaEng
 
Basics of arduino uno
Basics of arduino unoBasics of arduino uno
Basics of arduino uno
Rahat Sood
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
Ravikumar Tiwari
 
2009 11-17-arduino-basics
2009 11-17-arduino-basics2009 11-17-arduino-basics
2009 11-17-arduino-basics
Jhonny Wladimir Peñaloza Cabello
 
INTRODUCTION TO ARDUINO and sensors for arduino.pptx
INTRODUCTION TO ARDUINO and sensors for arduino.pptxINTRODUCTION TO ARDUINO and sensors for arduino.pptx
INTRODUCTION TO ARDUINO and sensors for arduino.pptx
Jo Mebs
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 
Arduino اردوينو
Arduino اردوينوArduino اردوينو
Arduino اردوينو
salih mahmod
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptx
AadilKk
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
sdcharle
 
Introduction to Arduino - Basics programming
Introduction to Arduino - Basics programmingIntroduction to Arduino - Basics programming
Introduction to Arduino - Basics programming
KishoreKumarKAsstPro
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
Qtechknow
 
Arduino_Beginner.pptx
Arduino_Beginner.pptxArduino_Beginner.pptx
Arduino_Beginner.pptx
shivagoud45
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
Wingston
 
LinnStrument : the ultimate open-source hacker instrument
LinnStrument : the ultimate open-source hacker instrumentLinnStrument : the ultimate open-source hacker instrument
LinnStrument : the ultimate open-source hacker instrument
Geert Bevin
 
Arduino board program for Mobile robotss
Arduino board program for Mobile robotssArduino board program for Mobile robotss
Arduino board program for Mobile robotss
VSARAVANAKUMARHICETS
 
Arduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagramArduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagram
ArifatunNesa
 
ArduinoSectionI-slides.ppt
ArduinoSectionI-slides.pptArduinoSectionI-slides.ppt
ArduinoSectionI-slides.ppt
Lam Hung
 
introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfintroductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdf
HebaEng
 
Basics of arduino uno
Basics of arduino unoBasics of arduino uno
Basics of arduino uno
Rahat Sood
 
INTRODUCTION TO ARDUINO and sensors for arduino.pptx
INTRODUCTION TO ARDUINO and sensors for arduino.pptxINTRODUCTION TO ARDUINO and sensors for arduino.pptx
INTRODUCTION TO ARDUINO and sensors for arduino.pptx
Jo Mebs
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 

Recently uploaded (20)

introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
LECTURE-16 EARTHEN DAM - II.pptx it's uses
LECTURE-16 EARTHEN DAM - II.pptx it's usesLECTURE-16 EARTHEN DAM - II.pptx it's uses
LECTURE-16 EARTHEN DAM - II.pptx it's uses
CLokeshBehera123
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
LECTURE-16 EARTHEN DAM - II.pptx it's uses
LECTURE-16 EARTHEN DAM - II.pptx it's usesLECTURE-16 EARTHEN DAM - II.pptx it's uses
LECTURE-16 EARTHEN DAM - II.pptx it's uses
CLokeshBehera123
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Ad

Lecture2- Smart Parking Assistant using Arduino

  • 3. Smart Parking Assistant Engr. Hassan Mehmood Khan Robotics Lab Incharge
  • 4. List of Components • Arduino UNO • Breadboard • Ultrasonic sensor • LED Traffic Light Module • Connecting Wires • Programming Cable • 9V Battery • Connecting wires and clips
  • 5. Arduino UNO Digital I/O pins – input and output pins (0 -13) of which 6 of them (3, 5, 6, 9, 10 and 11) also provide PWM (Pulse Width Modulated) output by using the analogWrite() function. Pins (0 (RX) and 1 (TX)) are also used to transmit and receive serial data. The microcontroller development board that will be at the heart of your projects. It’s a simple computer, but one that has no way for you to interact with it yet. You will be building the circuits and interfaces for interaction, and telling the microcontroller how to interface with other components.
  • 6. Digital IO • The digital inputs and outputs (digital I/O) on the Arduino are what allow you to connect sensors, actuators, and other ICs to the Arduino . • Learning how to use the inputs and outputs will allow you to use the Arduino to do some really useful things, such as reading switch inputs, lighting indicators, and controlling relay outputs. • Unlike analog signals, which may take on any value within a range of values, digital signals have two distinct values: HIGH (1) or LOW (0). You use digital signals in situationswhere the input or output will have one of those two values. For example, one way that you might use a digital signal is to turn an LED on or off.
  • 7. Breadboard A board on which you can build electronic circuits. It’s like a patch panel, with rows of holes that allow you to connect wires and components together. Versions that require soldering are available, as well as the solder-less type used here.
  • 9. RGB LED Module •Size: 56 * 21 * 11mm •Color: red, yellow green •LED: 5mm * 3 •Brightness: Normal brightness •Voltage: 5V •Input: Digital signal output •Interface: common cathode red yellow-green control
  • 12. Functions • The Arduino functions associated with digital signals that we will be using are: • pinMode() • digitalRead() • digitalWrite() pinMode (pin_number, mode) Because the Arduino digital I/O pins can be used for either input or output, you should first configure the pins you intend to use for digital I/O with this function. pin is the number of the pin you wish to configure. mode must be one of three values: INPUT, OUTPUT. (third value we will not discuss here) digitalWrite(pin_number,value) This function writes a digital value to a pin. pin specifies which Arduino pin the digital value will be written to, and value is the digital value to which the pin is set. Value must be either HIGH or LOW. digitalRead(pin_number) This function reads a digital value from a pin. pin is the number of the digital I/O pin you want to read. This function returns one of two values: HIGH or LOW.
  • 13. Programming int red = 2; int yellow = 3; int green = 4; void setup(){ pinMode(red, OUTPUT); pinMode(yellow, OUTPUT); pinMode(green, OUTPUT); } void loop(){ // green off, yellow on for 3 seconds digitalWrite(green, LOW); digitalWrite(yellow, HIGH); delay(3000); // turn off yellow, then turn red on for 5 seconds digitalWrite(yellow, LOW); digitalWrite(red, HIGH); delay(5000); // red and yellow on for 2 seconds (red is already on though) digitalWrite(yellow, HIGH); delay(2000); // turn off red and yellow, then turn on green digitalWrite(yellow, LOW); digitalWrite(red, LOW); digitalWrite(green, HIGH); delay(3000);
  • 14. Programming • The program consists of four distinct steps: • Green on, yellow off • Yellow off, red on • Yellow on, red on • Green on, red off, yellow off • These four steps replicate the process used in real traffic lights. For each step, the code is very similar. The appropriate LED gets turned on or off using digitalWrite. This is an Arduino function used to set output pins to HIGH (for on), or LOW (for off).
  • 16. Programming int trigPin = 2; // Trigger int echoPin = 3; // Echo int LED_Red = 10; // Red LED int LED_Yellow = 8; // Yellow LED int LED_Green = 9; // Green LED long duration, cm, inches; void setup() { //Serial Port begin Serial.begin (9600); //Define inputs and outputs pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(LED_Red, OUTPUT); pinMode(LED_Yellow, OUTPUT); pinMode(LED_Green, OUTPUT); digitalWrite(LED_Red, LOW); digitalWrite(LED_Yellow, LOW); digitalWrite(LED_Green, LOW); }
  • 17. Programming void loop() { // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose duration is the time (in microseconds) from the sending of the ping to the reception of its echo off of an object. duration = pulseIn(echoPin, HIGH); // Convert the time into a distance cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343 inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135 Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); if(cm<10) { digitalWrite(LED_Red, HIGH); digitalWrite(LED_Yellow, LOW); digitalWrite(LED_Green, LOW); } if((cm<20) && (cm>10)) { digitalWrite(LED_Red, LOW); digitalWrite(LED_Yellow, HIGH); digitalWrite(LED_Green, LOW); } if(cm>20) { digitalWrite(LED_Red, LOW); digitalWrite(LED_Yellow, LOW); digitalWrite(LED_Green, HIGH); } delay(250); }