Building a robot car

Roman Marakulin
7 min readFeb 18, 2023

--

Choosing a model

For almost an eternity I wanted to build a small robot. The robot, that you can manipulate or that can be intelligent enough to do some useful work.

After several past projects I have a raspberry pi available (a small single-board computer, from the image below), thus I’ve decided to quickly check what marketplaces can provide on this occasion. Although you can build a robot Arduino based, I was looking for something, that you can build on top of a raspberry pi specifically.

Raspberry pi board

When you start googling, it’s hard to stop scrolling. There are a great deal of options. At first, I wanted to build a robot from scratch — start with a design, procure detail after detail, find a workroom to produce a metal or plastic case, but instantly discarded this idea. Without any doubt, you could buy sets of parts, chips, but a path to a finished and complete result would be unmanageable — I was afraid of abandoning the project. As an introduction, I’ve just wanted to control and tweak a robot a little with a focus on programming, not searching for the right wheels or bolts and nuts.

I’ve chosen to stick with kits, where everything is already carefully selected for you and each set comes with a manual. All you need is to put it all together. What could go wrong, right?

There are 2 models that I like (by a description, of course) and that were not so expensive: a spider and a car. I ended up buying the last one. The spider (and all spider-like robots) are interested only on account of a gyro sensor. Watching several clips, I’ve found out that the spider is quite slow and noisy. Moreover, a body is build from acrylic plates (as for the car) and it lowered my expectations even more. Hence, I’ve decided to start with the car and to create a spider from scratch (and from materials that I want), based on the past experience afterwards.

A manufacturer (Sunfounder) offers 3 types of the car:

  1. Picar-S (goes with 3 modules: line following, ultrasonic sensor, light following)
  2. Picar-V (has only a USB webcam)
  3. Pimobile (with line following, ultrasonic sensor)

I already have a camera for raspberry pi, that I could attach later.

Raspberry pi camera

Therefore, I’ve decided to go with the first option (and it was the cheapest one).

Assembling

A delivery date has come and I finally got a package. Everything was well packed in a box with an instruction.

Robot car kit

To be honest, I expected, that the assembling was going to be harder — some parts are missing, some are broken — you know, how it usually goes, but surprisingly, everything was there and undamaged.

All parts together

One thing, that I’ve noticed — because body parts (the case, in particular) were built from plastic, they were bending during assembly. It isn’t critical, but not all parts fit perfectly together. Luckily, the kit went with several spare parts, therefore I could experiment with them. The most important thing is to pay attention to joints, especially for rare wheels. At that point I thought about replacing them with more reliable ones — from metal or, at least, from a more durable plastic.

All in all, it took me 2 evenings to build the whole car and start working with code (and even re-built a part of the car, because I didn’t set up wheels properly at first). Thereupon, I’d rate this kit as 2 out of 5 in complexity.

I was especially disappointed that they didn’t put a proper jumper wire (200mm 5-Pin) — the long one in a black wrap on the image. A problem with it is that pins on one side are not coupled together, but free. Therefore, the mount on the board itself is fragile and sometimes rear wheels refuse to change a direction of rotation and you need to tweak this wire a little.

Batteries

two 18650 batteries

Be prepared to search for batteries. The manual ask you to buy two 18650 batteries, which is not a trivial task. They are not sold in every store — I found them in an electronic watch store. I’d advice to buy rechargeable batteries with a charger, because they drain constantly.

I expected to replace them with more common, AA batteries, but imagine how the car would look like with 5 AA batteries underneath.

Installation

Until now everything was simple and in accordance with the manual.

From this moment I don’t like how the guide navigates you through a setup of OS for a raspberry pi. It looks to me overcomplicated (especially if you don’t have a screen). I’d propose just to download the latest version of Raspberry Pi Imager from the raspberry pi official site and inside it, while installing, you can choose OS, such as Raspberry PI OS (32-bit).

Raspberry Pi Imager menu

Besides, there is a gear icon “Advanced options”, where you can set up username and password for an SSH access and even configure an internet connection (wireless LAN):

setting up username and password

After you install the OS, you can ssh into the raspberry pi and clone, as the guidebook mentioned, the Sunfounder git repo.

The repo has several examples of programs (.py scripts) how you can control the car. Understanding of these scripts helps to write your own loops for car movements.

Ultrasound module

As I mentioned above, my version of the car went with 3 modules:

  1. Light Follower
  2. Line Follower
  3. Ultrasonic Avoidance

These modules work as eyes and help the car to navigate in space.

I was especially interested in the Ultrasonic Avoidance module, that works very simple — it registers reflections from surfaces of emitted ultrasound.

HC-SR04 ultrasound module

There are a speaker on the left and a receiver on the right. The speaker emits an ultrasonic wave (with a speed ~ 343 m/s, depending on the temperature), it reflects from an obstacle and returns to the receiver. Knowing time and speed you can easily calculate the distance to the obstacle.

The ultrasound module that I got is not precise and has an error in 2–5 cm, which is acceptable, but I’d like it to be better.

When everything was set up, I ran the provided script ultra_sonic_avoid.py and.. I was disappointed. It worked, in general, but because of a logic how to behave when an obstacle is near, the car stuck a lot and sometimes didn’t see obstacles right in front of it. I observed, that a distance can jump to very large and unrealistic numbers, such as: 10 cm, 12 cm, 15 cm and then, suddenly, to 7 m. According to a manual for HC-SR04 module, it cannot measure such a long distance — only up to 4 m (it wasn’t specified which module was used in the kit, but I highly doubt, that it differs radically). Moreover, there is no compensation for such jumps — the script doesn’t take into consideration previous distances.

As you can clearly see, there is a room for improvement.

Programming

In order to get hands dirty, I’ve decided to build a simple client/server app to control the car from my laptop using a keyboard. It supports actions, such as turn left/right, go forward/backward from a keyboard in realtime. You can check the code on github (client and server .py scripts).

Also, I’ve decided to add a feature — turn on/off the ultrasound module to ‘see’ obstacles. This way, it helps to avoid collisions with walls, boxes, while driving manually.

Furthermore, I recorded a video how the car drives (controlled from a laptop) and avoids obstacles — the car stopped right in front of the wall automatically (by detecting an obstacle with the ultrasound module).

Conclusion

It was my childhood dream and only now I had time and a strong desire to bring it to life. It was fun to play around.

In general, I wish the parts were more durable and modules more accurate, but it’s just a simple kit, you cannot require more from that.

All in all, if you are interested to take a shot with it — it’s a nice toy and works as a gently introduction to robots and programming. Don’t expect too much of it and be prepared that there is a possibility that some parts you will have to replace.

As for me, now I want to increase complexity - attach a camera and control the car using a bluetooth keyboard.

Tell me, if you did something similar in the past and how you use it now. It would be interesting to see, what could be applications of them, besides being just a toy.

--

--

Roman Marakulin
Roman Marakulin

Written by Roman Marakulin

I write about Technologies, Software and my life in Spain

No responses yet