Ultrasonic Sensor Library for Proteus

Hello friends, hope you all are fine and having good health. In today's post, I am going to share an Ultrasonic Sensor Library for Proteus. A few days ago, I posted a tutorial on Arduino Library for Proteus, and today I am going to share the new Ultrasonic Sensor Library for Proteus. Using this library, you can easily interface Ultrasonic Sensors with different Microcontrollers like Arduino, PIC Microcontroller etc.

First of all, let's have a brief introduction to ultrasonic sensor. In an ultrasonic sensor, there are two nodes available, one is the transmitter while the other is the receiver. The transmitter sends an ultrasonic wave and this wave strikes any hindrance present in front of it and then bounces back. This bounced ultrasonic sensor is then captured by the receiver and on the basis of the time taken by this wave to return, the sensor calculates the distance of that obstacle from that sensor.

The Ultrasonic sensor is usually used for detecting the obstacle in the path and also to find the distance between the sensor and the obstacle. The ultrasonic sensor normally used is HC-SR04, which we have designed in this library. Let's get started with Ultrasonic Sensor Library for Proteus, in this library we have used an extra pin on the ultrasonic sensor, which is an analog pin. The voltage on that pin is used to detect how close an object is because it's a simulation and we can't place an actual object in front of the simulated sensor. Moreover, you should also have a look at this Home automation Project using XBee & Arduino, I have used this ultrasonic sensor in that project.

I hope you are going to enjoy this library. This library is designed by our team after a lot of effort, if you have any feedback to improve, please let us know. So, let's get started with Ultrasonic Sensor Library for Proteus and its interfacing with Arduino.

Note:

Ultrasonic Sensor Library For Proteus

  • First of all download this Ultrasonic Sensor Library for Proteus, by clicking on the below button.
Ultrasonic Sensor Library for Proteus
  • In this ultrasonic sensor library for Proteus, you will find three files which are:
    • UltrasonicTEP.IDX
    • UltrasonicTEP.LIB
    • UltrasonicTEP.HEX
  • Now, place these three files in the library folder of your Proteus software.

Note:

  • Now start your Proteus software and in the components list, search for the Ultrasonic sensor and place it in your workspace as shown in the below figure:
  • Now we have our ultrasonic sensor in Proteus but if you run it then it won't work as we haven't yet added any functionality in it.
  • So, in order to add the functionality double click this ultrasonic sensor and open its properties.
  • In properties, select the Program File section and browse to UltrasonicTEP.HEX file and upload it as shown in below figure:
  • Now our ultrasonic sensor is ready to be used.
  • Now let's make a simple example for an ultrasonic sensor, so that you get an idea of how to use it in Proteus.

Ultrasonic Simulation in Proteus

  • After adding the Ultrasonic Sensor Library for Proteus, open your Proteus ISIS software or restart it, if it's already open.
  • Now search for the below components in the Proteus Components Library and add them in your workspace as shown in the below figure.
Components Used
Here's the list of components, which I have used for designing this Proteus Simulation:
Proteus Simulation
  • After adding these components, now design a simulation as shown in the below figure:
  • Now in this example, I am receiving data from Ultrasonic Sensor and then printing this data over Virtual Terminal in Proteus, if you are not much familiar with Virtual Terminal, then read How to use Virtual Terminal in Proteus ISIS.
  • Now open your Arduino software and paste the below code in it and compile it to get the hex file, read Arduino Library for Proteus to know how to get the Arduino Simulation in Proteus.
  • You must also read How to get the hex file from Arduino Software.
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor

void setup()
{
Serial.begin(9600); // Starting Serial Terminal
}

void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);

pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();

delay(100);
}

long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
  • It's quite a simple code and is self-explanatory, if you still got some trouble then ask in the comments and I will reply to them. I have simply used the ping example in Arduino Examples and slightly modified it.
  • After getting the hex file, now upload it to Arduino in Proteus by clicking the properties.
  • Click on the Start button and if everything's gone fine then you will see an output as shown in the below figure:
  • As you can see in the above figure, the virtual terminal is showing distance values, now this value depends on the variable resistance attached to the ultrasonic sensor.
  • As you change the value of the variable resistance, the voltage on that particular pin will also change and on the basis of that, you will get the distance in inches and centimeters on the virtual terminal.
  • Arduino code and hex file along with the Proteus Simulation for this ultrasonic example are attached below. You can download it by clicking on the below button but I would suggest you to design it on your own, it will help you in learning.
  • You should also have a look at these Arduino Projects for Beginners.
Download Code and Proteus Simulation

That's all for today, in the coming post I am gonna share some more examples of how to use ultrasonic sensor in Proteus. Till then take care and have fun.

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir