Make your own distance measuring equipment using an ultrasonic sensor and an LCD. Here we use wokwi Arduino simulator
You can easily measure the distance between an object and the Arduino using an ultrasonic sensor. this project uses ultrasonic sensor and
The Ultrasonic sensor uses the shout and listens to the method. it transmits the signal and monitors the time it took to reach back. by using this principle, you can measure distance, diameter, depth and various linear parameters.
The ultrasonic sensor (or transducer) works on the same principles as a radar system. An ultrasonic sensor can convert electrical energy into acoustic waves and vice versa. The acoustic wave signal is an ultrasonic wave travelling at a frequency above 18kHz. The famous HC SR04 ultrasonic sensor generates ultrasonic waves at 40kHz frequency.
Typically, a microcontroller is used for communication with an ultrasonic sensor. To begin measuring the distance, the microcontroller sends a trigger signal to the ultrasonic sensor. The duty cycle of this trigger signal is 10ÂµS for the HC-SR04 ultrasonic sensor. When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts and initiates a time counter. As soon as the reflected (echo) signal is received, the timer stops. The output of the ultrasonic sensor is a high pulse with the same duration as the time difference between transmitted ultrasonic bursts and the received echo signal.
Project source: https://wokwi.com/arduino/projects/290043622233997832
Wokwi Arduino Simulator - Ultrasonic sensor and LCD
Connection diagram for the ultrasonic sensor with Arduino and an LCD display. Please leave a comment if you have any doubts.
Hint: You can also look at the code to understand the connections as well ;)
The complete code for the project is given below
// Compatible with the Arduino IDE 1.0
// Library version:1.1
// set the LCD address to 0x27 for a 16 chars and 2 line display
long readUltrasonicDistance(int triggerPin, int echoPin)
pinMode(triggerPin, OUTPUT); // Clear the trigger
// Sets the trigger pin to HIGH state for 10 microseconds
// Reads the echo pin, and returns
// the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.print("--> Distance <--");
cm = 0.0344/2 * readUltrasonicDistance(3, 2);
inches = (cm / 2.54);
If you have any questions please leave a comment or hop on to Discord server to meet a welcoming group :)
Please visit the Electrotantra YouTube channel for more videos on the Arduino and Raspberry Pi Pico simulators.