Table-top robot that never falls off
Build it step by step
0 of 6 doneAssemble the chassis
Fit the motors, wheels, caster and battery holder from the kit.
Mount the sensors
Fix one at each front corner pointing down, 5 to 10 mm above the surface and just ahead of the wheels.
Wire the motor driver and Uno
Follow the wiring table. Join all grounds.
Check sensor outputs
With the robot on the table, note the DO level for each sensor over the table and over the edge, with a Serial print or the module's LED.
Set EDGE and speed
Put EDGE to the level seen over nothing. Start with SPEED 140.
Test on a table
Hold the robot near the edge and then let it drive. Put cushions on the floor first.
How do you build a table-top robot that never falls off?
IR sensors pointing down see the table edge, and the robot backs up and turns before it drops. You need Arduino Uno R3, TCRT5000 IR reflective sensor module × 2, L298N Dual H-Bridge Module, Robot car chassis kit 2WD (acrylic), Battery holder 18650 2S (series), 18650 cell 2600 mAh (branded) × 2 and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 7
Wiring
| From | To | Why |
|---|---|---|
| Left TCRT5000 OUT | Uno D2 | Left edge sensor |
| Right TCRT5000 OUT | Uno D3 | Right edge sensor |
| Both TCRT5000 VCC and GND | Uno 5V and GND | Sensor supply |
| L298N ENA, IN1, IN2 | Uno D5, D7, D8 | Left motor |
| L298N ENB, IN3, IN4 | Uno D6, D9, D10 | Right motor |
| Battery pack + | L298N 12 V terminal and Uno VIN | Motor and board supply from two 18650 cells |
| Battery pack - | L298N GND and Uno GND | Common ground |
Code
Arduino IDE, board "Arduino Uno". No libraries. The TCRT5000 modules have a small trimmer that sets the switching distance, and the output level over a surface versus over nothing differs between brands, so test and flip the EDGE constant.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const byte LS = 2, RS = 3; // edge sensors
const byte ENA = 5, IN1 = 7, IN2 = 8, ENB = 6, IN3 = 9, IN4 = 10;
const byte SPEED = 140;
const int EDGE = HIGH; // module output level over nothing: check yours and flip if needed
void drive(int l, int r) {
digitalWrite(IN1, l > 0); digitalWrite(IN2, l < 0);
digitalWrite(IN3, r > 0); digitalWrite(IN4, r < 0);
analogWrite(ENA, abs(l)); analogWrite(ENB, abs(r));
}
void setup() {
for (byte p = 5; p <= 10; p++) pinMode(p, OUTPUT);
pinMode(LS, INPUT); pinMode(RS, INPUT);
}
void loop() {
bool left = digitalRead(LS) == EDGE, right = digitalRead(RS) == EDGE;
if (left || right) {
drive(0, 0); delay(100);
drive(-SPEED, -SPEED); delay(300); // back away
if (left && !right) drive(SPEED, -SPEED); // edge on left: turn right
else drive(-SPEED, SPEED); // edge on right or both: turn left
delay(350 + random(300));
drive(0, 0); delay(50);
} else {
drive(SPEED, SPEED);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Sensors over the table | LED on the module on, output at the surface level |
| Sensor held over the edge | Output changes |
| Robot driving toward an edge | Stops, reverses, turns, and continues |
| Ten minutes on a table | Never falls off |
If it does not work
Robot drives off the edge
EDGE is the wrong level, the sensors are too high or the turn starts too late. Lower the speed.
Robot spins on the spot on the table
The sensor trimmers are set too sensitive for the table colour. Turn them back.
Wheels turn the wrong way
Swap the IN pins for that motor.
Sensor fooled by black tables
Black surfaces reflect little IR. Test the material first or use a different table.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the table-top robot that never falls off?
Arduino Uno R3, TCRT5000 IR reflective sensor module × 2, L298N Dual H-Bridge Module, Robot car chassis kit 2WD (acrylic), Battery holder 18650 2S (series), 18650 cell 2600 mAh (branded) × 2 and Jumper wires male to male (40 pcs, 20 cm).
How long does the table-top robot that never falls off take to build?
About 90 minutes for a beginner maker, in 6 steps.
How do I know the table-top robot that never falls off works?
Sensors over the table: LED on the module on, output at the surface level. Sensor held over the edge: Output changes. Robot driving toward an edge: Stops, reverses, turns, and continues.
Robot drives off the edge: what should I check?
EDGE is the wrong level, the sensors are too high or the turn starts too late. Lower the speed.
Robot spins on the spot on the table: what should I check?
The sensor trimmers are set too sensitive for the table colour. Turn them back.
Wheels turn the wrong way: what should I check?
Swap the IN pins for that motor.
Sensor fooled by black tables: what should I check?
Black surfaces reflect little IR. Test the material first or use a different table.
