Before connecting power to your PCB please double check all connections!

We will build 4wd car – the steering will be similar like in a tank – to turn one side of wheels will rotate with different speed than other. At the car will be placed camera on special holder where we can change camera position. The robot will be controlled by web browser (chrome or firefox at desktop, or firefox at mobile phone), at the browser, We will get camera video ( with only 200ms latency), and from the browser, we can control the car movements and camera position. To make communication easier I’ve used system, there is also working out of the box controlling of this kind of car, So You don’t have to write Your own code, but of course You can modify scripts add new possibilities etc.

What is needed:

  • Preview
    • Raspberry PI Zero W
    • Dedicated camera
    • Adafruit 16-Channel 12-bit PWM/Servo Driver – I2C interface – PCA9685 or its clone

    • Two servo mechanisms compatible with the camera holder
    • Camera holder

    • Batteries – In tutorial two possibilities of connection
    • H bridge TB6612FNG, to control wheel speer
    • PCB eagle files It is easy to make it thermal transfer method
    • DC-DC Step Down Converter Module DC

    • Robot case:



Raspberry pi control servo mechanism through PWM module and motor speed by H bridge which is connected to RasbperryPi pins, PWM input to H bridge is generated by the same module I used for servos (which parts I mention above no logic converters are needed )



And final results (I order it from allPCB but You can make it by the thermal transfer method, it’s quite easy since paths are fat)

And other side with outgoing connections

  1. PWM input for drive motors Should be connected to PWM module 15’th and 16th pins

  2. Power input for drive motors (check what maximum voltage your motors can work with)
  3. Power for RasbperryPi and PWM module – have to be exactly 5V
  4. Drive motor outputs (there are two outputs because we will pair drive motors )
  5. Servo Mechanisms power – also You have to check what voltage is good for them
  6. Jumper its present power from 5th input will power also drive motors so no need to connect anything to input 2
  7. Jumper if present RasbperryPi will be power from 3rd input – before put jumper here check if connections are OK – You don’t want to burn your RPi
  8. Lets solder here cables since we don’t need logic converters

How it’s going to work

At RasbperryPi there is python script which uses two libraries


  • import RPi.GPIO as GPIO – for pins 25-AIN1, 8-AIN2, 24-BIN1, 23-BIN2  (BCM notation) which are connected to H bridge:
    • A/B IN1 A/B IN2 PWM A/B Wyjście silników
      H L  > 0 if more PWM fill motor is rotate faster – counterclockwise
      L H  >0 if more PWM fill motor is rotate faster – clock-wise
      L L short break
      H H short break
      H/L H/L L Stop
  • import Adafruit_PCA9685 for PWM module

Rpi pins are connected as follows 25-AIN1, 8-AIN2, 24-BIN1, 23-BIN2  (BCM) and control mode of H bridge( forward, backward, stop, short break). H bridge needs also two PWM signals so we can control speed or motor rotation. Because at the project we already have PWM controller (used for servo) we will use it also to generate PWM for H bridge.


PWM module uses I2C communication protocol. I’ve used working out of the box Adafruit_PCA9685 . library

Car Assembling

We will start from screw drive motors to car case. Left/Side side motors connect together, and both pair, connect to some power cable which later will be connected to PCB. IMportant note while connecting motors wheels at each side have to rotate at the same direction.


all together


1 Option AA recharge batteries

I’ve used ten of them with 5th in every nest :

I’ve got stable 5v power for my PWM module and RPi and about 7volts for servo and drive motors (You have to check what is the maximum voltage for your servo and motor )

To the batteries set I’ve connected jack female socket which I’ve made by blending some plexiglass

batteries connection:


red = Jumps

2 Options Li-Po 7.2V batteries

In this case we got 3 voltages – 5v For Rpi and module, 6V for servos and directly from batteries 7.2 volts for drive motors. I had to use two step down modules

red= jumper

Option 2 with  LI-PO is better:

  • Batteries have bigger capacity – the car will drive longer
  • Bigger voltage for drive motors – the car will drive faster
  • Less probability that after drive motors start to locate we could have huge voltage drop and RPI restarts.


Of course, RPi and PWM module are connected by sockets

and extra Spacers for PWM module

And final form 🙂   

This PCB I’ve put at small Plexiglas bridge

At the end we connect the camera, here  Is written how to center servoMechanisms before mounting into camera holder, but the shortest way is to gently manual check maximum rotation position and set it at center position. This centered servo mechanisms we put into camera holder at center position ( camera is pointing forward like at the photo)

Few photos of final car: configuration

At this tutorial, i will just show step by step what should be done to make car driving ( here You will find more details)

  • Sing up – after signup You will be automaticly sign-In
  • open Token tab at the left, then click “new token” provide some name and click OK, We just created new token:
  • in this example, token value is:  ~1_&p@+BNnZ@A+x8 ( yours will be different 😉 )


  • Instalator will ask us some questions for all we response [Y]es and confirm by [enter]
  • when installation will ask for token we paste (shift+insert) token copied from the application and  Enter
  • the name for example Rpi
  • deviceId 1 Enter
  • after installation – run program

Lets go back to

At devices tab we will see our connected RPi ( green link icon means RPi is connected right now)

Lets add car script:


after script is added we can see it at devices tab under RPi, and there should be also green link icon

OK now lets add webpage to control devcie

New -> WebPage

Now at webpage source (index.html) we need to provide python script deviceId, so webpage “knows” where to send control messages  :

at my case device id is “2”


edit index.html:

change :


and open webpage at new tab

Camera configuration:

When we move mouse at video area camera should change position, and it should work excatly like in FPC games


 when the mouse cursor is at the video center camera should look exactly straight ahead, probably it’s not so let’s configure camera position

If we mouse move right to left and camera move bottom-up we have to flip servo mechanisms cables conencted to PWM module

Setting camera center position is made by changing script properties

at my case center position is 560 and 430 and range of movements is for both axies 200

You have to experiment wiht this numbers so You get camera position center and smoth movements, If You used this tutorial jsut copy pasted given values


If u pressed up arrow at the keyboarg gagues should change positions and car should drive. If You press “up” arrow and car is turning then You have to add, remove minus at these palces:


Its because You had several way of connecting motors, for example your 1-2 cables could be flipped,

Becasue i have no possibility to change cables positions I choosed adding minus/plus at the script


After this operation after hit “up” arrow car should drive ahead and down arrow car should drive backward.

Now turning – hit left arrow if car is turning right You have to flip cables:

If You solder this cables You can change it at script.js

just change order of sending motors speed, before:


and now You have to play with minuses like one step before to get it working corectly ;).

As You probably noticed after hit up arror car is not driving with full speed to make car move faster jsut fast release up arror when its in maximum position and press and hold it again – this is feature not a bug 😉


How is it working

Web page is sending 9th byte message messages to python script in format:

  • 1 byte one byte integer value 1
  • 2 bytes integer X camera position
  • 2 bytes integer Y camera position
  • 1 byte integer left motor mode (3= backward, 1= forward, 2=stop)
  • 1 byte  integer left motor speed
  • 1 byte integer right motor mode (3= backward, 1= forward, 2=stop)
  • 1 byte  integer right  motor speed

sending message is made here (script.js):

and python script read this message and based on that set up needed values (

class functions description here

You can play with this code 🙂

Tablet, mobile steering

We add new webpage excatly as we did previous time but now we choose template car4wdMobile

Next, we configure everything in script.js as we did for desktop control webpage

The message format is exactly the same so we don’t have to change script.


Instead of  login to your account from mobile just scan QR anymous url

details of QR here

If Your mobile control works when RPi and mobile is on the same wifi but doesn’t if You use mobile internet then You have to add turn server, how to do that I’ve written here


at circle 1 we place left thumb, at 2 right – don’t have to be exactly at this points – webpage will set zero position just after you touch screen, and by moving your thumbs (left driving, right camera position ) You can control your car


I hope You liked this tutorial, as I wrote before at this tutorial is more details about how it works under the hood