First off you will need to start by making the Pin that you select on your 16F877A a logic "LOW" and an output.
Then you will need to make that same pin a logic "HIGH" for about 10us (micro seconds) and then to a logic "LOW"
Immediately following that you will need to make the pin an input and time how long it takes for the pin to go "HIGH" again. <-- This HIGH will be the echo, and the time returned will be an arbitrary value that won't have any "weight" unless you know the precise unit of time (instruction clock speed) of your 16F877A. Keep in mind that this returned time will be the time of flight "there and back". If the pin does not go HIGH, then you will need to make previsions in code for the PING to timeout. This condition simply means that the PING sensor is aiming at something too far away to receive a valid echo response.
A small modification to what Beau said. After the 10µs trigger pulse, turn the pin into an input, and look for the low to high transition, which will occur at about 180µs after the trigger pulse. Then start your timer, and stop it when the pin goes low again. Use the duration high, times the speed of sound, to calculate the distance there and back.
The PING))) itself times out after 20 milliseconds.
I've just been looking at this in another thread. Here are a couple of 'scope shots. Voltage on the pin is the yellow trace #1, and the trigger pulse is enhanced with orange and also shown time-expanded as trace #A. First shot shows a return echo of about 1ms. In the second shot, the PING))) times out at about 20ms, from pointing off into open space. The other thread had to do with how to make it time out sooner, for faster response.
Zeic, Also, welcome to the forum. I edited your thread title. You'll have better luck with responses when the title is descriptive, more than just "hey guys"!
Comments
Welcome to the Forums!!
First off you will need to start by making the Pin that you select on your 16F877A a logic "LOW" and an output.
Then you will need to make that same pin a logic "HIGH" for about 10us (micro seconds) and then to a logic "LOW"
Immediately following that you will need to make the pin an input and time how long it takes for the pin to go "HIGH" again. <-- This HIGH will be the echo, and the time returned will be an arbitrary value that won't have any "weight" unless you know the precise unit of time (instruction clock speed) of your 16F877A. Keep in mind that this returned time will be the time of flight "there and back". If the pin does not go HIGH, then you will need to make previsions in code for the PING to timeout. This condition simply means that the PING sensor is aiming at something too far away to receive a valid echo response.
The PING))) itself times out after 20 milliseconds.
I've just been looking at this in another thread. Here are a couple of 'scope shots. Voltage on the pin is the yellow trace #1, and the trigger pulse is enhanced with orange and also shown time-expanded as trace #A. First shot shows a return echo of about 1ms. In the second shot, the PING))) times out at about 20ms, from pointing off into open space. The other thread had to do with how to make it time out sooner, for faster response.