Robot car simulator for Arduino

Build an Arduino robot car before you buy the kit. Wire the board, an L298N motor driver, two or four DC motors and your sensors on the 2D canvas, add a car chassis kit, and open the 3D Test Room: your sketch drives the car around a line track, a maze or an obstacle room, using the real voltages on the motor pins.

4WD robot car with an Arduino, L298N and HC-SR04 on its deck in the SolderHub 3D Test Room

What you can do

  • Your motors become the wheels

    The DC motors in your circuit drive the car through the same voltages a real L298N would give them. Swap two motor wires and the car spins, just like on the bench.

  • Line follower and obstacle avoider

    IR modules under the nose see the black tape, and the HC-SR04 at the front measures the distance to walls, obstacles and boxes, so line-follower and obstacle-avoider sketches work end to end.

  • 2WD or 4WD, your sizes

    Choose two- or four-wheel drive, wheel diameter, track width, motor rpm and voltage. The physics uses them, so a bigger wheel drives faster and a 4WD car skids in turns.

  • A real-scale 3D test room

    A furnished lab with a test mat, seven tracks and arenas, boxes and balls to push, a follow camera, live speed and sensor readings, and keyboard driving to try the car without code.

Worked example: a line follower robot car

  1. 1

    Open the example

    It loads an Arduino Uno, an L298N driver powered by a 6 V battery, two DC motors, two IR sensor modules and a 2WD car kit, wired and opened in the 3D Test Room.

  2. 2

    Press Run

    The prebuilt sketch starts at once. The car sits on the oval track with one IR sensor either side of the black tape.

  3. 3

    Watch it steer

    When a sensor sees the tape, that side's wheel stops and the car pivots back over the line, then drives straight again. Live readings show both wheel speeds and both sensors.

  4. 4

    Tune it

    Change the speeds or the 120 ms line memory in the sketch, switch to 4WD or bigger wheels, or pick another track, and see how the car copes.

Open this example

The sketch

// Line follower car: two IR modules under the nose, an L298N driving two DC motors.
// Open the Test Room (car icon) and press Run to watch it follow the black tape.
const int ENA = 5, IN1 = 7, IN2 = 8;   // left motor
const int ENB = 6, IN3 = 9, IN4 = 10;  // right motor
const int IR_L = 2, IR_R = 3;          // HIGH = this sensor is over the black line

void drive(int left, int right) {
  digitalWrite(IN1, left > 0);  digitalWrite(IN2, left < 0);
  digitalWrite(IN3, right > 0); digitalWrite(IN4, right < 0);
  analogWrite(ENA, abs(left));  analogWrite(ENB, abs(right));
}

void setup() {
  int outs[] = {ENA, IN1, IN2, ENB, IN3, IN4};
  for (int pin : outs) pinMode(pin, OUTPUT);
  pinMode(IR_L, INPUT);
  pinMode(IR_R, INPUT);
  Serial.begin(9600);
}

unsigned long lastSeen = 0;
int turn = 0;  // -1 left, +1 right: the side the line was last seen on

void loop() {
  bool left = digitalRead(IR_L);
  bool right = digitalRead(IR_R);
  if (left != right) { turn = left ? -1 : 1; lastSeen = millis(); }
  // Keep turning for a moment after the tape slips past the sensor ("line memory").
  if (turn != 0 && millis() - lastSeen < 120) {
    if (turn < 0) drive(0, 200); else drive(200, 0);
  } else {
    drive(130, 130);  // line between the sensors: straight on
  }
  delay(2);
}

Good for

  • Trying a robot-car sketch before buying the kit
  • Learning motor drivers, PWM and IR line sensors
  • Comparing 2WD and 4WD, wheel sizes and motor speeds
  • Robotics clubs and classroom challenges

Limits to know

  • The physics is approximated: no wheel slip, inertia or battery sag
  • Only DC motor parts turn the wheels; servos and steppers do not drive the chassis yet
  • The car's speed depends on the voltages in your circuit, so check your motor supply
  • Sensors read the room at your device's frame rate

Board models and firmware status

  • Arduino Uno
  • Arduino Nano
  • ESP32 DevKit
  • Raspberry Pi Pico

Frequently asked questions

Can I simulate an Arduino line follower robot?
Yes. Add two IR obstacle sensor modules and wire them to your Arduino. In the Test Room they sit under the car's nose and report the black tape, so a normal line-follower sketch steers the car around the track.
Does the L298N motor driver work in the simulator?
Yes. Wire IN1 to IN4 and ENA/ENB to the board and the motor outputs to DC motors. The car's wheel speed and direction come from the voltage the driver puts across each motor.
How realistic is the robot physics?
It is an approximated model: first-order gear motors with a stall voltage, differential and skid steering, collisions with walls and obstacles, and simulated encoders. It does not model wheel slip, battery sag or inertia beyond the motor time constant.
Can I drive the car without writing code?
Yes. Press Drive in the Test Room and use W, A, S, D or the arrow keys. Press Run instead to let your sketch take over.