Electronics TutorialsPROTEUS

How to Simulate HC-SR04 ultrasonic sensor in Proteus

In this tutorial, you will learn how to Simulate HC-SR04 ultrasonic sensor in Proteus with Arduino.

The HC-SR04 is a popular ultrasonic distance sensor that is used in project designs to measure distance. I have used it to design a distance measurement device and also a water level indicator using Arduino. But, do you know you can simulate HC-SR04 ultrasonic sensor in Proteus before carrying out the real design? Watch the video below and see how it is done.

How to Simulate HC-SR04 ultrasonic sensor in Proteus

To carry out this simulation in Proteus, you should have Proteus already installed on your computer system, then add Arduino and ultrasonic sensor libraries to the Proteus library folder, once you have done that, you open Proteus and draw the circuit diagram as shown below.

What is Proteus?

According to Wikipedia, the Proteus Design Suite is a proprietary software tool suite used primarily for electronic design automation. The software is used mainly by electronic design engineers and technicians to create schematics and electronic prints for manufacturing printed circuit boards.

There are various Proteus versions, which includes, but not limited to the following, versions listed below. If you visit the Labcenter Electronics website, you can do the following:
Download Proteus 8.12Proteus 8.11, Proteus 8.10, Proteus 8.9, Proteus 8.8, Proteus 8.7, Proteus 8, etc.

Where to download Proteus

If you do not have Proteus already installed on your computer, do not worry, I have already made a tutorial and how to download and install Proteus 8.11. I also have written tutorial that will guide you to installing the software perfectly together with all the Proteus Arduino libraries without any glitch.

Circuit diagram for the HC-SR04 Ultrasonic sensor simulation

Simulate HC-SR04 ultrasonic sensor
HC-SR04 simulation on proteus

You must make sure that the virtual terminal has same baud rate as the Arduino code as explained in the video, to see how to do that and how to upload the Arduino code to the virtual Arduino used in the Proteus simulation watch the video above. The Arduino code for the simulation is shown below.

Arduino code for the simulation

// defines pins numbers
const int trigPin = 10; // pin on the arduinowhere the trigger pin is connected
const int echoPin = 9;// pin on the arduino where the echo pin is connected

// defines variables
long duration; // variable where the the reflection time of the ultrasound is stored
int distance; // variable where the distance of the measured object is stored

void setup()
         pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
           pinMode(echoPin, INPUT); // Sets the echoPin as an Input
         Serial.begin(9600); // Starts the serial communication
     void loop()
// Clears the trigPin
digitalWrite(trigPin, LOW);
     // Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
     digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
   duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;

// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
delay (100);


You can as well check out other nice Proteus simulation videos like:
how to simulate a step-down transformer
how to simulate Arduino on Proteus.

Leave a Reply

Your email address will not be published. Required fields are marked *