![]() |
Sensors are widely used for detecting devices by approximating their distance from the source. One such example of a sensor is the HC-SR04 ultrasonic sensor which uses the SONAR technique for the sensing purpose. The main feature of this sensor is to mimic the nature of bats and therefore predict the distance of objects without actually establishing contact with the device. In this article, we will study how to design this ultrasonic sensor using the Arduino board and programming software. We will study the specifications needed for this sensor, and the methods and circuit diagrams used for designing this sensor. In addition to this, we will see the Arduino code written on IDE that will result in a sensor. Table of Content What is an Ultrasonic Sensor?Similar to any other sensor, the Arduino Ultrasonic Sensor is used to sense the presence of any object and predict the distance of the object in appropriate units which is inches in this case. Therefore, we can define the Arduino Ultrasonic Sensor as a device that uses the ultrasonic sensing technique to estimate the distance of an object. Arduino is used for creating this sensor since it needs to be programmed to detect the reflected rays from objects and display the distance in the desired format. Technical SpecificationsBefore getting started with the sensor, we need to mention some specifications of the sensor that can ensure proper working conditions for the sensor.
ApparatusApparatus refers to the components that are needed for the project. The components required for designing a sensor using Arduino include.
These devices are easily available at nearby electronics shops. Working of the Ultrasonic SensorThe Ultrasonic Sensor works on the principle of reflection, let us see how
Given Below is the Ultrasonic Sensor ![]() Working of sensor Principle: If you carefully look at the diagram above, you will see that there is a transmitter. This component is responsible for emitting waves of an appropriate frequency that can travel far i.e. it should be able to transmit the ultrasound. Once the ultrasound waves are emitted, they continue a straight line path until they find an object. As shown in the figure, when the ultrasound waves are blocked by any object, the waves reflect. The receiver is present to receive the incoming waves after reflection. Once the reflected wave is received, we note the time taken by the waves to detect the object and predict the distance using this formula.
Note that the factor ‘2’ appears because the time noted is for the period when the wave strikes the object and then comes back. Circuit DiagramHere is the circuit diagram for making connections. Circuit DiagramGiven Below is the circuit diagram of ![]() Circuit Connections Carefully observe the diagram given above for making connections on the breadboard. Note that the ultrasonic sensor has four terminals namely +5V, Trigger, Echo, and GND, follow the steps given for making connections:
Arduino CodeHere is the pseudocode and code for making an ultrasonic Sensor using Arduino. PseudocodeFirstly, we need to initialize the constants that denote the pins to be used.
We will set PINs 8 and 9 as trigger pins and echo pins respectively.
We need to set up the Arduino in the setup() function by determining the starting terminal.
Then we set which pin will be used for output and use digitalWrite() to ensure that the pin is low first.
We will introduce a delay of 2 milliseconds using the delay() function.
We will set which pin will be used for input using the digitalWrite() function with another delay of 10 milliseconds.
We create two functions microsecondsToInches() and microsecondsToCentimeters() to give the distance at which the object is present. The parameter of this function will be the time at which the object was sensed. Code
ConclusionOnce you have uploaded this code on Arduino, the sensor will begin working. The Arduino will successfully display the distance measured by a sensor in inches and cm. It will appear on the computer screen depending on the function that you use. The sensor will work accurately in different conditions like sunlight but it might not detect certain light items. You can make further modifications to improve the project according to your needs by incorporating some advanced boards.
|
Reffered: https://www.geeksforgeeks.org
Arduino |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |