SlideShare a Scribd company logo
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

Arduino radar system
Arduino radar systemArduino radar system
Arduino radar system
delhi technological university
 
Radar Detector
Radar Detector Radar Detector
Radar Detector
RahulNarang40
 
Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino
MajdyShamasneh
 
RADAR
RADARRADAR
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2
Satoru Tokuhisa
 
MaxBotix Code Examples
MaxBotix Code ExamplesMaxBotix Code Examples
MaxBotix Code Examples
MaxBotix Inc
 
Modern Equipment's in Survey Works
Modern Equipment's in Survey WorksModern Equipment's in Survey Works
Modern Equipment's in Survey Works
Sujith Velloor Sudarsanakumar Nair
 
OV7670 Camera interfacing-with-arduino-microcontroller
OV7670 Camera interfacing-with-arduino-microcontrollerOV7670 Camera interfacing-with-arduino-microcontroller
OV7670 Camera interfacing-with-arduino-microcontroller
Somnath Sharma
 
Certification
CertificationCertification
Certification
subhransu mishra
 
Simulation-Iss4
Simulation-Iss4Simulation-Iss4
Embedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
Embedded PPT 2.0-1.pptxkkkkhhhhhggggggggggEmbedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
Embedded PPT 2.0-1.pptxkkkkhhhhhgggggggggg
SapnaDodamani1
 
Indoor & outdoor distance sensing mobile robot
Indoor & outdoor distance sensing mobile robotIndoor & outdoor distance sensing mobile robot
Indoor & outdoor distance sensing mobile robot
zolofy
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming Familiarization
Amit 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
 
Rangefinder ppt
Rangefinder pptRangefinder ppt
Rangefinder ppt
KaushlendraSingh44
 
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
hussain0075468
 
FinalOral_v1_5_rob
FinalOral_v1_5_robFinalOral_v1_5_rob
FinalOral_v1_5_rob
ROBERT MCGILVREY
 
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
IRJET 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 Science
researchinventy
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
Electric&elctronics&engineeering
 

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
 
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
 
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
 

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

14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 

Recently uploaded (20)

14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 

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