Skip to main content

Posts

Showing posts with the label PING

Arduino: Ultrasonic sensor

One of the easiest methods to measure distances in an embedded project is to use an ultrasonic sensor. They provide sufficient accuracy to most applications.It is exceptionally useful in robotics as well. So how do we interface ultrasonic sensors with arduino? It`s fairly simple. let`s briefly look how it works.Ultrasonic sensor consists of a transmitter and receiver The transmitter emits ultrasonic pulse for short duration and waits for the echo pulse on the receiver. The time delay is a measure of the distance from sensor to the object.Roughly we could assume sound waves travels at the rate of 1cm per 29 microseconds. first we have to pull the trigger pin high for a short duration say 10us.Then wait till the receiver gets the echo pulse.If your sensor is PWM type (common type like parallax PING)) ) we get a pulse whose width corresponds to delay of the ultrasound pulse.All we have to do is to calculate the pulse duration and print suitably, here is the sample code, //