

On the other hand, if an object is made out of a material that absorbs sound or is shaped in such a way that it reflects the sound waves away from the receiver, readings will be unreliable. In fact, they’re unaffected by the color of the material they are sensing. While radar and ultrasonic sensors can be used for some of the same purposes, sound-based sensors are readily available-they can be had for just a couple dollars in some cases-and in certain situations, they may detect objects more effectively than radar.įor instance, while radar, or even light-based sensors, have a difficult time correctly processing clear plastic, ultrasonic sensors have no problem with this. This type of sensor can be manufactured in a smaller package than with separate elements, which is convenient for applications where size is at a premium. While some sensors use a separate sound emitter and receiver, it’s also possible to combine these into one package device, having an ultrasonic element alternate between emitting and receiving signals. This is similar to how radar measures the time it takes a radio wave to return after hitting an object. They then wait for the sound to be reflected back, calculating distance based on the time required. Ultrasonic sensors work by emitting sound waves at a frequency too high for humans to hear. Ultrasonic sensors How Does an Ultrasonic Sensor Work?.Light detection (infrared sensors, light-dependent resistors, and computer vision setups).LcdBarGraph lbg(&lcd, 16, 0, 1) // Creates an LCD Bargraph object. #include // Maximum distance we want to ping for (in centimeters).

#include // includes the LcdBarGraph Library The following table lists the pin connections: Now connect the trig and echo pins to digital pins #9 and #10 respectively. Connect the VCC pin to the 5V pin on the Arduino and the GND pin to the ground pin. Start by placing the sensor on your breadboard. Now that we have a complete understanding of how the HC-SR04 ultrasonic sensor works we can start connecting it to our Arduino!Ĭonnecting the HC-SR04 to Arduino is very easy. Now we know that the object is 8.5 cm away from the sensor. So to get the distance, you have to divide your result by two. With that information we can now calculate the distance!īut we’re not done yet! Remember that the echo pulse indicates the time it takes for the signal to be sent and reflected back. To calculate the distance we need to convert the speed of sound into cm/µs. Of course it’s the speed of sound! It is 340 m/s. Now let’s calculate how far the object is from the sensor. Suppose we have an object in front of the sensor at an unknown distance and we receive a pulse of 500µs width on the echo pin. Let us take an example to make it more clear. Thus a pulse of 38ms indicates no obstruction within the range of the sensor. If those pulses are not reflected back, the echo signal times out and goes low after 38ms (38 milliseconds). Meanwhile the echo pin goes HIGH to initiate the echo-back signal. These eight ultrasonic pulses travel through the air away from the transmitter. This 8-pulse pattern is specially designed so that the receiver can distinguish the transmitted pulses from ambient ultrasonic noise. In response, the sensor transmits an ultrasonic burst of eight pulses at 40 kHz. It all starts when the trigger pin is set HIGH for 10µs. How Does HC-SR04 Ultrasonic Distance Sensor Work? By measuring the time the Echo pin stays high, the distance can be calculated. By setting this pin to HIGH for 10µs, the sensor initiates an ultrasonic burst.Įcho pin goes high when the ultrasonic burst is transmitted and remains high until the sensor receives an echo, after which it goes low.

Trig (Trigger) pin is used to trigger ultrasonic sound pulses. You can connect it to the 5V output from your Arduino. VCC supplies power to the HC-SR04 ultrasonic sensor.
