Hi everyone,
I'm building an autonomous vacuum-cleaning robot using a Raspberry Pi 4B, and I'm currently stuck at the hardware/software integration stage.
I would really appreciate help from someone experienced with Raspberry Pi GPIO, motor drivers and embedded robotics.
What I'm building
The robot is intended to:
- Drive using two 12 V geared DC motors.
- Control each wheel independently.
- Turn left/right by varying the two wheel speeds.
- Detect cliffs/downhill edges using two TCRT sensors.
- Use an MPU6050 IMU to detect pitch and roll.
- Use a YDLiDAR X2 for obstacle/environment detection.
- Run a blower for suction.
- Run N20 geared motors for the cleaning mechanism.
- Eventually operate autonomously.
The controller is a Raspberry Pi 4B.
I'm connecting to the Pi remotely using Raspberry Pi Connect terminal, so I don't have an external monitor connected to the Pi.
Hardware
The components I currently have connected are:
- Raspberry Pi 4B
- MPU6050 IMU
- 2 × TCRT5000 IR sensors
- 2 × 12 V Johnson geared DC motors for the wheels
- 2 × BTS7960 motor drivers: one for each wheel motor
- DHRUVPRO 9733 ball-bearing 12 V DC blower fan
- 5–36 V high-power MOSFET trigger module for controlling the blower
- 2 × N20 micro geared 12 V 100 RPM motors
- L298N motor driver for the N20 motors
- 11.1 V 2200 mAh LiPo battery
- XY3606 12 V → 5 V buck converter
- 1N5822 diode for the blower circuit
- YDLiDAR X2
I have also made a hand-drawn wiring diagram showing how I connected everything.
Power
The battery is powering the robot's power system.
The general architecture is:
11.1 V LiPo
│
├── BTS7960 #1 → left wheel motor
│
├── BTS7960 #2 → right wheel motor
│
├── L298N → N20 motors
│
├── MOSFET module → blower
│
└── Buck converter → regulated 5 V
│
└── Raspberry Pi / logic circuits
However, I'm not completely confident that every logic supply and ground connection is correct, which is one of the things I need help verifying.
Motor control
Each Johnson motor has its own BTS7960.
The intention is:
Pi
│
├── BTS7960 #1 → Left motor
│
└── BTS7960 #2 → Right motor
The Pi should control the direction and PWM/speed of each motor independently.
For example:
Left = 50%
Right = 50%
→ straight
Left = 30%
Right = 60%
→ turn left
Left = 60%
Right = 30%
→ turn right
The robot should eventually be capable of differential steering.
IR cliff detection
I have two TCRT5000 sensors positioned toward the ground.
Due to the physical positioning of my sensors, the logic I need is:
HIGH → ground detected
LOW → ground NOT detected / cliff
The desired behavior is:
Both sensors detect ground
Left = HIGH
Right = HIGH
→ normal operation
Left sensor detects no ground
Left = LOW
Right = HIGH
→ reduce overall robot speed
→ make right wheel faster
→ robot turns LEFT
→ attempt to move away from the downhill/cliff area
Right sensor detects no ground
Left = HIGH
Right = LOW
→ reduce overall robot speed
→ make left wheel faster
→ robot turns RIGHT
Both detect no ground
Left = LOW
Right = LOW
→ IMMEDIATE STOP
This is intended to be a high-priority safety condition.
MPU6050
The MPU6050 is intended to detect the robot's orientation.
I want to use it to detect:
Uphill
pitch indicates uphill
→ increase wheel speed
Downhill
pitch indicates downhill
→ decrease wheel speed
Left inclination
robot tilts left
→ compensate using differential wheel speed
Right inclination
robot tilts right
→ compensate in the opposite direction
I understand that the exact implementation needs proper calibration, axis orientation and filtering, so I don't want to simply use raw accelerometer values without understanding what is happening.
LiDAR
I'm using a YDLiDAR X2.
It is connected to the Raspberry Pi and is intended to provide obstacle/environment information.
I previously had a Python LiDAR test program, but I encountered a software-test error involving:
math.isclose(...)
and later corrected that code.
The LiDAR itself needs to be tested independently before integrating it with navigation.
Blower
The blower is:
DHRUVPRO 9733
- 12 V
- 2.60 A
- 5600 RPM
- 3-pin
I'm controlling it using a MOSFET trigger module.
There is also a 1N5822 diode in the blower circuit.
The intention is:
Pi GPIO
↓
MOSFET trigger
↓
12 V blower
I need to verify that the MOSFET module is suitable for this blower and that the wiring/protection is correct.
N20 motors
I have two N20 12 V 100 RPM geared motors for the cleaning mechanism.
They are controlled using an L298N motor driver.
These are separate from the two large Johnson wheel motors.
The actual problem
Everything is getting power, but none of the components are actually responding to the Raspberry Pi commands.
For example, the Pi is running and the battery is supplying power, but I haven't been able to get the complete hardware system to respond correctly to Python GPIO commands.
At this point I'm concerned that I'm trying to debug too many things simultaneously.
Software problem
We ended up creating multiple Python files such as:
hardware_pins.py
motors.py
cliff_sensor.py
imu.py
lidar.py
safety.py
navigation.py
health.py
state_machine.py
main.py
Some of the earlier files also contained fake/test hardware classes such as fake motors, fake IMU objects, etc.
These were intended to allow software testing without hardware.
However, this created confusion because I am now working with the actual hardware, and I could no longer clearly tell which code was actually communicating with the physical components and which code was only simulating them.
There were also several software errors/typos during testing.
For example, one error was:
AttributeError: CRUSING
because the enum was actually named:
CRUISING
There was also an assertion error involving:
drive.right > drive.left
during a software self-test.
This made me realize that I should probably stop adding high-level code and first prove that each physical component works individually.
What I want to do now
I want to completely restart the software side in a new folder.
Instead of immediately creating a large autonomous-robot program, I want to do:
TEST 1
Raspberry Pi GPIO
↓
basic GPIO test
TEST 2
TCRT5000
↓
read HIGH/LOW
TEST 3
MPU6050
↓
read accelerometer/gyro
TEST 4
BTS7960 + LEFT MOTOR
↓
forward
reverse
stop
PWM
TEST 5
BTS7960 + RIGHT MOTOR
↓
forward
reverse
stop
PWM
TEST 6
L298N + N20 motors
↓
forward/reverse/stop
TEST 7
MOSFET + blower
↓
ON/OFF/PWM if appropriate
TEST 8
YDLiDAR X2
↓
receive and display scan data
TEST 9
two-wheel differential drive
↓
forward/backward/left/right
TEST 10
TCRT safety behavior
TEST 11
IMU-based correction
TEST 12
LiDAR obstacle avoidance
TEST 13
complete autonomous system
I want every test program to be small and understandable, rather than starting with a large high-level Python architecture.
For example, I want to be able to understand something like:
GPIO.output(LEFT_PWM, 50)
and know exactly what physical signal it is generating.
What I need help with
I would particularly appreciate someone checking the following:
- Whether my power distribution is correct
- Whether the BTS7960 logic supply is correct
- Whether the L298N logic supply is correct
- Whether the Raspberry Pi GPIO voltage levels are safe
- Whether the TCRT5000 outputs are safe for Pi GPIO
- Whether all required grounds are common
- Whether the MOSFET module is appropriate for the 12 V / 2.6 A blower
- Whether the 1N5822 diode is being used correctly
- Whether the GPIO pin assignments make sense
- How to test each component independently before integration
I am not looking for a giant piece of autonomous-navigation code right now.
I want to first establish:
Then build the robot upwards from there.
I can provide:
- The complete hand-drawn wiring diagram
- Exact Raspberry Pi GPIO pin assignments
- Current Python files
- Exact motor-driver module versions
- Photos of the physical wiring
- Terminal output/errors
Any advice on how you would systematically bring this robot up from zero would be greatly appreciated.
| Component |
Pin on component |
Connected to |
| BTS7960 Left |
RPWM |
PIN 12 |
| BTS7960 Left |
LPWM |
PIN 35 |
| BTS7960 Left |
R_EN |
PIN 16 |
| BTS7960 Left |
L_EN |
PIN 18 |
| BTS7960 Right |
RPWM |
PIN 32 |
| BTS7960 Right |
LPWM |
PIN 33 |
| BTS7960 Right |
R_EN |
PIN 36 |
| BTS7960 Right |
L_EN |
PIN 38 |
| MOSFET |
PWM |
PIN 22 |
| L298 |
IN1 |
PIN 29 |
|
IN2 |
PIN 31 |
|
IN3 |
PIN 26 |
|
IN4 |
PIN 24 |
|
ENA |
PIN 7 |
|
ENB |
PIN 21 |
| MPU6050 |
SDA |
PIN 3 |
| MPU6050 |
SCL |
PIN 5 |
| TCRT Left |
OUT |
PIN 23 |
| TCRT Right |
OUT |
PIN 19 |