HC-SR04 pulse-length specific interrupt possible?

Hi all, I'm aware the forum is littered with questions about the HC-SR04 however I can't find any about my specific question.

I am aware of how to use interrupts for TRIG output and timing the ECHO, however, I was wondering if it was at all possible to trigger an interrupt when ECHO <= a certain value? I'm working on a battery-powered project and I would ideally rather not have the main loop constantly sample an IF statement (eg if(time<=50ms){dosomething() ; ) to reduce processing load and extend battery life. In an ideal world, I would keep the main loop empty and only take action upon interrupt. I'm not confident this is possible and would appreciate anyone advice/experience.

Thank you!

No. Echo calculations require processor intervention. Are you putting the processor to sleep to save power?

I am. I was previously using a PIR sensor however I needed something with a shorter range. Previously I slept my Arduino Nano until the PIR triggered an interrupt; but in this case, I would have to continuously be waking the processor up every time I send out a pulse which would realistically be every 100ms or so; so there's not much value in sleeping in this case. I may just have to take the hit on the battery life in this case and just run IF logic inside the main loop.

Why? the duty cycle at 100ms would be extremely low. Keep in mind, however you do it, the ultrasonic transducer itself uses a fair bit of pulse current because it has a small power amplifier circuit to drive the transmitter.

I've just checked the datasheet and you're completely right, a 20ms measurement cycle is realistic so at a 200ms sample rate that's a good sleep/wake ratio. While not as good as an interrupt, if there's no clever workaround for the interrupt, that's a good compromise. Thanks!

Seems like a low power external timer (CMOS 555?) and a logic chip or two could be put together to trigger the HC-SR04 every "x" ms and then trigger an Arduino interrupt if an echo was received in less than "y" ms after the HC was triggered.

External hardware to do that is pointless, the MCU has the ability to set a wake timer itself. Hardware to monitor the echo pin is pointless because the HC-SR04 consumes much more current than the processor has to consume, while it is ranging.

The trigger and echo events require that the MCU timer is running between them, or else there is no way to obtain the microseconds delay value. The hardware you describe, could not provide that. It would only provide a threshold set by analog timing.

Also while the hardware would terminate a measurement cycle from the point of view of the driving circuit, the HC-SR04 doesn't know about that and would complete the entire measurement cycle, using its full current consumption.

It's possible, with external hardware. Pulse Trigger every 500 milliseconds with an astable multivibrator. Then have the rising edge of Echo trigger a one-shot timer for your "certain value". If Echo goes low before the one-shot goes low, interrupt.

You could also write your own firmware for the HC-SR04 MCU.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.