MAKING VIDEO
The Line Follower Robot is one of the most popular and fundamental projects in robotics, widely used in competitions, research, and learning. Its main objective is to autonomously detect and follow a predefined path, usually a black line on a white surface, using infrared sensors.
WORKING OF A LINE FOLLOWER ROBOT
A line follower robot is an autonomous robot that detects and follows a line drawn on the floor, usually a black line on a white surface (or vice versa). A typical line follower robot should have 3 main sections.
1.Sensors (IR modules or LDRS)
Usually uses the IR modules and infrared sensors placed at the bottom to detect the difference in reflectivity between black (absorbs light) and white (reflects light).When the sensor is over white → it reflects IR light back → sensor outputs HIGH. When the sensor is over black → little or no reflection → sensor outputs LOW. So with this logic, we can differentiate between black and white.
2. Microcontroller (Brain)
microcontroller is not neccessory, but for easy and accurate. Based on which sensor detects the line, it makes a decision (go forward, turn left, turn right, or stop).
3.Motors
The controller sends signals to the motors via a motor driver, and with the help of the motors, the robot moves.
ABOUT ATOM LINE FOLLOWER ROBOT
In this project, we have built a Line Follower Robot powered by the M5Stack Atom Matrix, a compact ESP32-based development module. The Atom Matrix serves as the brain of the robot, handling sensor data and motor control, and also provides a built-in LED matrix for real-time visual feedback.
The robot is equipped with two infrared line sensors to detect the track and two transistor based motor drivers to control the two DC gear motors. When the sensors read the path, the Atom Matrix processes the data and adjusts the motor, allowing the robot to stay on track with precision.
This project demonstrates the integration of embedded systems, sensor technology, and motor control in a simple yet practical robotics application. It serves as a great starting point for beginners to understand autonomous navigation and can be further enhanced with features such as PID control, speed optimisation obstacle detection.
Components needed
1.M5stack atom matrix - 1 Nos
2. N10 gear motor 3v (50 rpm) - 2 Nos
3. TCRT5000 IR transceiver - 2 Nos
4. 3.7v Li-Polymer Battery - 1 Nos
5. BC547 Transistor - 2 Nos
6. 10K resistor - 4 Nos
7. 330ohm resistor - 2 Nos
8. 1N4007 diode - 2 Nos
9. Dot PCB
10. Switch on/off - 1 Nos
11. 3D printed parts
12. screws
Atom-Matrix is an ultra-compact development board in the M5Stack series, measuring only 24.0 x 24.0 mm. It offers additional GPIOs for user customization and is ideal for embedded smart-hardware projects. Powered by the ESP32-PICO-D4 with an integrated Wi-Fi module and 4 MB SPI flash, the board carries an IR transmitter, a 5 × 5 RGB LED matrix, a built-in IMU (MPU6886), and a programmable button hidden beneath the Neo-LED matrix. A USB Type-C port enables quick program upload/download, and a HY2.0-4P connector is provided for peripheral expansion. An M2 mounting hole on the back allows secure installation.
These two DC gear motors drive the robot.
This TCRT5000 IR Sensor is used to detect colour and distance. This sensor module consists of an IR transmitter & an IR receiver. The IR Transmitter continuously emits an IR signal, which is then reflected by the white surface and is then detected by the IR receiver.
CIRCUIT DIAGRAM
This circuit diagram has 3 sections
1. main controller is U1: M5Stack ATOM Matrix.
Pin G33 goes to sensor output from left sensor, Pin G32 goes to the sensor output from right sensor. Pin G19 is connected to base resistor R3, then to the transistor. pin G22 connected to base resistor R5, then to transistor.2. Sensor Section (TCRT5000L Reflective IR Sensors)
There are two TCRT5000L sensors. Each has an IR LED emitter +phototransistor..Working:
White surface → reflects IR → phototransistor conducts → output goes to controller.
3. Motor Driver Section
This part uses two NPN transistors (BC547C) as simple low-side switches to drive DC motors. Flyback diodes (1N4007) connected across motor terminals (cathode to VCC, anode to transistor collector). capacitor (0.1 µF) connected across motor terminals to suppress noise.Working:
When the atom outputs HIGH at G22 or G19, current flows into the base → transistor turns ON → motor is connected to GND → the motor runs.
PCB Assembly
The circuit was assembled on a common PCB board with a two-sided arrangement: the ATOM controller on the top side for programming and display access, and the sensors and motor driver components on the bottom side for compact wiring. The sensor section provides black/white detection to the controller, while the motor driver section controls the two DC motors based on controller outputs. This arrangement makes the robot small, modular, and easy to troubleshoot.
TYRE AND MOTOR HOLDER
I designed a simple tyre and a motor holder using tinkercad and printed it with my BambuLab A1 3D printer. I used TPU filament for theTyre and PLA for themotor holder.
After printing, I attached the tyres to the motor. Then I attached the motor holder to the downside of the populated PCB using two screws. After that, I placed the motors in the holder and secured them with some copper wires.
Since we are using pin 32 for sensor reading, we need to take the connection from theGrove socket. After taking the connection from pin32, I connected to the circuit.
PROGRAMMING
For the programming part of the project, I used UIFlow online editor, which is an intuitive block-based coding platform provided by M5Stack. UIFlow makes programming very simple and interesting because it uses graphical blocks that can be dragged and dropped to create logic, similar to Scratch. This eliminates the need for writing complex syntax, making it beginner-friendly and efficient for rapid prototyping. In this project, UIFlow was used to read the sensor inputs, process the signals, and control the motor outputs accordingly. The online editor also allowed me to test and debug the code directly with the ATOM Matrix controller. This greatly simplified the development process and helped me focus more on the functionality of the line follower robot rather than struggling with low-level coding.
To use UIflow, we need to first burn UIflow on theA tom matrix. For that, I downloaded the M5Burner from here. After installing, sign up with your email. Then connect the atom matrix to your PC, and now select the atom from the left side and select the atom matrix from the top right side, and burn it to your atom matrix.
Open the UIFlow 2.0 Web IDE. Log in using your previously used M5Stack account. Then select anew project, name the project and select the atom matrix as the device. Then you can see the coding area
From here, we can see two sections: a setup section and a loop section, just like Arduino code. We can use left-side snippets to code your logic
Here is our code setup section.This setup code prepares two pins (32 & 33) for analog input, two pins (19 & 22) for digital output, and initialises the built-in RGB LED matrix at 20% brightness. It’s basically configuring the hardware before the main program loop runs.
Begin Initialization (True)- This ensures that the setup code runs once at the beginning when the program starts.Init built-in hardware at beginning - Loads and prepares the built-in hardware of the Atom (buttons, LEDs, sensors, etc.).Init Pin 32 (attenuation 11dB, 0~3.3V) - Configures GPIO 32 as an analog input with an attenuation of 11dB, which expands the ADC measurement range up to about 3.3V
Init Pin 33 (attenuation 11dB, 0~3.3V)- Configures GPIO 33 in the same way as GPIO 32, also as an analog input for signals up to 3.3V. These two pins are used to read sensor values.Init Pin 19 (mode OUT, pull DOWN)- Configures GPIO 19 as a digital output with a pulldown resistor.Init Pin 22 (mode OUT, pull DOWN)-Configures GPIO 22 as another digital output with a pulldown.
Works similarly to Pin 19.
RGB Init (built-in) - Initialises the built-in RGB LED matrix of the Atom module.RGB set brightness (20%) - Sets the brightness of the RGB LEDs to 20% (to reduce power consumption and avoid excessive glare).
This is our loop section. This program continuously reads the IR sensors, compares their values to a threshold, and turns the motors ON/OFF accordingly. The Atom Matrix LEDs are used as a visual indicator (green = motor ON, red = motor OFF) to make debugging easy.
Step 1: Sensor Readingset left to read ADC32 - The left IR sensor is connected to pin 32. - The right IR sensor is connected to pin 33Both sensors measure reflected light from the surface (black absorbs → low value, white reflects → high value).
set right to read ADC33
Step 2: Debugging (Optional)
print left right
Displays live sensor values in the console/log for debugging and calibration
Step 3: Motor Control Based on Sensor Values
The program uses if conditions to check whether the sensor values are above or below a threshold (> 1000). Depending on this, it turns the motor pins ON or OFF:If left > 1000
Pin 19 ON → Left motor runs, and Atom Matrix shows a green LED grid.If right > 1000
Pin 22 ON → Right motor runs, and Atom Matrix shows another green LED grid.If left < 1000
Pin 19 OFF → Left motor stops. And Atom Matrix shows a red LED grid.If right < 1000
Pin 22 OFF → Right motor stops, and Atom Matrix shows a red LED grid
Step 4: Loop Update
Update
Keeps refreshing the sensor values and motor outputs continuously in real time.
How It Works in the Robot
If both sensors detect white (line present), both motors run → robot goes forward
If the left sensor sees black (off track), theleft motor stops, theright motor runs → therobot turns left.
If the right sensor sees black, theright motor stops, theleft motor runs → robot turns right.
If both sensors see black, both motors stop → robot halts.
The Editor automatically detects devices bound to your account that are online or connected via USB. now select the down right download button to burn the code.
FINISHING and TESTING
After uploading the code to the Atom matrix. I placed the atom on the PCB. Then I connected the battery to the circuit and finished everything. I added an LED on the front to avoid the friction, which will act like a castor wheel.
I made the test track using standard electrical tape.
WORKING VIDEO
PROBLEMS
- With only 2 sensors, the robot can only detect “left or right, ” not how much it’s off the line. On sharp curves, it often overshoots or zig-zags.
- Since it can’t measure error continuously, the robot keeps correcting left/right abruptly, leading to jerky movement instead of smooth following.
- If the line is thicker or thinner than expected, it struggles to stay centred.
- With only 2 sensors, it can’t decide which path to take at a crossroad or T-junction.
- If the robot moves too fast, the two sensors can’t react quickly enough to keep it stable, so it often goes off the line.
- PID control needs more sensor data (usually 3–5 sensors) to calculate theerror. With just 2, you’re limited to basic on/off (bang-bang) control.
- Small changes in ambient light or surface reflection can confuse the sensors, since there are no extra channels to confirm the correct position.
That's all about the build. Hope you got some ideas about how I made this tiny line follower robot. if you have any doubt, then you can comment or contact. thanks

_cb1jwgVyin.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)













Comments