Overview
This is a small differential-drive robot built around an Arduino and an L298N dual H-bridge motor driver, designed to autonomously navigate a desk surface and vacuum up debris. The robot drives forward continuously until a downward-facing HC-SR04 ultrasonic sensor detects an edge closer than 10 inches, then stops, reverses for 1.5 seconds, and pivots a random amount before continuing. A second ultrasonic sensor mounted at the front acts as a touchless toggle — waving a hand within 10 cm starts or stops a 2-minute cleaning cycle.
Battery voltage is monitored through a 2.7 kΩ / 1 kΩ resistor divider on the Arduino's analog input and displayed on a 16×2 I2C LCD alongside a countdown timer during operation. The fan is driven through a MOSFET and only powered when the robot is actively moving forward, which extends battery life since suction is unnecessary during reversing and turning maneuvers.
Design decisions
Ultrasonic edge detection
Using an HC-SR04 ultrasonic sensor for edge detection gives a real distance measurement rather than a binary near/far signal from IR. The threshold is set to 10 inches, which provides enough reaction time for the motors to stop before the robot reaches the edge regardless of surface color or lighting — both of which can throw off IR reflectance sensors.
Random-bounce navigation
The navigation algorithm is deliberately simple: go straight until hitting a boundary, then reverse and turn. The turn duration is randomized between 1100 and 1300 ms using Arduino's random() seeded from a floating analog pin, which prevents the robot from tracing the same path repeatedly. The right motor runs at 0.975× the commanded speed to compensate for a small torque mismatch between the two motors that would otherwise cause the robot to drift in a curve during straight-line motion.
Touchless wave-to-activate toggle
A dedicated HC-SR04 sensor handles activation instead of a physical button. The firmware uses rising-edge detection on the proximity signal — a single wave within 10 cm toggles the robot on or off, while sustained proximity does nothing after the initial trigger. This lets the robot be started and stopped without touching it while it's running on a desk that may have work spread across it.
Fan gating
The suction fan is MOSFET-switched and only enabled while the robot is moving forward. During reversing and turning — which together account for roughly 30–40% of active time — the fan is off. In the final three seconds of the run cycle, the motors stop but the fan stays on at full speed to clear any debris that was just reached, then everything shuts down together.