1.4 Distance Measurement - UltrasonicSensor - Revised
1.4 Distance Measurement - UltrasonicSensor - Revised
§ Introduction
§ Components Required
§ Methodology
§ Conclusions
§ References
Introduction
3
Components Required
▪ Arduino Uno Board - used as the main controller for the distance measurement system.
The distance measurement system using ultrasonic sensors for identification of the distance of
the obstacle in centimeters can be implemented using the following steps:
• Connect the VCC pin of the ultrasonic sensor to the 5V pin of the Arduino board.
• The TRIG pin to pin 11 of the Arduino board, and the ECHO pin to pin 12 of the Arduino board.
• Upload the code to the Arduino board. Use the Arduino IDE to write and upload the code to the
board.
• The code should read the sensor data, calculate the distance in centimeters
• Test the system. Place an object in front of the sensors and observe the LED indication.
• The distance measured by the ultrasonic sensor will be indicated based on the distance of the object
• Repeat the steps for different distances and objects to test the system's accuracy and consistency.
Figure. 1: Connect the LEDs and resistors in series between the digital output pins of the Arduino
board, such as pin 5 and pin 6, and the GND pin.
Figure. 2: Connect the trigger pin of the ultrasonic sensor module to a digital output pin
of the Arduino board, such as pin 3.
Code Used
void loop()
int trig=9;
{
int echo=10;
// put your main code here, to run repeatedly:
digitalWrite(trig,LOW);
int timeInMicroseconds;
delay(2);
int distanceInCm;
digitalWrite(trig,HIGH);
void setup()
delay(10);
{
digitalWrite(trig,LOW);
// put your setup code here, to run once:
Serial.begin(9600);
timeInMicroseconds=pulseIn(echo,HIGH);
pinMode(9,OUTPUT);
distanceInCm=timeInMicroseconds /29 /2;
pinMode(10,INPUT);
Serial.println(distanceInCm);
}
delay(100);
}
7
IV Conclusion
• The system is easy to build and customize, making it an ideal tool for educational and
research purposes.
• The system's low cost and simplicity make it an attractive alternative to traditional
7
V References
[1] https://www.arduino.cc/
[2] https://en.wikipedia.org/wiki/Arduino
[3] https://learn.sparkfun.com/tutorials/what-is-an-arduino/all
[4]https://www.learnrobotics.org/blog/ir-sensor-vs-ultrasonic-sensor/#:~:text=Ultrasonic%20sensors%20use%20sound%20waves,big
%20differentiators%20in%20these%20sensors.
8
V
Thank You!