
PS2 Controller Robot Rover with ESP32 and VL53L1X - Proteus Simulation

Hello friends, I hope you all are doing great. Today, I am going to share the PS2 Controller Robot Rover with ESP32 and VL53L1X - Proteus Simulation, the ninety-fifth project of our IoT Projects series. If you have searched for an ESP32 PS2 controller robot, how the PS2 controller protocol works, collision avoidance with a time-of-flight sensor, or an L298N robot car with an ESP32, here is a complete rover in a Proteus simulation. A PS2 wireless controller is one of the cheapest ways to drive a robot: a game pad with sixteen buttons, two sticks and two rumble motors, and a small receiver that speaks a simple serial protocol.
This rover adds the thing every remote-control car is missing: a sense of what is in front of it. A VL53L1X time-of-flight sensor in its nose measures the distance with a laser sixteen times a second. Within 2.5 m the ESP32 cuts the forward speed in proportion, and at 30 cm it blocks forward completely. It tells the driver too, through the controller's own rumble motors: a buzz in the slow zone, a strong rumble at the wall. Back and turns still work, so you can always drive away. In this tutorial, we will go through the circuit, the PS2 protocol byte by byte, how a time-of-flight sensor measures, the L298N and the differential drive, the collision assist, and the code. Then we drive the rover at a white card, a black object and a wall in the simulation, turn away and race off at full speed. The black object teaches the most. At the end, you can download the project with the sketch and every library file.
NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the PS2 controller robot rover with ESP32 and VL53L1X in Proteus simulation:
What Does This PS2 Robot Rover Do?
- Drives from a game pad: UP, DOWN, LEFT and RIGHT on the D-pad, turns on the spot or in an arc.
- Three gears: TRIANGLE switches 40, 70 and 100 % of full speed; START arms the rover, CROSS brakes.
- Sees ahead: a VL53L1X time-of-flight sensor measures up to 4 m, every 60 ms.
- Slows and stops by itself: the speed is cut within 2.5 m and forward is blocked at 30 cm.
- Talks back: the controller buzzes in the slow zone and rumbles at the wall; a red LED shows BLOCKED.
- A dashboard: STOP, ARM and the assist on the network, with the distance, the wheels and the controller's link.
It is a great project for learning a bit-banged serial protocol, I2C with 16-bit registers, PWM motor control and a simple safety layer in one go. In the simulation, the PS2 pop-up is the controller itself, the VL53L1X pop-up places objects in front of the sensor, and the motors' pop-ups show each wheel's speed and current.
Components Used in the Proteus Simulation
All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| ESP32 DevKit V1 | ESP32 DEVKIT V1 | ESP32 DevKit V1 Library for Proteus | U1, ESP32_PS2_Rover.hex, Wi-Fi 192.168.1.101 |
| PS2 wireless controller | PS2RECEIVERTEP | PS2 Wireless Controller Library for Proteus | U2: DAT D19, CMD D23, ATT D5, CLK D18, 3.3 V |
| VL53L1X time-of-flight | VL53L1XTEP | VL53L1X Distance Sensor Library for Proteus | U3: SDA D21, SCL D22, GPIO1 D4, 3.3 V |
| L298N motor driver | L298NDRIVERTEP | L298N Motor Driver Library for Proteus | U4: ENA D32, IN1 D33, IN2 D25, ENB D14, IN3 D26, IN4 D27 |
| TT gear motors (2) | TTGEARMOTORTEP | TT Gear Motor Library for Proteus | M1 left, M2 right, 65 mm wheels |
| 5 mm LEDs | LED5MMGREENTEP, LED5MMREDTEP | 5mm LED Library for Proteus | D1 armed (D17), D2 blocked (D16) |
| Resistors 220 ohm | RESISTOR4BANDTEP | Resistor Library for Proteus | R1, R2 for the LEDs |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the PS2 Rover: the Circuit
| Signal | ESP32 | Goes to |
|---|---|---|
| DAT / CMD / ATT / CLK | D19 / D23 / D5 / D18 | the PS2 receiver (DAT with the input's pull-up) |
| SDA / SCL / TOFINT | D21 / D22 / D4 | the VL53L1X (I2C 0x29) and its data-ready pin |
| ENA / IN1 / IN2 | D32 / D33 / D25 | the L298N's bridge A: the left wheel |
| ENB / IN3 / IN4 | D14 / D26 / D27 | the L298N's bridge B: the right wheel |
| LARM / LSTOP | D17 (TX2) / D16 (RX2) | the green and red LEDs through 220 ohm |
| +7.4V | - | the L298N's motor supply: a 2S Li-ion pack |
The PS2 receiver and the VL53L1X run on 3.3 V, the same as the ESP32's pins. The L298N drives both wheels from a 7.4 V two-cell pack; with the 2 V its bridges lose, the 6 V TT motors get close to their rated voltage at full duty. Both enable jumpers on the L298N are off, so ENA and ENB come from the ESP32 and carry the PWM.
How the PS2 Robot Rover Works
The PS2 Controller Protocol
The PS2 receiver is an SPI-like slave with four wires. The host pulls ATT (attention) low, then clocks bytes out on CMD and in on DAT at the same time, least significant bit first: CMD is set while CLK is high, CLK falls, and the receiver's bit on DAT is read when CLK rises again. DAT is open drain, so it needs a pull-up. A poll is the bytes 01 42 00: the controller answers its ID (41 for digital mode) and 5A, then two bytes of buttons, active low, one bit a button. The fourth and fifth bytes the host sends drive the two rumble motors, once they have been mapped with the 4D command in configuration mode (43). The ESP32 polls fifty times a second.
Measuring with Light
The VL53L1X sends 940 nm infrared laser pulses through its lens and times their return on an array of single-photon detectors: distance = the speed of light x the round trip / 2. Light travels 30 cm in a nanosecond, so the chip measures in picoseconds. A longer timing budget collects more photons; long distance mode reaches up to 4 m in the dark. Every measurement comes with a range status: 0 when the distance is valid, other codes when the signal was too weak or noisy. A black object returns far less light than a white card, and sunlight adds noise; both make the range shorter. The sketch starts the chip the way ST's Ultra Lite Driver does: its default configuration, one measurement, then long mode, a 50 ms budget and a distance every 60 ms.
Differential Drive and the L298N
The rover steers like a tank: two wheels, each with its own motor. Both forward at the same speed, it goes straight; one faster, it turns in an arc; one forward and one back, it spins on the spot. The L298N has an H-bridge for each wheel: IN1 / IN2 set the direction of the left one, IN3 / IN4 the right one, and the PWM on ENA / ENB sets the speed. Each wheel ramps 5 % every 20 ms, so a full start takes 0.4 s and the rover does not jerk.
The Collision Assist
The assist only touches forward. Nearer than 2.5 m, the forward speed is scaled down in proportion to the distance left: full at 2.5 m, zero at 0.3 m. Nearer than 0.3 m, forward is blocked: the wheels stop even with UP held, and forward stays blocked until the way is clear beyond 0.35 m. Those 50 mm of hysteresis matter: our first run had a card that read 298 to 301 mm, and without them BLOCKED switched on and off ten times a second. The assist only trusts a valid distance (range status 0), which is also its weak spot, as the results show. DOWN and the turns are never limited, because they are how the driver gets away. The controller tells the driver what is happening: its small motor buzzes in the slow zone, its large motor rumbles at the wall, and the red LED lights while forward is blocked. SQUARE switches the assist off for tight places.
The Arduino Code Explained
The sketch is ESP32_PS2_Rover.ino, built for our ESP32 DevKit V1 with the WiFi, WebServer and Wire libraries. The PS2 byte: CMD set, CLK low, DAT read on the way back up:
digitalWrite(CMD, (out >> i) & 1);
if (digitalRead(DAT)) in |= 1 << i;
A poll sends the rumble values in bytes 3 and 4 and reads the buttons, active low, from the answer:
const byte tx[9] = {0x01, 0x42, 0x00, small, large, 0x00, 0x00, 0x00, 0x00};
buttons = ok ? ~(rx[3] | (rx[4] << 8)) : 0;
The VL53L1X uses 16-bit register addresses. After its default configuration, the sketch sets the timing budget and the period, and reads the range status and the distance when GPIO1 says one is ready:
wr32(0x006C, (uint32_t)((rd16(0x00DE) & 0x3FF) * 60 * 1.075)); // a distance every 60 ms
dist = rd16(0x0096);
The assist: the wall with its hysteresis, the forward speed scaled between 300 and 2500 mm, and the rumble motors set from it:
wall = dist < (blocked ? RELEASE_MM : STOP_MM); // (50 mm of hysteresis: final 1's card at 0.3 m read 298 - 301 mm
if (f > 0) f = wall ? 0 : (long)f * (dist - STOP_MM) / (SLOW_MM - STOP_MM); // and BLOCKED flickered ten times a second)
large = armed && wall && (buttons & B_UP) ? 255 : 0; // the large one rumbles at the wall
The wheels: the D-pad mixed into the two duties, a ramp of 5 % every 20 ms, and a 500 Hz PWM (in the simulation a PWM of 1 kHz or more reaches a driver as its average voltage):
leftWant = constrain(f + t, -100, 100);
leftNow += constrain(leftWant - leftNow, -5, 5);
ledcAttach(ENA, 500, 10); ledcAttach(ENB, 500, 10);
The dashboard's links are Refresh, STOP, ARM and ASSIST ON / OFF; /data gives the state, the distance, both wheels and the rumble as JSON.
How to Run the Proteus Simulation
- Download the project zip below and install the library files (the steps are under the download button).
- Open ESP32-PS2-Rover.pdsprj from the Proteus Simulation folder. Keep the HEX and the DLL files next to it.
- Press Play. When the serial monitor says READY, click U2 for the controller.
- Its chips hold a button and release it on the second click: Start arms the rover, Up drives it.
- Click U3 for the sensor and give it a target: white 2 m slows the rover, white 0.3 m stops it, black 1 m is not seen at all. Left or Right turn it away.
Simulation Results: the Rover in Proteus
We pressed Play and drove the rover with the PS2 pop-up's buttons while the VL53L1X's pop-up put things in front of it: a white card at 2 m, a black card at 1 m, a white card at 0.3 m, then nothing. The motors' pop-ups show each wheel's speed, voltage and current, the sensor's pop-up the distance with its range status and signal. The times are the sketch's clock; the whole run took 33.6 simulated seconds.
Linked and Ready
The controller paired 0.62 s after Play, in digital mode (ID 0x41). The VL53L1X answered with its model ID, 0xEACC, and started ranging. At 2.91 s the sketch reported READY. Nothing was in range yet: the sensor's pop-up showed a white card at 6 m, well beyond its 2981 mm range for a white target, so every reading came with status 2 and the dashboard said no target.
Driving Forward
START armed the rover and the green LED lit; UP held at gear 2 drove both wheels at 70 %. The L298N put 4.11 V across each motor; each TT motor turned at 163 RPM, 0.55 m/s at the rim of its 65 mm wheel. The PS2 pop-up shows UP held and no rumble.
Slowing Down at 2 m
Then a white card 2 m ahead. The sensor measured 1996 mm with status 0 and a return signal of 1.00 MCPS. Inside the 2.5 m slow zone, the forward speed was scaled to (1996 - 300) / (2500 - 300) of the gear: 53 %, 3.15 V on each motor. The controller's small motor came on: the driver feels the obstacle coming before seeing it.
The Black Object It Did Not See
Next, a black card at 1 m, nearer than the white one. The rover did not slow down: it went back to 70 %. The sensor's pop-up explains why: a black card returns so little light, 0.23 MCPS, that its range for this target is only 711 mm. The chip still gave a number, 974 mm, but with range status 2, signal fail, and the sketch trusts only status 0. That is the right decision, because a failed measurement can be anything, and it is also the most important lesson of this project: a time-of-flight sensor sees a dark object much later than a light one. A real robot needs a margin for that, a slower top speed or a second kind of sensor.
Blocked at the Wall
Then a white card at 0.3 m. At 16.47 s the sketch reported BLOCKED at 299 mm: forward stopped: both wheels ramped down to zero with UP still held, the red LED lit, and the controller's large motor rumbled at full strength (255). The reading wandered between 298 and 303 mm, and the 50 mm of hysteresis kept the rover blocked the whole time.
Turning Away
We let go of UP and held LEFT. A turn is never limited: the left wheel ran backwards and the right one forwards, both at 163 RPM, and the rover spun on the spot. When the way was clear again, the sketch reported forward free.
Full Speed and Stop
With nothing ahead, TRIANGLE switched to gear 3 and UP drove both wheels at 100 %: 5.90 V on each motor, close to the TT motor's rated 6 V, and 243 RPM, 0.83 m/s. SQUARE switched the assist off, and STOP on the laptop disarmed the rover. The phone shows the same dashboard, and the serial monitor holds every event of the run.
The assist did its job: it slowed the rover in proportion, stopped it at the wall without flickering, left the turns free, and warned the driver through the controller. And it showed honestly what it cannot do: a black object at 1 m was invisible to it.
Download the Project Files
Click the button below to download PS2-Controller-Robot-Rover-ESP32-VL53L1X-Proteus-Simulation-v1.0.zip (about 4.7 MB, without the source code of the models):
PS2 Controller Robot Rover with ESP32 and VL53L1X - Proteus Simulation V1.0- Proteus Simulation: ESP32-PS2-Rover.pdsprj, ESP32_PS2_Rover.hex and copies of the models.
- Arduino Code: ESP32_PS2_Rover.ino, the sketch.
- Proteus Library Files: the LIB files of every part.
- Proteus Model Files: the DLL models.
- README.txt: the installation steps, the properties, the test results and the links to every library post.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install the Project Files
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files from Proteus Model Files into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
Open the sketch in the Arduino IDE with the TEP Boards for Proteus installed, select ESP32 Dev Module (TEP Proteus), and use Sketch > Export Compiled Binary. Put the new HEX next to the project. The distances of the assist, the gears and the ramp are near the top.
Ideas to Extend the Project
- Switch the controller to analog mode and drive with the sticks for smooth speed and steering.
- Add a second VL53L1X at the back so that reversing into a wall is caught too (two sensors need XSHUT to set their addresses).
- Add wheel encoders and drive a set distance or a straight line.
- Record a drive and play it back: an autonomous route taught by hand.
- Stream the distance to the dashboard as a live graph.
- Add a buzzer for the people around the rover, not only the driver.
From Simulation to Real Hardware
- The PS2 receiver: 3.3 V only; most need a pull-up on DAT, and many like a slow clock (a few microseconds a bit).
- Pairing: a real controller pairs with its receiver when both are switched on; the LED stops blinking.
- The VL53L1X: keep its window clean and uncovered; a cover glass needs ST's crosstalk calibration.
- Power: the motors on their own 2S pack, the ESP32 from a regulator, one common ground.
- Motors: mount one motor mirrored and swap its wires, so that both wheels turn forward together.
Troubleshooting
- PS2 controller LOST: the pull-up on DAT, 3.3 V on the receiver, and the controller ON on its pop-up.
- The rover does not move: START arms it (the green LED); the L298N's ENA / ENB jumpers must be off.
- The wheels only switch on and off: a PWM of 1 kHz or more reaches the L298N as its average voltage in the simulation; keep 500 Hz.
- Never blocked: the assist is off (SQUARE), or the sensor's range status is not 0.
- No dashboard: the ESP32 joins TEP-WiFi about three seconds after the start; press Go again.
Limitations of the Simulation
- The PS2 receiver, the VL53L1X, the L298N and the motors are our libraries' models, built from their datasheets, not every detail of real parts.
- The rover does not move on the sheet: the wheels turn, and the distance is what the VL53L1X's pop-up sets.
- The VL53L1X model takes the target from its chips (0.3, 1, 2 or 3 m), not from a moving rover.
- ESP32 is a product of Espressif Systems, VL53L1X of STMicroelectronics and PlayStation of Sony; this project is not made or endorsed by them or by Labcenter.
So, that was all about the PS2 Controller Robot Rover with ESP32 and VL53L1X - Proteus Simulation. I hope it helps you understand the PS2 protocol, how a time-of-flight sensor measures with light, how a differential drive steers, and how a small safety layer can sit between the driver and the motors, all tested in a simulation before you build the rover. More projects with the ESP32 and the Raspberry Pi 5 are coming. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!






















Comments
0