What is PIND?
Topic: What is PIND?
(Read 668 times)
The last thing you did is where you should start looking.
Re: What is PIND?
Dec 06, 2014, 12:19 am
: Dec 06, 2014, 12:27 am by LarryD
After the trigger pulse has occurred, your "while loop" will not immediately find the rising edge of the ECHO pulse since it takes 460uS for this to occur.
In your sketch, the last instruction in loop() is, delay(500) or 1/2 second, which freezes the controller.
When the delay is over you have missed the pulse entirely.
In electronics, you must pay attention to timing.
You must realize that while you are doing one thing the other thing may have come and gone.
Obliviously, the way around this is to use my sketch, or perhaps even better, use an interrupt technique to capture the edge changes of a pulse. You can use pin 2 or 3 on an UNO for the interrupt.
You have to trigger the sensor, look for the rising edge to the ECHO pulse, when you find it, start a timer, then look for the falling edge of the ECHO pulse, when you find it, use the time between the two edges for the distance.
Of course, using the PulseIn function works too.
The way you have it in your schematic isn't the same as how you have it wired up!