Hello folks, in this tutorial you will be learning how to make a parking sensor via proximity sensor HC-SR04 and a buzzer.
What is and how does a proximity sensor work?Our friend Bat is very hungry and wants to eat Bug. But there is a little problem: the night has come and the land is dark, and the moon is the only light it sees ♪♫ (thank you Ben E. King). Or better: our Bat sees very little and very badly.
Its solution is using ultrasounds with a wavelength like Bug. So, when ultrasounds meet Bug they will reflect and return to Bat which can easily calculate the distance and direction where find Bug and... eat it.
Indeed, the echo occurs when a sound meets an object of dimensions similar to its wavelength.
But I'm not a scientist!You have only to know that the sound speed (in the air) is about 343 m/s. But we would like to use centimetres and microseconds. So we have to multiply the distance by 100 and divide (time is in the denominator) by 1 million. Eventually, to convert the speed, you have just to divide the sound speed by 10,000.
All this to explain line 17 of the code (and its remark), when you read:
// Definition of sound speed (centimetres / microsecond)
#define c 0.0343
The sensor detects obstacles up to 15° from its viewing point and up to 4 meters away.
In the code, each single acquisition is sent through the serial port (useful for testing), while an acoustic signal is activated when the obstacle is closer than 100 cm (as declared in beep_start
constant). At this point the acoustic signals have an interval (in milliseconds) equal to the distance (in centimetres) multiplied by 4.
This means that at a distance of one meter, there will be an acoustic signal every 400 milliseconds, at half a meter, every 200 milliseconds, and so on, until the minimum distance is reached (in the code set to 5 cm, as declared in min_distance
constant), at which point the sound will be continuous.
Let uncle Albert explain to you how the project works in this short video.
Comments
Please log in or sign up to comment.