![]() ![]() The period is 25 μs.įor my liquid level sensor arrangement the front of the HC-SR04 is 75 mm from the ground, giving an expected time of 441 μs. Given the speed of sound is 340 ms −1, sound takes roughly 3 μs per millimetre double that to allow for going there and back. In other words the output is not a monotonic function of distance. Monotonicity turns out to be a big problem - as the target distance increases the HC-SR04 output does not always increase. The HC-SR04 is triggered by the amplitude of the pulse coming back, making no allowance for the phase of echoes or lost ones.The processor in the HC-SR04 polls the analogue electronics.in the NewPing library), this has a resolution of 4 μs. Use of the Arduino micros() function to measure microseconds (e.g.The usual claim vendors make for the HC-SR04 is an accuracy of 3 mm. To start with I'm repeating material from that page. There is a very good web page Making a better HC-SR04 Echo Locator which covers a great deal including limitations. There's a lot of space around the sensor with nothing in it so there are no echoes from other objects. The HC-SR04 is positioned looking down vertically at the floor/water - it fires a pulse of sound and waits for the echo. The liquid level sensor is built around a "bare bones Arduino", roughly equivalent to an Uno, Pro Mini or other ATMega 328p based Arduino, so that's the processor I have to work with. The result of all this is that a modified HC-SR04 can measure tiny distances.Ī newer project is a liquid level sensor using a laser time of flight sensor. My aim is a quick response to level changes and an accuracy of 1 mm. Possibly that is unusual for a user of the HC-SR04 and for depth of under floor water. I am interested in a sensor to target distance around 100 mm and changes of that distance always less than 25 mm. This type of sensor did not work perfectly with the dirty water, eventually I replaced it with an ultrasonic ranging module, the HC-SR04. I built a liquid level sensor using a capacitive sensor to monitor the water level in the crawl space under my house. Lcd.For schematics see (external links) Making a better HC-SR04 Echo Locator and Circuit Diagram Ultrasonic Distance Sensor HC-SR04.Ī new development is the HCSR04 P variant. 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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |