Hello! Welcome 🙂
Today I would like to show you how to build a straightforward project which will imitate a police car with light and sound.
I want the projects here to be fully aligned with KISS policy – so I’ll Keep It Simple…
But then, I’ll extend the project into another one:
Fake TV Simulator – Turning police car into an anti-theft toy to discourage intruders/burglars
So let’s start with this one!
My Gear
My gear for this project includes:

2 Smart Bulbs
I’m using Yeelight LED BULB II (Color), and I can strongly recommend them. The control is convenient, deployment is effortless, and I believe they are trustworthy.

1 Bluetooth speaker
can be any, but I got for one
of my many journeys, JBL GO. The quality of the sound
is good, and the battery
is durable.

Raspberry PI 4B
Last but not least – I need some platform to run this project. It’s unnecessary for this one, but it will be mandatory for this one presented in the introduction, so setting it up on this level will save some time in the future.
So, my whole set looks like this:

RPi – prerequisites
As promised, I will use RPi as a platform to run the whole code in this project. So I assume that your RPi is appropriately configured, it’s up-to-date, etc.
I don’t want here to waste time describing how to do it; it can be easily found on the Internet 😊
I will use RPi 4B to connect to my Wi-Fi, which I can control via VNC protocol, so the whole configuration and screenshots show this perspective.
However, if you don’t want to use RPi to emulate my project, it can still be done on a regular PC.
Bulbs Preparation
I don’t want to get through the installation in detail – this is elaborated in the instruction, and the wizard is intuitive. But, just a quick overview:
- Before you start, place the bulb into the proper lamp (with E27 socket)
- Download the Yeelight app on your Android/iOS device from the appropriate store.
- Turn Wi-Fi and Bluetooth on
- Go to Devices, then click Add Device and select the proper device.
- Then follow the instruction (for the time being) to turn on a light for 2 seconds, then turn off for 2 seconds and repeat it four times. After that, your light bulb should be restarted and switched on with white light.)
- Press Next, Find your Lightbulb on the list, and finish with the wizard.
- Check if the firmware is up-to-date. If not, update it.
So after these easy steps, my setup for two bulbs looks like this:

The final step for using Bulbs in this project is to turn ‘developer mode’ on, called ‘LAN Control.’ To do this:
- Go to your devices page
- Open context menu from the left and press ‘LAN control’:

- Switch it on like this:

Now your Bulbs are correctly installed and if you are curious about them, spend some time to discover their options 😉
Connecting the speaker
To connect the speaker to my RPi, I will use the default Bluetooth manager. To do that for the first time, I need to:
1. Click the Bluetooth symbol and Turn On the Bluetooth
2. Then click ‘Add Device….‘

- The adding device window will prompt.
- I’ve found my device on the list (mine is JBL GO), so I select it and click ‘Pair.’

- After a while, I got the confirmation that the Pairing was done correctly:

- Now my devices are paired. Next time when I want to use the speaker, I will start with this step.
- To connect to the speaker (or any other Bluetooth device), we need to click on the Bluetooth button, then select the name on the device and click ‘Connect’

- Sometimes I got ‘connection failed’ message:

- To work around, I will use the audio menu to connect the speaker:

- I’ve heard the ‘beep’ meaning that the speaker is connected, and the icon in the Bluetooth manager changed icon:

I always check with any YouTube clip to double-check if everything works perfectly. If it works, we are ready to go further.😊
If you are not using RPi to recreate this code, please connect your Bluetooth speaker to your environment and make sure it works properly. 😉
Connecting the Bulbs
To control our bulb, using Python yeelight library is required.
So with a pip, we need to use:
pip3 install yeelight
Now we need to discover the IPs of our bulb. We can do it by:
- checking manually in bulb’s settings

- or we can use yeelight library
from yeelight import discover_bulbs
discover_bulbs()
Which is not always working correctly…
Once found, we can check if we can steer our Bulbs with python code.
Here is a simple example:
from yeelight import Bulb
from time import sleep
bulbR = Bulb("192.168.0.157") #make to provide correct IP address
bulbL = Bulb("192.168.0.45")
bulbR.turn_on()
bulbL.turn_on()
sleep(5)
bulbR.turn_off()
bulbL.turn_off()
If you managed to turn off the lamps for 5 seconds and then they turned off, everything works like a charm 😉
Note: Interacting with Bulbs is done via a cloud provider. They can only accept 60 quotes per minute. It’s going to be important in the final part.
Playing the sound
I decided to use the python-vlc library to play the sound from many others because the vlc player is already preinstalled in my Raspbian distribution. After reviewing some manuals, it was one of the top up-to-date solutions.
I was also considering using pygame, a lovely library designed for games development, but installing and importing whole sets of modules designed for writing video games would be taking a sledgehammer to crack a nut.
So let’s use python-vlc. Sticking to the instruction, we need to start with installing the module:
pip3 install python-vlc
Then I’ve found a brief article about: How to Play Audio With VLC In Python
While I would like to ’emulate’ Police Car, I need a good sound. I’ve found a few of them on https://freesound.org, and the police2.wav created by guitarguy1985 appeared the most for me. You can find it: Here, and yes, login to download is required, but if you don’t like it, you can use a different sound instead. Simple code to play the .wav looks like this:
import vlc
file= 'police2.wav'
player = vlc.MediaPlayer(file)
player.play()
Sometimes we can get strange error code to look ugly, but then the code is still working (vlc plays the file):

I’ve found a small workaround by changing the vlc verbosity to -1. Now the code looks like this:
import vlc
import os
os.environ['VLC_VERBOSE'] = str('-1')
file= 'police2.wav'
player = vlc.MediaPlayer(file)
player.play()
Getting it all together
My goal was to ‘act’ a police car using two lightbulbs and a speaker. Now we have the speaker in place, we can play sounds and communicate with Smart Lightbulbs.
So we have to build a code that will:
- play a sound of ‘police sirene’
- change their brightness of ‘police lights’
- simultaneously change lightbulb colors to make them blink
Let’s import everything that we need: yeelight for bulbs, vlc & os for playing music without errors, and time for sleeping the code.
We have to keep in mind that bulbs accept only 60 requests (total, not each) per minute, so I’ll define some interval to keep things in order and add some prints to make it more ‘gangsta’:
from yeelight import Bulb
from time import sleep
import vlc
import os
os.environ["VLC_VERBOSE"] = str("-1")
interval = 0.5
file = 'police2.wav'
print("RUN!")
player = vlc.MediaPlayer(file)
bulbR = Bulb("192.168.0.157")
bulbL = Bulb("192.168.0.45")
sleep(5)
bulbR.turn_on()
bulbL.turn_on()
print("FREEZE!")
print("Put your hand's in the air!")
The main loop is used to change the brightness and color of the bulb in a state-machine way (obviously, self-describing):
for i in range(0,4):
player.play()#playing sirene and changing state
bulbL.set_rgb(0, 0, 255)
bulbR.set_rgb(255, 0, 0)
bulbL.set_brightness(0)
bulbR.set_brightness(100)
sleep(interval)
bulbR.set_brightness(0)
bulbL.set_brightness(100)
bulbR.set_rgb(0, 0, 255)
sleep(interval)
bulbL.set_rgb(255, 0, 0)
bulbL.set_brightness(0)
bulbR.set_brightness(100)
sleep(interval)
bulbR.set_brightness(0)
bulbL.set_brightness(100)
sleep(interval)
player.stop()
print(f"***Siren {i+1}***")#we are counting sirenes
Unfortunately, after four sirens, we got busted ☹, so we had to clean and turn off the lights:
print("BUSTED")
bulbR.turn_off()
bulbL.turn_off()
Final show:
And the ‘gangsta’ output:

And that’s it for today 😊
Source code for this project on my Github: HeadFullOfCiphers/SmartBulbCopcar
I hope you liked this little project, and if you want to check what the project evolved to or what was also developed in the process of creating this material, you can read:
- Fake TV Simulator – Turning police car into anti-theft toy to discourage intruders/burglars
- Simple Python Ex-If remover
- Handy Android EXIF Cleaner
Reference list:
- yeelight.com
- Python yeelight library readthedocs
- Python-vlc library docs
- How to Play Audio With VLC In Python
- Police2.wav sound from freesound.org
Check out related posts: