Let Raspberry Pi Robots Follow Their Own Voice (Part 5)

As a further feature, we now want our little robot to follow the sound of our voice. If the mode is activated, the robot should automatically navigate in the direction from which the call was made.

There are also small analog sound detection sensors, which are read out via an MCP3008 ADC converter and then the Raspberry Pi robot steers accordingly in this direction.

As with most of the previous tutorials on the Raspberry Pi robot, you can skip these or adapt them if you want your robot to have different functionality.

Required Hardware Parts

If you want to recreate this tutorial, you will need the following components:

Otherwise, hot glue continues to make assembly easier.


Construction and Wiring

Raspberry Pi MCP3008 Pinout

The 8 channels that can be read out analogue are located on the left side of the MCP3008.

First, we connect the sensors. To do this, three jumper cables must be connected per sensor. If your sensors have 4 pins, you only have to connect VCC, GND and A0. Now the modules can simply be glued to the body. Before you finally fix it (with hot glue or similar), you should first find the best position (more on that later). I connected a sensor in the front, as well as one on the right and one on the left. Other sound detectors, e.g. to be attached at the rear or in a 45° position.

Raspberry Pi Robot Sound detection

Next up is the MCP3008. Communication takes place via SPI, we only get the 3.3V voltage from another, free pin:

RaspberryPi MCP3008
Pin 17 (3.3V) Pin 16 (VDD)
Pin 17 (3.3V) Pin 15 (VREF)
Pin 25 (GND) Pin 14 (AGND)
Pin 23 (SCLK) Pin 13 (CLK)
Pin 21 (MISO) Pin 12 (DOUT)
Pin 19 (MOSI) Pin 11 (DIN)
Pin 24 (CE0) Pin 10 (CS/SHDN)
Pin 25 (GND) Pin 9 (DGND)

On the other side are the 8 channels to which analog sensors (data or A0 pin) can be connected. We connect the front sensor to CH0, the right sensor to CH1 and the left to CH2. The VCC pin of all three modules is also connected to 3.3V and GND to a GND connection of the Raspberry Pi.

The structure (including our previous connected modules) looks like this:


MCP3008 ADC Converter

The Raspberry Pi cannot easily read out any analog values. Therefore an ADC like the MCP3008 is necessary. In a previous tutorial, I described how an ADC works, including the necessary installations. If an analog-to-digital converter has never been used, we recommend reading this tutorial. Otherwise, you can simply continue here.

So we create a new file in the folder with our other Python Robot files, which contains a class for the analog-to-digital converter:

sudo nano MCP3008.py

Now you only have to save (CTRL + O) and exit the editor (CTRL + X).


Expanding the Code

In our robot.py file, we first import the created file:

At the end of the class, another function must also be created, which can be used to respond to voice recognition. So let’s add the following code:

You can experiment with the threshold values (the volume at which the reaction occurs). Since the motors are quite loud, I set the threshold for the side microphones higher. As soon as you have found a good position (or adjust the threshold values accordingly), the sound detectors can also be attached to the body.


If the file is expanded accordingly, we can run a small test. To do this, we open the Python console (sudo python) and enter the following code:

Unfortunately, the noise sensors are not too precise, which is why following the voice does not always work optimally – as a gimmick, it is certainly a nice thing.


With the help of the infrared control, which we created before, we can e.g. specify a button that turns on the voice follow mode.

With a real microphone, you could even make the Raspberry Pi robot respond to voice commands. Only certain code words would have to be reacted to (forwards, right, left, stop, etc.) and the corresponding actions called.

In the next part, we let the robot be controlled remotely via Xbox 360 controller/joystick.

One Response

  1. Why do you title this “follow their own voice”? They don’t follow their OWN voice — they follow someone else’s voice.


Leave a Comment

Your email address will not be published.

Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!