Project · ESP32 · Neural network
Four IR sensors look at the floor. A small neural network turns what they see into a speed for the left motor and a speed for the right. The car below is driven by the trained network from the code repository.
Each sensor reads 1 over the tape and 0 over the floor. That gives 16 possible patterns, such as 0110 when the line is in the middle.
Two hidden layers of 7 neurons. 107 numbers in total, 428 bytes, 91 multiply-adds per decision. No Jetson needed.
Left and right wheel speed between 0 and 1. An ESP32 runs this 200 times per second and drives a TB6612FNG motor driver.
| Lost-line events in 120 s | Demo loop | Oval | Winding |
|---|---|---|---|
| Gap 81 mm | 0 | 0 | 0 |
| Gap 135 mm | 6 | 0 | 8 |
| Gap 189 mm | 18 | 1 | 8 |
| Gap 243 mm | 29 | 14 | 11 |
Try it above: set the line to dashed and drag the gap slider to the right. With all four sensors at 0 the network can only drive straight, so on a curve a long gap takes the car off the line.
Every number on this page comes from simulation. The firmware has not run on a real car yet, so real sensors, motors and floor friction are still untested.
With 16 sensor patterns the network matches a steering rule written by hand. The plan is to train it on logged driving from the real car, with analog sensor readings.