The Ultrasonic Sensor also called “Ping Sensor” is used to detect the objects in front and measure the distance between the sensor and the object. In this post, I will show you how you can simulate an ultrasonic sensor in Proteus and how to use it to measure the distance. But first, let’s see how to add and simulate the Ultrasonic Sensor library in Proteus.
How to add Ultrasonic Sensor Library to Proteus?
You can also watch this video for easy reference:
STEP 1: First of all download Ultrasonic Library from the link given below:
**Don’t have an Arduino library? Click here to download that library.
STEP 2: Download the file to the desktop
STEP 3: Unzip the .zip file to the desktop
STEP 4: You will obtain these three files:
(A) 1.UltrasonicTEP.LIB
2.UltrasonicTEP.IDX
(B) 3.UltraSonicTEP.HEX
STEP 5: Copy the first two files and paste them in:
“C:\Program Files (x86)\Labcenter Electronics\Proteus 7 Professional\LIBRARY“
Next Copy the “.HEX” file and paste it in:
“C:\Program Files (x86)\Labcenter Electronics\Proteus 7 Professional\BIN“
STEP 6: Open proteus and click on “pick from libraries”
STEP 7: Search for “ultrasonic” in the components tab. You will see “ultrasonic sensor“. Select it and then place it anywhere on the front panel!
STEP 8: Double-click on the sensor and then click on the “Ultrasonic sensor.HEX” as shown in the figure BELOW.

STEP 9: Select “UltraSonicTEP.HEX” file from BIN and hit enter as shown in the figure below.

STEP 10: Now you are good to go! You can Start simulating Ultrasonic Sensor right away.
Simulate Ultrasonic Sensor with Arduino in Proteus:
Before going further be sure to check out ” How to add and simulate Arduino in Proteus?“
Distance Measurement Project using Ultrasonic Sensor in Proteus:
STEP 1: Connect all the components as shown in the simulation figure below.

STEP 2: Download this “UltraSonic” program to your Arduino IDE:
const int echoPin = 2; // Echo Pin of Ultrasonic Sensor const int pingPin = 3; // Trigger Pin of Ultrasonic Sensor void setup() { Serial.begin(9600); // Starting Serial Communication pinMode(pingPin, OUTPUT); // initialising pin 3 as output pinMode(echoPin, INPUT); // initialising pin 2 as input } void loop() { long duration, inches, cm; digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(10); digitalWrite(pingPin, LOW); duration = pulseIn(echoPin, HIGH); // using pulsin function to determine total time inches = microsecondsToInches(duration); // calling method cm = microsecondsToCentimeters(duration); // calling method Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); } long microsecondsToInches(long microseconds) // method to covert microsec to inches { return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) // method to covert microsec to centimeters { return microseconds / 29 / 2; }
STEP 3: Go to preferences

STEP 4: Check “Compilation” CheckBox

STEP 5: Click on verify (compile)


STEP 6: After compilation is complete copy the HEX file path from the bottom corner:
STEP 7: Open Proteus and double click on Arduino. Paste the file path and click ok

STEP 8: Double-click on the sensor and then click on the Ultrasonic sensor.HEX as shown in the figure.

STEP 9: Select “UltraSonicTEP.HEX” file from BIN and hit enter as shown in figure.

STEP 10: Run the simulation! Change the potentiometer’s wiper terminal position to test the distance value on the virtual terminal. As you can see in the picture below, the value of the distance gets printed on the serial monitor.

Read Similar Articles:
How To Change Frequency On PWM Pins Of Arduino UNO
How to Add Microphone library to Proteus and generate audio waveforms
How to add Arduino Library to Proteus and Simulate Arduino Projects
I got proteus 8.7 SP1 pro (legal) and try to simulate, I got this error :
mixed model PIC16EX.DLL failed to authorize – Product Key not found. [SONAR1]
Do you know tis error, can you help me
Thank you
Is this happening to every simulation file or just any particular??
Such a good article!