Skip to the content
2 layers90 × 137.5 mmPcb main board, the printed circuit board in 3D

Pcb main board

ghemyn/picar1

Car with autonomous and remote-controlled capabilities using the Raspberry Pi 5

Size
90 × 137.5 mm
Copper layers
2
Thickness
1.6 mm
Parts
76
Nets
45
Pads
222
Tracks, vias
322, 64
Pours
2
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
28 Apr 2025
Updated
24 Jul 2026

Overview

Pcb main board is an open-source printed circuit board by ghemyn, from the ghemyn/picar repository on GitHub, published under the MIT licence. It is a 2-layer board of 90 × 137.5 mm with 76 parts on 45 nets, routed with 322 tracks and 64 vias.

It is built around the MP2338GTL-Z and SMBJ15A. Its parts include 27 capacitors, 24 resistors, 8 connectors, 4 ICs and 2 diodes. It belongs with the RISC-V boards of this library.

Main components

2

README

README.md

picar

Car with autonomous and remote-controlled capabilities controlled by Raspberry Pi 5 and a CH32V003 microcontroller. Features a custom made mainboard PCB responsible for controlling motors, servos and delivering power to the RPi 5.

It is capable of real-time remote control with a gamepad (e.g. XBox One gamepad) alongside a live WebRTC stream from its camera. Moreover, simple autonomous driving is possible by following an RGB tracking marker.

Version 3 Early (still the old frame from V2)

picarV3early1 picarV3early2

PiCar with the tracking marker next to it

Future ideas

  • Add a ToF sensor and use it in tandem with the DepthAnything V2 depth estimation model to acquire real (approximated) depth information from the camera.

Hardware

  • Battery pack composed of 3x 18650 cells connected in series. It has both XT60 connector for the main power and 4-pin JST-XH used for balancing.
  • SG92R micro servo used for steering
  • Raspberry Pi 5 8GB
  • Raspberry Pi Camera HD v2 8MPx
  • Custom PCB mainboard responsible for controlling motors, servos and delivering power to the RPi 5. (More on that below)
  • Custom 3D-printed frame and steering system (files available in the "designs" directory)
  • 4x 60x8mm black Pololu 1420 wheels
  • 2x 6x13x5mm bearings for the front wheels
  • 2x N20-BT07 micro 100:1 320RPM 12V motors
  • M3 screws used for assembling the frame and wheels together

PCB mainboard

schematic

/pcb_main_board/pcb_main_board_schematic.svg

render

/images/pcb_main_board1.png

On-board microcontroller

ch32v003

CH32V003 MCU is the main controller of the whole board. It is responsible for controlling the motor drivers, servo motors and monitoring the battery voltage. It communicates with the Raspberry Pi 5 over I2C.

Battery to RPi 5 voltage step-down

mp2338

The battery input voltage is first filtered by the input low-ESR capacitor and capped to 15V by a SMBJ15A TVS diode. Then the MP2338 IC is used to reliably step-down the battery voltage from 9V-12.6V range to ~5.1V that is then connected via a USB-C cable to the RPi 5. The MP2338's GND pin is connected to wide copper traces with vias in order to improve cooling.

Motor control

motors

TB6612FNG IC is used to drive both of the main motors. The IC logic is driven by PWM signals generated by the on-board microcontroller. The PWM frequency can be adjusted from the software layer if the user wants to prioritize peak power or to minimize the audible switching noise. The lower the frequency, the more efficient the motors are, but the louder they become.

Servo control

servo

The mainboard is capable of running 4 separate hardware PWM signals at once which are generated by the on-board microcontroller. The servo motors are powered with 4.8V generated by another MP2238 IC configured in the same way as the other one used for powering RPi 5, except for the output voltage. The servo section also has a 3-pin header for each signal channel in order to simplify the connections. There are more servo channels than are currently needed for future-proofing reasons. e.g. allowing the camera to have adjustable yaw and pitch in the future.

Wheels

The front wheels are fastened to their mounts with short M3 screws. Those mounts then clip into the ball bearings, working similarly to LEGO Technic connections. A pin with the correct diameter and side cuts is pushed into the bearing hole and holds firmly enough for normal operation. The rear wheels are press-fitted onto the motor shafts:

frontandback

Front wheel assembly disassembled in Fusion 360:

frontwheelassembly

Software and control

Frontend

PiCar can be controlled through a simple Websockets-based web interface (/car/software/index.html). When you run the Python "Remote Control" main loop an HTTP server starts up and reveals the visual interface at http://{raspberry_pi_5_ip}:8000. There are two sliders that control it but the better (and way cooler) option is to use a gamepad and control the car this way. The website automatically detects connected gamepads and lets the user steer by using both triggers for accelerating and braking and the left thumbstick for steering. It is also possible to set the motors PWM switching frequency.

frontenddemo

There also is a viewport for watching the live feed coming from the camera connected to the RPi 5. The stream source must be a WebRTC source which can be created easily by using MediaMTX. You can find the working mediamtx.yml file I use to enable the stream at /car/mediamtx.yml. Once mediamtx starts with my provided config, the camera can be accessed by connecting via WebRTC to {raspberry_pi_5_ip}:8889/rpi.

Vision

Autonomous driving, for now, is a simple computer vision algorithm that searches for a special marker with three key colors: red, green, and blue on the live feed streamed from the Raspberry Pi Camera HD v2 8MPx.

The camera feed is first filtered bilaterally to remove small details and noise in the subsequent marker search. Then gamma is adjusted to increase contrast, and the resulting image is binarized so that the SimpleBlobDetector from the OpenCV library can detect three circles. Finally, the algorithm checks whether the circles are "inside" the potentially found marker—i.e., whether they are not shifted from the averaged center by more than one standard deviation. If they are not, we can be certain that the marker has been found.

Below is a visualization of how the marker is seen by the algorithm:

MarkerDetection

When the marker is found, the vehicle drives forward and turns so that the center of the marker aligns with the center of the camera's view. This is sufficient to effectively track the marker.

Future Vision Enhancement

I plan to use a ToF distance sensor in tandem with the computer vision model DepthAnythingV2, which estimates depth using a single camera. This combination will allow me to acquire approximate (yet sufficiently accurate) distance information of everything visible in the front camera. This data will enable shape detection by contours and autonomous obstacle avoidance.

Firmware

The CH32V003 microcontroller runs a firmware that acts as a PWM and motor control interface for the Raspberry Pi 5. The firmware exposes a register-based interface over I2C using slave address 0x17, allowing the RPi to elegantly control all aspects of motor and servo operation.

I2C Communication Protocol

The firmware operates as an I2C slave that receives write-only commands structured as [register_id, data_low, data_high]. Each register controls a specific aspect of the system:

RegisterPurposeRange
1TIM1 (servo) frequency1 - 48000 Hz
2TIM2 (motor) frequency1 - 48000 Hz
4-7Servo CH1-CH4 duty cycle0 - PWM_PERIOD(1000)
10-11Motor PWM (right/left) duty cycle0 - PWM_PERIOD(1000)
12Motor direction controlBit 0: DIRF, Bit 8: DIRB

Building the code

RPi 5 Python

Configure the virtual environment if you need and run pip install -r requirements.txt while being in the /car/software directory to download the necessary packages. Downlaod opencv as a standalone package. Once everything is downloaded, run python main.py and it should work fine.

Enabling the necessary RPi 5 options

To make I2C communication work properly, enable it either with the raspi-config command or by manually adding the necessary lines to the /boot/firmware/config.txt file:

text
dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=80000 # or any other as you wish
dtparam=i2s=on

Also enable the camera detection in the same way. Here is the line for /boot/firmware/config.txt:

text
camera_auto_detect=1

CH32V003 C Firmware

Downloading and building it through MounRiver Studio IDE is the easiest route to go. This repo already has project files that work out of the box when you open them with the IDE. Just press F7 and it should build perfectly fine.

Flashing it

You'll need a WCH LinkE programmer in order to flash the firmware to the chip. Once you have it, connect GND to GND and the SWDIO pin to the chip's SWIO pin according to its datasheet (It's pin PD1 for CH32V003A4M6). The chip must be powered either from the programmer's voltage pin or externally during flashing.

Now go to MounRiver Studio IDE and press F7 to build your project and then F8 to flash it having the WCH LinkE programmer plugged into your computer at the same time, note that flashing your code does not rebuild it automatically, you have to remember to press F7 each time.. You can also change the flashing configuration but it's almost always good to go by default. (called Download Configuration):

wchlinke

Do not press or hold the reset button during flashing (the NRST pin)

Archive

Take a look at the PROGRESS.md markdown file to see how the project evolved over time.

Parts

76
QtyValueFootprintReferences
60.1uFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC4, C7, C10, C13, C21, C23
610uFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC2, C3, C6, C9, C19, C20
510kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR4, R6, R7, R11, R12
422uFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC14, C15, C22, C24
475kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR2, R10, R13, R23
3100kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR1, R9, R22
3100nFCapacitor_SMD:C_0805_2012MetricC11, C18, C25
210kResistor_SMD:R_0805_2012MetricR5, R17
218kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR8, R14
222nFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC5, C26
2470uFCapacitor_THT:CP_Radial_D8.0mm_P3.50mmC1, C16
25.1kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR19, R21
251kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR3, R24
26.8uHInductor_SMD:L_Chilisin_BMRF00101040L1, L2
2MP2338GTL-ZPackage_TO_SOT_SMD:SOT-583-8IC1, IC2
10.47uFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC8
110uFCapacitor_SMD:C_0805_2012MetricC12
112kResistor_SMD:R_0805_2012MetricR16
11kResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR20
1220pFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC17
1330pFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC27
13kResistor_SMD:R_0805_2012MetricR18
1680Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR15
1BATT+Connector_Wire:SolderWire-1sqmm_1x01_D1.4mm_OD3.9mmH1
1BATT-Connector_Wire:SolderWire-1sqmm_1x01_D1.4mm_OD3.9mmH2
1CH32V003AxMxPackage_SO:SOP-16_3.9x9.9mm_P1.27mmU4
1Conn_01x02_SocketConnector_PinSocket_2.54mm:PinSocket_1x02_P2.54mm_VerticalJ3
1Conn_01x03_SocketConnector_PinSocket_2.54mm:PinSocket_1x03_P2.54mm_VerticalJ1
1LEDLED_SMD:LED_0805_2012Metric_Pad1.15x1.40mm_HandSolderD2
1LOGOCustomIcon:PiCarIconG***
1MOT_ATerminalBlock:TerminalBlock_MaiXu_MX126-5.0-02P_1x02_P5.00mmJ7
1MOT_BTerminalBlock:TerminalBlock_MaiXu_MX126-5.0-02P_1x02_P5.00mmJ8
1MountingVia1MountingHole:MountingHole_3.2mm_M3_Pad_ViaH5
1MountingVia2MountingHole:MountingHole_3.2mm_M3_Pad_ViaH6
1MountingVia3MountingHole:MountingHole_3.2mm_M3_Pad_ViaH7
1PWM1Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ2
1PWM2Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ4
1PWM3Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ5
1PWM4Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_VerticalJ6
1RPi5GNDConnector_Wire:SolderWire-0.5sqmm_1x01_D0.9mm_OD2.3mmH3
1RPi5VCCConnector_Wire:SolderWire-0.5sqmm_1x01_D0.9mm_OD2.3mmH4
1SMBJ15ASMBJ15A:DIOM5436X244ND1
1SW_PushButton_Switch_THT:SW_PUSH_6mmSW1
1TB6612FNGPackage_SO:SSOP-24_5.3x8.2mm_P0.65mmU3

More from ghemyn/picar

2
  • 2 layers85 × 56 mmPcb main board, the printed circuit board in 3D

    Pcb main board

    ghemyn/picar

    Car with autonomous and remote-controlled capabilities using the Raspberry Pi 5

    72 parts1MIT
  • 2 layers30 × 25 mmServo controller, the printed circuit board in 3D

    Servo controller

    ghemyn/picar

    Car with autonomous and remote-controlled capabilities using the Raspberry Pi 5

    8 parts1MIT

Similar boards

  • 2 layers31.1 × 94.2 mmMeshtasticStick, the printed circuit board in 3D

    MeshtasticStick

    Oliver0804/MeshtasticStick

    80 parts8
  • 4 layers63.2 × 49.3 mmRiMon, the printed circuit board in 3D

    RiMon

    RafaelEstevamReis/MonitoramentoRios

    Repositório do projeto de monitoramento de Rios

    58 parts2MIT
  • 2 layersPowerboard, the printed circuit board in 3D

    Powerboard

    Adamh-Tech/PCB

    The hand

    44 parts
  • 2 layers118.7 × 168.3 mmDMClockPanel, the printed circuit board in 3D

    DMClockPanel

    danielpchamoun/DMClock

    207 parts
  • 4 layers55 × 60 mmPiComputeModuleBreakout, the printed circuit board in 3D

    PiComputeModuleBreakout

    darren4141/darrenliusite2

    check out my website/portfolio @ https://darren4141.github.io/darrenliusite2/index.html

    131 parts
  • 4 layers36.3 × 38 mmLtwoo pcb, the printed circuit board in 3D

    Ltwoo pcb

    dmitrodem/ltwoo_pcb

    LTWOO ERX/ER9 Rear Derailleur PCB

    113 parts
  • 2 layers105.7 × 50.8 mmObd xp, the printed circuit board in 3D

    Obd xp

    MustSeeMelons/can_esp32

    The loose wire goes to 3rd pin from the bottom (DTR?).

    69 parts

Questions

How big is the Pcb main board PCB?

It measures 90 × 137.5 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Pcb main board use?

76 parts, built around the MP2338GTL-Z and SMBJ15A. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Pcb main board KiCad files?

From the ghemyn/picar repository on GitHub, at the commit this page was made from: the board is pcb_main_board/design/pcb_main_board.kicad_pcb and its schematic OLD_pwm_board/design/servo_controller.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Pcb main board design in my own project?

Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).