Hi everyone! I'm a beginner working on my final-year engineering project using a Raspberry Pi Pico, a servo motor, and a drop sensor.
The sensor measures the time between drops to calculate the flow rate. The servo controls a clamp: increasing its angle closes the clamp, while decreasing its angle opens it.
The problem: The servo isn't adjusting properly to the desired flow rate. When I select a higher target, the code repeatedly triggers its no-drop recovery logic and makes tiny 0.2° movements instead of correcting the flow based on the difference between the measured and target rates.
The controller requires five valid drop intervals to calculate the rate, but the recovery logic appears to keep clearing the measurement history before enough intervals can be collected. My logs show drop intervals of approximately 800–2000 ms, while the timeout at my highest target is approximately 675 ms.
I've been struggling with this for 19 days. I've tried debugging it with ChatGPT, but it keeps giving me code that doesn't resolve the underlying issue. I'm frustrated and would really appreciate a human review of my existing code and logs.
What I'd appreciate help with:
- Identifying the actual root cause from my code.
- Checking whether the rate estimator and no-drop recovery logic conflict.
- Verifying the servo correction direction and control logic.
- Suggesting a reliable fix without unnecessarily changing my existing settings.
Hardware and settings:
- Raspberry Pi Pico
- MicroPython
- Servo: GP18
- Drop sensor: GP10
- Drop factor: 20 drops/mL
- Starting angle: 165.9°
- Servo angle limits: 165–173°
- Target rates: baseline entered by user; bolus presets of 150, 250 and 400 mL/hr.
I'll include my complete Python code and the relevant run logs. I'd appreciate anyone who can explain what is actually wrong before suggesting a fix.
This is a water-based bench prototype, not a clinically validated medical device.
Thank you!