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
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.