SlideShare a Scribd company logo
1 of 7
1
Arduino Tutorial #4
- Measuring the distance -
Dong Ho Son
POSTECH
Pohang, Korea
donghoson@postech.ac.kr
2
Measuring the distance - Overview
 Infrared proximity sensor (GP2Y0A21YK0F)
• A sensor to detect the presence of nearby objects without any physical contact
• The sensor has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm
 How the circuit works
• Infrared proximity sensor will sense the distance and send the result to the
Arduino board
• A serial monitor shows the distance from the sensor to the target object
Source: commons.wikimedia.org/wiki/File:Sharp_GP2Y0A21YK_IR_proximity_sensor.jpg
3
Measuring the distance – configuring the circuit
 Configure the circuit
VOC
GND
Vout
Source: pixabay.com/photo-2168193
4
Measuring the distance - Sketch
 Declare variables
• float Vcc = 5.0;  Voltage
• float dist;  Distance
 setup() { }
• Serial.begin(9600);
− Prepare the serial communication to get
the value of distance (from the sensor)
− 9600 : serial communication speed
– 9600 bits per second is the default for the Arduino
5
Measuring the distance - Sketch
 loop() { }
• dist = Vcc * analogRead(A0) / 1023;
− Read analog value of infrared distance
− analogRead(A0) returns the value as 10 bit
− 210=1024, 0~1023 values are returned
− Dividing the output by 1023  the distance
• dist = 26.549 * pow(dist, -1.2091);
− Formula [Distance = 26.549 × 𝑉𝑜𝑙𝑡𝑎𝑔𝑒−1.2091]
http://image.dfrobot.com/image/data/SEN0014/gp2y0a21yk0f.pdf
6
Measuring the distance - Sketch
 loop() { }
• Serial.print(“ Dist = ”);
− It prints the text “ Dist = ” to the serial console
• Serial.print(dist);
− It prints the value of ‘dist’ to the serial console
• Serial.println(“ cm ”);
− It prints the text “ cm ” to the serial console
− Also changes the line (newline)
• Delay(300);
− Need 300ms to check step-by-step
7
Measuring the distance - Result
 The sensor measures the distance!
10cm
Dist = 10.00 cm
20cm
Dist = 20.00 cm
Dist = 40.00 cm
40cm
Dist = 80.00 cm
80cm
VOC
GND
Vout
Source: pixabay.com/photo-2168193

More Related Content

Similar to Arduino tutorial #4

Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino MajdyShamasneh
 
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Satoru Tokuhisa
 
MaxBotix Code Examples
MaxBotix Code ExamplesMaxBotix Code Examples
MaxBotix Code ExamplesMaxBotix Inc
 
OV7670 Camera interfacing-with-arduino-microcontroller
OV7670 Camera interfacing-with-arduino-microcontrollerOV7670 Camera interfacing-with-arduino-microcontroller
OV7670 Camera interfacing-with-arduino-microcontrollerSomnath Sharma
 
Embedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
Embedded PPT 2.0-1.pptxkkkkhhhhhggggggggggEmbedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
Embedded PPT 2.0-1.pptxkkkkhhhhhggggggggggSapnaDodamani1
 
Indoor & outdoor distance sensing mobile robot
Indoor & outdoor distance sensing mobile robotIndoor & outdoor distance sensing mobile robot
Indoor & outdoor distance sensing mobile robotzolofy
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming FamiliarizationAmit Kumer Podder
 
Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...
Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...
Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...Wanita Long
 
Short Range Radar System using Arduino Uno
Short Range Radar System using Arduino UnoShort Range Radar System using Arduino Uno
Short Range Radar System using Arduino UnoIRJET Journal
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Scienceresearchinventy
 
Smart shoe
Smart shoeSmart shoe
Smart shoeslmnsvn
 

Similar to Arduino tutorial #4 (20)

Arduino radar system
Arduino radar systemArduino radar system
Arduino radar system
 
Radar Detector
Radar Detector Radar Detector
Radar Detector
 
Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino
 
RADAR
RADARRADAR
RADAR
 
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2
 
MaxBotix Code Examples
MaxBotix Code ExamplesMaxBotix Code Examples
MaxBotix Code Examples
 
Modern Equipment's in Survey Works
Modern Equipment's in Survey WorksModern Equipment's in Survey Works
Modern Equipment's in Survey Works
 
OV7670 Camera interfacing-with-arduino-microcontroller
OV7670 Camera interfacing-with-arduino-microcontrollerOV7670 Camera interfacing-with-arduino-microcontroller
OV7670 Camera interfacing-with-arduino-microcontroller
 
Certification
CertificationCertification
Certification
 
Simulation-Iss4
Simulation-Iss4Simulation-Iss4
Simulation-Iss4
 
Embedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
Embedded PPT 2.0-1.pptxkkkkhhhhhggggggggggEmbedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
Embedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
 
Indoor & outdoor distance sensing mobile robot
Indoor & outdoor distance sensing mobile robotIndoor & outdoor distance sensing mobile robot
Indoor & outdoor distance sensing mobile robot
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming Familiarization
 
Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...
Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...
Ultrasonic Distance Measurement NRF905 Wireless Transmission System Based on ...
 
Rangefinder ppt
Rangefinder pptRangefinder ppt
Rangefinder ppt
 
FinalOral_v1_5_rob
FinalOral_v1_5_robFinalOral_v1_5_rob
FinalOral_v1_5_rob
 
Short Range Radar System using Arduino Uno
Short Range Radar System using Arduino UnoShort Range Radar System using Arduino Uno
Short Range Radar System using Arduino Uno
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Science
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
 
Smart shoe
Smart shoeSmart shoe
Smart shoe
 

More from 동호 손

Raspberry pi : how to get started
Raspberry pi : how to get startedRaspberry pi : how to get started
Raspberry pi : how to get started동호 손
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi동호 손
 
Arduino tutorial #1
Arduino tutorial #1Arduino tutorial #1
Arduino tutorial #1동호 손
 
Arduino : how to get started
Arduino : how to get startedArduino : how to get started
Arduino : how to get started동호 손
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino동호 손
 
OpenVirtex (OVX) Tutorial
OpenVirtex (OVX) TutorialOpenVirtex (OVX) Tutorial
OpenVirtex (OVX) Tutorial동호 손
 

More from 동호 손 (6)

Raspberry pi : how to get started
Raspberry pi : how to get startedRaspberry pi : how to get started
Raspberry pi : how to get started
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
 
Arduino tutorial #1
Arduino tutorial #1Arduino tutorial #1
Arduino tutorial #1
 
Arduino : how to get started
Arduino : how to get startedArduino : how to get started
Arduino : how to get started
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
OpenVirtex (OVX) Tutorial
OpenVirtex (OVX) TutorialOpenVirtex (OVX) Tutorial
OpenVirtex (OVX) Tutorial
 

Recently uploaded

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Arduino tutorial #4

  • 1. 1 Arduino Tutorial #4 - Measuring the distance - Dong Ho Son POSTECH Pohang, Korea donghoson@postech.ac.kr
  • 2. 2 Measuring the distance - Overview  Infrared proximity sensor (GP2Y0A21YK0F) • A sensor to detect the presence of nearby objects without any physical contact • The sensor has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm  How the circuit works • Infrared proximity sensor will sense the distance and send the result to the Arduino board • A serial monitor shows the distance from the sensor to the target object Source: commons.wikimedia.org/wiki/File:Sharp_GP2Y0A21YK_IR_proximity_sensor.jpg
  • 3. 3 Measuring the distance – configuring the circuit  Configure the circuit VOC GND Vout Source: pixabay.com/photo-2168193
  • 4. 4 Measuring the distance - Sketch  Declare variables • float Vcc = 5.0;  Voltage • float dist;  Distance  setup() { } • Serial.begin(9600); − Prepare the serial communication to get the value of distance (from the sensor) − 9600 : serial communication speed – 9600 bits per second is the default for the Arduino
  • 5. 5 Measuring the distance - Sketch  loop() { } • dist = Vcc * analogRead(A0) / 1023; − Read analog value of infrared distance − analogRead(A0) returns the value as 10 bit − 210=1024, 0~1023 values are returned − Dividing the output by 1023  the distance • dist = 26.549 * pow(dist, -1.2091); − Formula [Distance = 26.549 × 𝑉𝑜𝑙𝑡𝑎𝑔𝑒−1.2091] http://image.dfrobot.com/image/data/SEN0014/gp2y0a21yk0f.pdf
  • 6. 6 Measuring the distance - Sketch  loop() { } • Serial.print(“ Dist = ”); − It prints the text “ Dist = ” to the serial console • Serial.print(dist); − It prints the value of ‘dist’ to the serial console • Serial.println(“ cm ”); − It prints the text “ cm ” to the serial console − Also changes the line (newline) • Delay(300); − Need 300ms to check step-by-step
  • 7. 7 Measuring the distance - Result  The sensor measures the distance! 10cm Dist = 10.00 cm 20cm Dist = 20.00 cm Dist = 40.00 cm 40cm Dist = 80.00 cm 80cm VOC GND Vout Source: pixabay.com/photo-2168193