r/arduino • • Oct 22 '26

Microcontroller Driven SR04 Actuator (PID)

My youtube channel is ALMA Industries

This is a short demo of an actuator I put together (on my channel, video is titled CH003 FN1: ACTUATOR). The actuator is first sketched out, 3D printed in pieces, assembled together, and controlled via PID running on a microcontroller. Ultrasonic distance sensor is included in the close-loop feedback system to prevent the actuator from running into the ceiling (shown in the second half of the clip, and discussed more in the full video).

There are a few modes. The first is 'don't touch the ceiling' (Ultrasonic Distance Sensor to keep a distance from the wall, hand, etc). The second is to have the actuator distance sensor follow a second distance sensor...so when one goes up the other follows going up, and when one down the other down.

Comments, questions, or new ideas are welcome.

8 Upvotes

6 comments sorted by

3

u/Civil_Firefighter832 Oct 22 '26

Nice closed-loop demo. Question on the SR04 in the loop: it updates at maybe 20-30 Hz with real multipath noise off angled surfaces, so are you filtering it (median of 3-5 pings or a low-pass) before the PID sees it? And how do you handle its blind zone below about 2 cm - does the controller saturate if the target gets that close? A slew-rate limit on the setpoint is a cheap way to kill overshoot if you're not already doing it. The follow mode with two sensors is a neat idea; cross-mounting them at slight angles would tell you whether the echoes interfere.

1

u/ALMA_x11 Oct 23 '26

Thanks man, appreciate the comment.

Would you believe me if I said this is the raw signal without any filter? I initially did all kinds of averaging, running average, etc. Which wasn't trivial as I wanted the averaging to be in a compact for-loop type setup (and each one has to wait for sending out and receiving data over time t). Turns out even when I got it working, the raw signal was totally fine with almost no noise and no averaging was needed. I thought maybe filtering out outliers would be needed--nope, just not needed. Works really well. Stable feedback signal.

When two SR04's are next to each other, I didn't have issue with one affecting the other (unless like they are right next to each other.... then if in same direction got some messed up signals as maybe the sound wave of one goes in the other). But normal distances from each other seemed to be totally fine (maybe 1 to 2-feet apart no issues).

Not sure what you mean on the 2cm thing--like are you saying if like 2cm from the surface can it still get a reading? Not sure if that is the question, but if it is.... I always say be about 10cm away from the object ;)

2

u/Civil_Firefighter832 23d ago

On the 2cm thing - I meant the sensor's rated minimum range. The HC-SR04 datasheet lists a measuring range of 2cm to 400cm: https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf. Your 10cm minimum is within that range.

1

u/ALMA_x11 23d ago

Got it, yeah I guess it really depends on the application. For my purposes 10cm is perfectly fine. If under 2cm… time to spend some money I guess for something that does mm’s :)

2

u/Civil_Firefighter832 22d ago

Yeah, for a ceiling-avoidance setup 10cm is plenty. If you ever need the sub-2cm range, one option is ST's VL53L0X - a time-of-flight laser-ranging module that measures absolute range up to 2m: https://www.st.com/en/imaging-and-photonics-solutions/vl53l0x.html

1

u/ALMA_x11 22d ago

Thanks for the recommendation. I’ll check that out for sure. Sub 2cm but max 2m. That sounds pretty cool. Looks like it’s an i2c device too so addressable. That might cause issue in some applications but for ease of use that could be pretty cool. Thanks for sharing!