This semester project focuses on micromice which are small autonomous robotic "mice" designed to solve a maze as quickly as possible. As seen in various videos, these robots can navigate and complete a maze in just a few seconds, demonstrating remarkable speed and precision.

Source: The Fastest Maze-Solving Competition On Earth
https://youtu.be/ZMQbHMgK2rw?si=60H5i8q6jv-QUGHG
Just like these spectacular micromice, we are going to build a little micromouse that uses sensors, motors, and a microcontroller. However, instead of solving mazes at a high speed, this project focuses on a different but equally interesting robotics challenge: obstacle avoidance, similar to a robotic vacuum cleaner. (Full maze solving is a bit involved for the individual project.)
You will build a small mobile robot capable of navigating an unknown environment, avoiding obstacles, much like a simplified Roomba. Below are some photos of the Micromouse you will build. (Note that those photos are from a more advanced version with three sensors and a Gyro)
The aim of this project is to get hands-on experience in a number of areas. We'll be learning how to assemble components following a circuit, soldering, 3D design, laser-cutting and programming micro-controllers.
We strongly encourage the use PlatformIO: a famous VSCode extension for programming microcontrollers, including ESP32s. Upload times are considerably faster with PlatformIO. In addition, familiarizing yourself with PlatformIO can be useful for other projects using ESP32s, Arduino and many other microcontrollers.
Whatever your choice, you'll find a tutorial for importing the project and installing the necessary libraries on Arduino IDE and PlatformIO in the Software section
The micromouse is 95x58mm.
In order to achieve precise movement, the micromouse makes extensive use of control theory, more specifically PID systems. Thanks to this, the micromouse can correct itself in real time using its various sensors.
You should have received a component bag with the following:
- 2x N20 Motors 500RPM
- 2x set of cables for the Motors
- 1x Motor Driver MX1508
- 1x Time-Of-Flight sensors ToF400C-VL53L1X
- 1x Microcontroller ESP32 30pin
- 2x 9V battery
- 1x Buck converter LM2596
- 1x 9V battery connector
- 2x Lego axels 4L
- 2x Lego tires
- 4x Lego gears
- 20x Jumper wires female to female
- 1x Soldering kit
Encoders keep track of how many steps each motor has taken. This is important because, unlike stepper motors, the brushed motors we're using for this project (N20 gear motors) are not exactly the same. In fact, these motors will always have a small difference in speed between them, and we need to compensate for this difference (however slight!) so that the micromouse can move straight forward / make precise movements. Thanks to the encoders, we can compensate for the difference in speed between the two motors by reading the number of steps each motor has taken, and trying to keep this number of steps almost equal.
The goal of this semester is to work close to the hardware of the mouse, you'll have to build the mouse and code the interface with the sensors and motors. The expected behavior will be to drive up to an obstacle with a nice and straight tragectory, detect it, turn away and drive away.
Build the mouse based on the instructions located further below in this document.
To practice 3D design, you will design the wheels of the micromouse (not the tires).
The dimensions of the wheels are for you to choose, but beware: The behavior of the mouse depends heavily on these parameters!
Also, since we use lego shafts to attach the wheels to the gear box, you need to make sure, when designing the wheels, that the shaft fits in the wheel. For your information, here are the lego shaft dimensions:
For your reference, here is an example of a wheel that you may get inspired from. The tire is given to you and fits snuggly around a 17.7mm rim. The design given uses supports inside the rail that are a pain to remove, it's your job to find a better design if you want to avoid this issue :D
This is the opportunity to make your product stand out! Fortunately this part is quite small and is therefore quite cheap and quick to manufacture, so don't be afraid to experiment!
Your software tasks are divided into several categories:
You will be given .h header files containing function signatures. Your task is to implement the corresponding .cpp files so that the functions exhibit the expected behavior.
-
encoders.h
Functions related to encoder usage and measurements. -
ToF.h
Functions related to the front Time-of-Flight (ToF) sensor. You will need to calibrate your sensors to have accurate readings, this can be achieved with a simple linear regression. -
motors.h
Functions defining the API used to control the motors.
We have provided a few function signatures that we consider important, but this is not intended to be exhaustive. You are encouraged to extend the API with any additional functions you find useful. Make it your own.-
Active braking
Active braking is a technique used to stop a DC motor more quickly than simply cutting power.
With brushed DC motors, one common method is to short the motor terminals together. While the motor is still spinning, it acts like a generator and produces a voltage known as back EMF (electromotive force). By shorting the terminals, this generated current flows through the motor itself, creating a torque that opposes the rotation and rapidly slows the motor down.With brushed DC motors, this is commonly achieved by briefly shorting the motor terminals together (aka set both pins to High)
-
For these tasks, no file structure or function signatures will be provided. You are expected to design the software architecture and implementation yourself.
Implement a PID controller that adjusts the power delivered to each motor so both wheels rotate at the same speed. The objective is to improve the robot’s ability to drive in a straight line.
A PID (Proportional–Integral–Derivative) controller is a feedback control algorithm commonly used in robotics and automation. It continuously measures the error between a target value and the current measured value, then adjusts the system output to minimize that error over time. You are expected to research how PID control works and tune your controller appropriately.
Implement an algorithm that:
- Drives the robot forward in a straight line
- Detects an obstacle ahead
- Uses active braking and correction to stop approximately 5 cm from the wall
- Performs a ~140 degree turn in either direction to face away from the obstacle (you will not be graded on the accurracy of that turn)
- Continues driving forward afterward
.step file in order to avoid mistakes.
-
First things first, you need to laser-cut and 3D-print the parts of the micromouse. You will need to open the step file and export the 3D parts you need. The part you need to laser-cut are given to you as
.dxfin the CAD folder.You need to laser-cut the following parts:
- 1x Base plate
- 2x Side walls
- 1x Top module plate
You need to use 3mm MDF: A sturdy enough width without being exceedingly heavy.
You also need to 3D-print the following parts:
- 2x N20-to-LEGO adapters
- 1x Motor bracket
- 1x Sensors holder
- 1x Battery holder
- 1x Shaft holder
- 1x Backplate (Buck converter holder)
⚠️ Most 3D parts were designed to require minimal to no supports. Be sure to disable them in PrusaSlicer when not necessary and mind the orientation of the parts when scheduling a print. Make sure to show them to an assistant or to a staff member of the SPOT before printing them.⚠️ If you want to specify which side of your part you want supported you can do that by using the brush tool.⚠️ Also, if you want the supports to be easily removable, you can use the organic supports option (although the sensor holder is the only piece that requires supports). -
Once you have laser-cut parts, you can assemble them:
⚠️ Be patient and careful when assembling MDF parts as they are fragile- Put the shaft holder in the middle of the gearbox and scew it to the base plate.
- Wedge the top module plate on top of the two side plates.
- Wedge the aforementioned assembly into the base plate, you should feel some resistance.
💭 You should use wood glue to make everything secure but you will not be able to disassemble your mouse afterwards should you need to debug. Only do this if you are sure that you don't want to disassemble the parts.
-
Now, we install the motors on the micromouse:
- Put the N20-to-LEGO adapters on the motors
- Press the N20 Motors into the motor bracket. It should be a snug fit
- Insert nuts in the battery holder. Place the battery holder on top of the motor bracket and the Screw both of them to the chassi. Screws should be inserted from the bottom of the chassis.
⚠️ Make sure the Lego adapter tips are properly aligned. The mouse would suffer from a lot of friction otherwise ! -
Mounting the gear box:
- Install a gear on each of the N20-to-LEGO adapters.
- Insert the lego shafts into the gearbox from the small hole in the gearbox walls. At the same time, add the other gear on the shaft and push it against the gearbox wall. The shafts should be maintained in place by the shaft holder which is in the middle of the gearbox.
-
Install the sensor holder on the front of the chassis. The sensor holder is designed to hold the 3 ToF sensors.
-
Finally, install the backplate on the back of the chassis by screwing it to the chassis. Same for the sensors holder: Attach it to the front of the chassis and screw it.
✅ After these steps, the basic mechanism of your mouse should be complete!
For this project, we recommend avoiding soldering wires directly to the boards. Instead, solder male header pins to the boards and create female cable assemblies to connect them.
When soldering male header pins to boards, make sure everything is stable and will not slip or move while you are heating the board and pins with the soldering iron. When soldering straight pins, you can use a breadboard to stabilize both the board and the pins (there is no need to push the pins too far into the breadboard). Make sure you adequately heat both the board and the pin before applying solder. The solder should not bead up, as that means the joint is too cold. Instead, it should flow smoothly around the metal ring and the pin, allowing you to add solder until you are satisfied with the amount.
We also recommend using appropriately sized solder wire for the task. For example, thinner solder wire makes it easier to control the amount of solder when working with the TOF sensor pins. The correct amount of solder should form an even, slightly convex “volcano” shape around the pin.
When soldering cable assemblies, make sure the stripped wires are twisted together securely. The wires should not pull apart easily once twisted together, the solder is intended primarily for electrical connectivity, not tensile strength. Try to find a good balance for the stripped wire length: if it is too long, it will require more solder and make it harder to achieve an even spread; if it is too short, twisting the wires together will be more difficult.
As with board soldering, make sure your setup is stable and that the wires are heated adequately before applying solder. Do not keep applying solder if it beads up, as this indicates the joint is not hot enough, remove the solder and continue heating.
A properly tinned soldering iron tip should look smooth, shiny, and evenly coated with a thin layer of solder. A dry, dark, or oxidized tip will not transfer heat effectively and will make soldering much more difficult. Regularly wipe the tip on the provided steel wool or brass wool cleaner and reapply a small amount of solder to keep it tinned between joints. If you have a stubborn black spot on the tip, you can use the acid paste to help remove the oxidation, then reapply solder to the tip and wipe it clean with the steel wool.
The next step is to solder all the components together. This step needs to be done carefully as there is a lot of wires to solder in a small space.
Keep in mind these important points:
-
⚠️ While this schematic accurately represents the soldering connections you should attempt to replicate we recognize it looks very cluttered as there are a lot of connections to make. For your convenience we linked a table with pinout assignments you can follow. -
‼️ Keep in mind that you cannot use every pin of the ESP32. Some pins have particular behavior. Please refer to the following website to know which pins you should prefer. As always we also include correct assignements you may want to use. -
💭 To have some clean soldering work, make sure to use heat shrink tubes or some electrical tape
-
💭 For modularity, instead of directly soldering wires to the components, you can solder pin headers to your various components and use female wires.
-
💭 Keep cables as short as they possibly need to be. This will have an enormous effect on the perceived cleanliness of the finished product.
Solder the IN+ and IN-.
OUT+ and OUT-) to measure the output voltage of the buck converter and adjust the potentiometer (Little golden screw) until you get
💭 You might see very slow change in the voltage at first. That is normal! Keep adusting the potentiometer until voltage changes are higher.
From the OUT+ and OUT- of the buck converter, you will join all the power wires from every component together.
- Motor driver: Solder a wire for power and a wire for ground to the motor driver
+and-pins. - Motors:
- Left: Solder the motor
+(Red wire) et-(White wire) to the motor driver (pins next to "Motor-A"). Solder a wire for encoder+(Black wire !) and for-(Blue wire). - Right: Solder the motor
+(Red wire) et-(White wire) to the motor driver (pins next to "Motor-B"). Solder a wire for encoder+(Black wire !) and-(Blue wire).

Source: https://www.amazon.com/Torque-Electric-Encoder-Engine-Science/dp/B0CBR8Z617

Source: https://components101.com/modules/mx1508-dc-motor-driver-pinout-features-datasheet
- Sensors: Solder wires to
VINandGNDpins of these components. - ESP32: Solder wire to
V5andGNDpins to supply power to the ESP32. - Join and solder all power wires together and all ground wires together (motor driver, sensors, encoders and ESP32) except for the motors, which are soldered to the motor driver. Once all the components to be supplied with
$5V$ are connected together by two wire "bus" (one bus for power and one bus for ground), solder these two wire buses to the buck converterOUT+($5V$ power bus) andOUT-(ground).
-
Encoders
- Left motor encoder: Solder the yellow & the green wire of the encoder to pins of the ESP32.
- Same idea for the right motor encoder.
-
Motor Driver
- Left motor: Solder a wire between the pin INT1 (Forward) of the motor driver and a pin of the ESP32. Same for the pin INT2 (Backward), but with another pin of the ESP32.
- Same idea for the right motor.
⚠️ Make sure that the pins you use are not "input only" pins (i.e GPIO 34, 35, 36, 39). -
X-SHUT
The X-SHUT pin is used to switch off the sensor. In case there we multiple sensors, we would need to switch them off one by one in order to redefine their addresses, because if they use the same addresses on the
$I^2C$ bus, they'll send data to the same address and the data read by the ESP will be incorrect. (You don't have to worry about this aspect as there is only one sensor).- Solder a wire between the X-SHUT pin of the sensor and a pin of the ESP32.
📝 In an ESP32 system, peripherals like ToF sensors communicate with the microcontroller on the same
💭 Often, the default
Once every electrical component has been soldered, we can mount them on the micromouse, in their appropriate place. Most of the screw to be used are M2.5 screws, except for the sensors, which are M2 screws.
And voilà! Your mouse is completed!
We need to setup the environment in which you will work on to be able to program and upload code to the micromouse.
If you want to use PlatformIO, follow the instructions below. If you want to use Arduino IDE, please refer to the Arduino IDE section.
- Install VSCode on your computer. You can download it here.
- In the extensions tab, search for PlatformIO and install it.
- Download the code from the repository.
- In VSCode, go to
File>Open. Look for the directory you just downloaded and open it. You should see aplatformio.inifile in the root directory of the project. - Click on the PlatformIO icon in the left sidebar. Wait a bit for the project to load. Once it is loaded, you should see
Build,Uploadand many other options under theProject Taskssection. - That's it ! You can now start coding in the
srcdirectory. The main file ismain.cpp. Each time you want to upload the code to the micromouse, click on theBuildbutton in the PlatformIO sidebar, and thenUpload. If you want to read the serial monitor, click on theUpload and monitorbutton in the PlatformIO sidebar.
- Install Arduino IDE on your computer. You can download it here.
- Open Arduino IDE and go to
Tools>Board>Boards Manager. - In the search bar, type
ESP32. - Install the package made by "Espressif Systems".
- Now, let's install the libraries we need for the sensors:
- Go to
Tools>Manage Libraries. - In the search bar, type
VL53L1X& install the first one that appears.
- Go to
- You can now open the downloaded project in Arduino IDE. Go to
File>Openand select thesrcdirectory of the project you just downloaded. You should see amain.cppfile in the root directory of the project, this is the file you will be working on.
To ensure that everything is working properly, and that your soldering work is correct, we want to test every components of the micromouse.
For that, we provide you with a healthcheck.bac file, which contains functions to check if everything is working properly: It will help you read the sensors, check that the motors work as expected and that the value read by the encoders are correct. To run the code, first rename the file to healthcheck.cpp. Additionally, rename main.cpp to main.bac (or similar) to prevent it from being compiled.
- Sensors: If you notice that the sensors doesn't work or you have some
$I^2C$ related errors (appearing on the serial monitor), then first check in the pin assignment (this is probably due to some faulty X-SHUT pin assignment) inwiring.h. If the pin assignment is correct, check your soldering work again. Also, if the values are not accurate, you may want to adjust the offset values inconfig.h. - Motors: If the motors don't go in the expected direction, then you should invert the pins of the motors in
wiring.h. If a motor doesn't work at all, then recheck the pins and/or your soldering work. - Encoders: When moving forward the mouse should have positive values for the encoders, and negative values when moving backward. If the values are not correct, then check the pin assignment of the encoders and your soldering work. If the values doesn't get updated at all, then check your pin assignment and/or your soldering work.
If everything works as expected, then you have the necessary basis to start programming the micromouse !

Source: https://www.upesy.com/blogs/tutorials/esp32-pinout-reference-gpio-pins-ultimate-guide?shpxid=94928d88-3b39-46f8-bb16-cd075441d1bf
Here is an example of a pin assignment for the ESP32.
| Component | Pin Name | ESP32 Pin |
|---|---|---|
| Sensors | I2C SDA | 21 |
| Sensors | I2C SCL | 22 |
| Left Motor | INT1 (Motor Driver) | 26 |
| Left Motor | INT2 (Motor Driver) | 25 |
| Right Motor | INT3 (Motor Driver) | 33 |
| Right Motor | INT4 (Motor Driver) | 32 |
| Front Sensor | XSHUT_PIN_CENTER | 19 |
| Left Encoder | SIGNAL_FEEDBACK_YELLOW_LEFT | 15 |
| Left Encoder | SIGNAL_FEEDBACK_GREEN_LEFT | 2 |
| Right Encoder | SIGNAL_FEEDBACK_YELLOW_RIGHT | 4 |
| Right Encoder | SIGNAL_FEEDBACK_GREEN_RIGHT | 5 |
| Power & Ground | 5V and GND | Vin and GND |
| Sensor power | Vin and GND | 3.3V and GND |










