DaveX
July 28, 2024, 12:08am
10
You could wire all the triggers to the same pin and read one with the library and read the durations of the other echoes directly with micros(). You’d need to disable the emitters on the other sensors
One doesn't need any interrupts at all. Here's a simulation that shows that an Arduino/Nano can be fast enough to read an HC-SR04 with plain old state machine and state change detection coding:
[image]
/*
HC-SR04 Ultrasonic sensor with plain, non-blocking state-machine coding
https://wokwi.com/projects/404439179947636737
This code blinks the trigger pin periodically,
records the time of the falling edge of the trigger, and the flight time of the echo.
*/
/*
Uno with Scope http…
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!