Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Build a Safe Low Speed AI Driving Demo on a Closed Course

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through building a safe, low-speed AI driving demo on a closed course. You'll create a small vehicle (or use a simulated one) that follows a lane or path using simple sensors and a control algorithm. The focus is on safety, simplicity, and practical steps you can complete in a weekend.

What You'll Need

  • A small vehicle platform: a 1/10 or 1/16 scale RC car chassis, or a custom-built robot with two driven wheels and a caster.
  • A microcontroller or single-board computer: Arduino, Raspberry Pi, or similar with PWM outputs for motor control.
  • Motor driver (e.g., L298N, TB6612) and batteries (LiPo or AA pack) with appropriate voltage for your motors.
  • Distance sensors: 2-3 ultrasonic (HC-SR04) or IR sensors mounted on the front/sides, or a single camera if using a Pi.
  • Optional: wheel encoders for speed measurement, a buzzer for warnings, and an emergency stop button.
  • Closed course: a flat, open area (parking lot, gym floor) with clear boundaries (cones, tape) and no pedestrians or obstacles.
  • Software: Arduino IDE or Python with OpenCV (if using camera), plus a simple control loop.

Step-by-Step

  1. Design the course. Choose a flat, dry, obstacle-free area at least 10x10 meters. Mark a simple loop with cones or tape, leaving at least 1 meter of clearance on each side. Ensure the surface is not slippery and there is no traffic.
  2. Assemble the vehicle. Mount the motor driver, microcontroller, and sensors securely. Connect motors to the driver, and the driver to the microcontroller's PWM pins. Power the logic and motors separately if possible to avoid brownouts.
  3. Calibrate the sensors. For ultrasonic sensors, test the distance readings against known distances (e.g., 20 cm, 50 cm). Adjust the trigger/echo pins and ensure readings are stable. For IR sensors, adjust sensitivity so they detect the course boundary at the desired distance.
  4. Write the control loop. Start with a simple proportional controller: read the distance to the left and right boundaries. If the vehicle drifts left, turn right, and vice versa. Use a formula like: steering = (right_distance - left_distance) * gain. Keep the gain low to avoid oscillation.
  5. Set speed limits. In code, cap the motor PWM output to a safe maximum (e.g., 30% of full speed) to keep the vehicle under 1 m/s. Use a low speed initially, then increase gradually.
  6. Add an emergency stop. Implement a physical kill switch (e.g., a push button that cuts motor power) and a software timeout that stops the vehicle if no sensor reading updates for 500 ms.
  7. Test without power. Push the vehicle along the course manually to verify sensor placement and that the control logic would respond correctly (you can simulate by moving objects in front of sensors).
  8. Run the first powered test. Place the vehicle at the start, enable the kill switch, and run at the lowest speed. Monitor the serial output for sensor values and steering commands. Be ready to hit the kill switch.
  9. Tune the controller. If the vehicle oscillates, reduce the gain. If it hits the boundary, increase the gain or reduce speed. Adjust sensor mounting angles if needed.
  10. Document and repeat. Record the final parameters (gain, speed, sensor thresholds) and run multiple laps to ensure consistency. Add a buzzer to alert when the vehicle is close to a boundary.

Common Mistakes

  • Sensor misalignment: Ultrasonic sensors have a narrow beam; if they point too far outward, they miss the boundary. Test the field of view.
  • Too high gain: A high proportional gain causes the vehicle to zigzag. Start with a small gain (e.g., 0.5) and increase slowly.
  • Ignoring battery voltage: As batteries drain, motor speed drops, and the controller may become unstable. Use a voltage regulator or monitor battery level.
  • Not securing wires: Loose wires can get caught in wheels or cause intermittent sensor readings. Use zip ties or cable management.
  • Skipping the manual test: Jumping straight to powered runs can damage the vehicle or cause accidents. Always test the logic manually first.

Tips

  • Use a foam bumper around the vehicle to minimize damage on impact.
  • Place the sensors at the height of the course boundaries (e.g., cones) to ensure they detect them.
  • Log sensor data to an SD card or serial plotter to visualize the vehicle's behavior.
  • Start with a straight line course before attempting curves.
  • Have a second person as a spotter to watch for unexpected issues.

Troubleshooting

  • Vehicle doesn't move: Check motor connections, power supply, and PWM pins. Ensure the motor driver is enabled (often an EN pin).
  • Vehicle spins in circles: One motor may be wired backwards. Swap the motor leads or invert the PWM direction in code.
  • Sensors give erratic readings: Check for loose connections, power noise, or reflective surfaces. Add a capacitor across the power pins.
  • Vehicle oscillates: Reduce the gain, increase the distance between sensors, or add a low-pass filter to the sensor readings.
  • Vehicle drifts off course: Calibrate the sensors again, check for wheel misalignment, and ensure the surface is level.

Frequently Asked Questions

Do I need a camera for this demo?

No, a camera is optional. Ultrasonic or IR sensors are simpler and cheaper for a low-speed demo. A camera adds complexity but allows for more advanced lane detection.

What is the safest maximum speed?

Keep the vehicle under 1 m/s (3.6 km/h) for indoor demos. At this speed, you have time to react and the vehicle can stop within a few centimeters.

Can I use a remote control to override the AI?

Yes, you can add a manual override using an RC receiver or a Bluetooth module. This is a good safety feature for testing.

How do I handle intersections or sharp turns?

For a simple loop, avoid sharp turns by designing the course with wide curves. If you must have turns, place sensors on the side that will detect the boundary earlier.

What if my vehicle is too fast even at minimum PWM?

Use a lower voltage battery, add gear reduction, or set a PWM limit in code (e.g., max 100 out of 255).

Is it okay to test on a public sidewalk?

No, use only a closed course with no public access. Even low-speed vehicles can cause accidents or trip pedestrians.