1

I want to connect multiple Ultrasonic sensors to my Arduino board. For that, I need multiple pulseIn() functions to work at the same time. How can I do that?

1 Answer 1

3

You can't. pulseIn() is a blocking function that waits for a pulse to arrive before returning.

Instead you will either have to use interrupts or (where available) Input Capture peripherals.

However, using multiple ultrasonic sensors at the same may not make sense. Unless you take great care with your physical design you will get interference between the two. Echoes from one bouncing around will trigger the other. For this reason it is normal to not trigger both at once, but to use them sequentially, in which case pulseIn() is still perfectly fine to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.