# A Physical Notifier for AI Coding Assistants: Making Wait States Visible

    Learn how to build a small solenoid-based device that bounces when your AI coding assistant is waiting for input. This guide covers mechanical design, MOSFET driver circuits, non-blocking firmware, serial scripts, and event hook integration.

    When you work with an AI coding assistant in the terminal, it spends most of its time running in the background. You might be waiting for a task to finish or for a permission confirmation, while your attention has already moved elsewhere. By the time you check back, the assistant may have been idle for a long while.

    A straightforward idea is to surface the tool’s working state in a way that takes up no screen space and doesn’t interrupt your train of thought. Desktop notifications get buried under other messages, and status lights are easy to overlook. A small device that physically bounces up and down is far harder to ignore.

    This article walks through a common community approach: a small model connected via USB that bounces once or several times whenever the coding assistant enters its “waiting for user input” state. The engineering chain is not complicated, but each segment has details worth paying attention to.

    Define the Scope First

    The solution described here suits individual developers or small teams building a desktop prototype. It relies on three things: a programming tool that supports event hooks, a computer that can run scripts, and hardware consisting of a microcontroller plus a driver circuit.

    Hook names and configuration formats vary widely between coding assistants. This article does not assume any specific product’s interface and only describes the general chain. When implementing it, refer to the official documentation of your chosen tool.

    Mechanical Design: Selection and Key Points

    The mechanical structure of such a device is common and centers on three components.

    1. Actuator: a solenoid. When energized, the coil generates magnetic force that pushes the armature forward; when power is cut, a spring or gravity returns it. Switching it on and off at low frequency produces the bounce effect. When selecting a solenoid, check both the pull-in current and the holding current. The pull-in current is usually significantly higher than the holding current, and both values must be matched against your power supply’s capability.

    2. Guide mechanism. The solenoid’s reciprocating motion tends to produce lateral wobble, which causes wear and sticking over time. A low-cost solution is a thin stainless steel guide rod passing through a sintered bronze bushing. Bronze bushings are somewhat self-lubricating, and a thin rod with good straightness keeps lateral play small. The fit tolerance between bushing and rod should be set according to your assembly drawings and machining capability: too tight increases friction, too loose allows wobble.

    3. End stops and cushioning. Every impact of the armature against a stop surface generates noise. Adding a rubber or silicone pad to the impact surface noticeably reduces sound and lessens structural damage from repeated impacts.

    For the enclosure, take a phased approach. Print the first version in PLA on a 3D printer to validate the range of motion and assembly fit. Once you’ve confirmed there are no interferences, decide whether to add counterweights to improve the feel. If you want a metal enclosure, CNC-machined aluminum with tolerances set per your assembly clearances works well. For most prototypes, solving the motion path and heat dissipation matters more than chasing premium materials.

    Driver Circuit: GPIO Cannot Drive a Coil Directly

    This is the part where things most often go wrong. A microcontroller’s GPIO pins can only source a small amount of current. Wiring the coil directly to a pin means the pull-in current will damage the pin, and possibly the entire board.

    The correct approach is to control the coil with a switching device. Two common options:

    • Logic-level MOSFET: choose a model that fully turns on at a gate voltage of 3.3V or 5V, and place a small resistor in series with the gate to reduce oscillation.
    • Relay module: simple to drive, but slow to switch with limited contact life; suitable for low-frequency bouncing.

    The coil should be powered by a separate supply with headroom in both voltage and current. The supply ground and the microcontroller ground must be connected together so the control signal has a common reference potential. If the coil shares a single supply with the microcontroller, the current surge at pull-in will drag the voltage down and cause the MCU to reset.

    Wire a flyback diode across the coil terminals in reverse parallel, such as a 1N4007 or equivalent, with a voltage rating above the supply voltage. When the coil is de-energized, it produces a reverse electromotive force; the flyback diode gives that current a path and protects the switching device.

    Long periods of frequent switching heat up the coil and shorten its life. The firmware should enforce a maximum on-time per activation and leave a cooling interval after each bounce sequence. Exact values should follow the duty cycle and temperature rise data in the coil’s datasheet.

    Firmware: Non-Blocking Bounce

    Many example codes use delay() to implement the bounce. That approach blocks the entire program during the bounce, so serial commands can’t be processed promptly. The firmware below uses timestamps for state transitions, letting the main loop keep receiving commands.

    1. const int SOLENOID_PIN = 5;
    2. const unsigned long ON_MS = 80;
    3. const unsigned long OFF_MS = 120;
    4. const unsigned long COOLDOWN_MS = 2000;
    5. int remaining = 0;
    6. bool active = false;
    7. unsigned long lastChange = 0;
    8. unsigned long lastFinished = 0;
    9. String buffer;
    10. void setup() {
    11. pinMode(SOLENOID_PIN, OUTPUT);
    12. digitalWrite(SOLENOID_PIN, LOW);
    13. Serial.begin(9600);
    14. }
    15. void loop() {
    16. while (Serial.available()) {
    17. char c = Serial.read();
    18. if (c == '\n') {
    19. handleCommand(buffer);
    20. buffer = "";
    21. } else if (buffer.length() < 32) {
    22. buffer += c;
    23. }
    24. }
    25. updateBounce();
    26. }
    27. void handleCommand(String cmd) {
    28. cmd.trim();
    29. unsigned long now = millis();
    30. if (cmd == "BOUNCE" && remaining == 0 && now - lastFinished >= COOLDOWN_MS) {
    31. remaining = 3;
    32. active = false;
    33. lastChange = now - OFF_MS;
    34. }
    35. }
    36. void updateBounce() {
    37. if (remaining == 0) return;
    38. unsigned long now = millis();
    39. if (!active && now - lastChange >= OFF_MS) {
    40. digitalWrite(SOLENOID_PIN, HIGH);
    41. active = true;
    42. lastChange = now;
    43. } else if (active && now - lastChange >= ON_MS) {
    44. digitalWrite(SOLENOID_PIN, LOW);
    45. active = false;
    46. remaining--;
    47. lastChange = now;
    48. if (remaining == 0) lastFinished = now;
    49. }
    50. }

    Three design points stand out. First, only fixed commands are accepted; anything else is ignored, and line length is capped. Second, the cooldown prevents the device from being triggered repeatedly in a short time and protects the coil. Third, bounce count and durations are constants, making it easy to tune for different coils.

    Desktop Script: Serial Send and Error Handling

    The desktop script has a simple job: when a hook event fires, send one command over serial, then exit. First install the dependency:

    1. pip install pyserial
    1. import os
    2. import sys
    3. import serial
    4. PORT = os.environ.get("HAPTIC_PORT", "/dev/ttyUSB0") # commonly COM3 on Windows
    5. BAUD = 9600
    6. def send_bounce() -> int:
    7. try:
    8. ser = serial.Serial(PORT, BAUD, timeout=1)
    9. except serial.SerialException as exc:
    10. print(f"Failed to open serial port {PORT}: {exc}", file=sys.stderr)
    11. return 1
    12. try:
    13. ser.write(b"BOUNCE\n")
    14. ser.flush()
    15. return 0
    16. except serial.SerialException as exc:
    17. print(f"Failed to send: {exc}", file=sys.stderr)
    18. return 1
    19. finally:
    20. ser.close()
    21. if __name__ == "__main__":
    22. sys.exit(send_bounce())

    A few practical issues need handling up front:

    • Port name: on Linux it’s usually /dev/ttyUSB0 or /dev/ttyACM0; on Windows it’s a COM number; on macOS it’s a device starting with /dev/tty.usbserial. Set it via the HAPTIC_PORT environment variable instead of hardcoding it in the script.
    • Permissions: on Debian and Ubuntu, serial ports usually belong to the dialout group. After adding your user to the group, log out and back in.
    • Port contention: a serial port can only be opened by one program at a time. If a serial monitor is still running, the script will fail to open the port.
    • Exit promptly: the script must exit quickly. Hooks wait for the script to finish, and a stuck script will slow down the coding assistant.

    Wiring Into Event Hooks

    Event names and configuration fields differ between tools; only the general steps are covered here.

    1. In the tool’s hook configuration, assign a command to the “waiting for user input” event, with the command being a run of the script above.
    2. On Linux or macOS, make the script executable, e.g. chmod +x followed by the script path.
    3. Set a timeout for the script and give up when it’s exceeded. If the hook fails, log it only—never let it block the main task.
    4. Run the script manually once to confirm the device moves before wiring it into the hook.

    Never let the script execute arbitrary content received from hook input. The script sends only a fixed command, so even if hook data is malformed, it cannot turn into arbitrary control of the hardware.

    Troubleshooting Common Failures

    • Device doesn’t move at all: check coil power, whether the MOSFET gate is receiving a signal, and whether grounds are tied together.
    • Weak or unstable action: the supply voltage may be insufficient, especially at pull-in. Try a higher-capacity supply, or power the coil separately from the MCU.
    • MCU resets frequently: the coil current is dragging down the supply voltage. Same fix as above.
    • Loud noise: check that the stop cushions are in place and reduce the bounce frequency.
    • Coil overheating: shorten each on-time, lengthen the cooling interval, or switch to a lower-duty-cycle design.
    • No command received over serial: confirm matching baud rates and check whether another program is holding the port.

    Security and Boundaries

    Disconnect power before wiring, and verify pin assignments, polarity, and diode orientation one by one. For the first power-up, test at a lower voltage to confirm the direction of motion and travel are correct.

    This design’s input comes from a local hook, so the risk is low. But whenever external input can trigger hardware actions, abuse becomes a concern. There was once a case where someone built an SMS-receiving device out of a second-hand printer, only for others to figure out its rate-limiting rules and repeatedly send split long messages. Any such entry point should enforce:

    • Authentication: accept only registered sources.
    • Rate limiting: avoid fixed, predictable thresholds, and limit both per-message length and messages per time window.
    • Circuit breaking and alerting: automatically stop responding to abnormal traffic and notify the administrator.

    Reproduction Checklist

    Before you start, record the following to make reproduction and troubleshooting easier:

    • Microcontroller model and firmware version
    • Driver approach (MOSFET or relay) and its part number
    • Coil specs: rated voltage, pull-in current, holding current
    • Power supply specs: voltage and current headroom
    • Serial parameters: baud rate and port
    • Coding assistant version and the hook event name used
    • Test steps and observed failures

    Conclusion

    This approach delivers value in three areas. Mechanically, the guide, end stops, and manufacturing choices determine whether the device works reliably over the long term. On the software side, event hooks make the tool’s internal state readable by external programs through a clean interface. On the hardware side, driver circuit design is a safety prerequisite that cannot be skipped.

    For developers who want to build this, start with a microcontroller, a solenoid, a MOSFET board, and a hook script. Get the first version bouncing reliably before worrying about the enclosure and aesthetics. That way, “the code is waiting for you” becomes a visible signal on your desk.