Using a Sound Sensor With a Raspberry Pi to Control Your Philips Hue Lights

Introduction: Using a Sound Sensor With a Raspberry Pi to Control Your Philips Hue Lights

Use case: once my kitchen door is closed I'm not able to hear my doorbell - annoying when you throw a party with many guests!

Luckily, one guy at the partycame up with the excellent idea to "hook up some kind of microphone and ring a sound if the doorell rings".

The idea seemed nice, so we brainstormed the possiblities over a couple of beers with my tech-savy friends.
It hat to be a bit more flashy than just a doorbell sound, so instead of using my speakers we decided to use my Philips Hue lights instead to create a cool light effect to announce new guests!

All of the lights were set up in the kitchen already, so we went for a blink the lights if the doorbell rings approach.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Hardware Requirements

  1. a Raspberry Pi 2 to run the software / scripts (every Raspberry generation should be feasible to implement this)
  2. a cheap sound sensor for a couple of bucks from ebay/amazon/etc - e.g. here or here
  3. some female-to-femalejumper wires to connect the sound sensor with the Pi
  4. Philipps Hue lights, you can go for every set up you want - I went for
    • Philips Friends of hue - LivingColors Bloom
    • Philips Hue Go
    • Philips hue - LED
    • one of the above needs to be the starter kit / you will need a bridge to control the lights after all

Step 2: Software Requirements

In my setup I used a Raspberry Pi 2 with Raspbian Wheezy with a few python libraries:

  1. Raspbian
  2. Python package python-dev
  3. Python library requests
  4. Python library qhue from Quentin Stafford-Fraser
  5. Python library RPI.GPIO

Step 3: Initial Setup

This will outline the main steps of the set up, as you can see it's pretty simple and should be straight-forward to understand.

  1. Connect the sound sensor to the Raspberry Pi via female-to-female jumpers, using 3 jumpers for:
  2. power on your Raspberry Pi
    • If your sound sensor has indicator LEDs, make sure it triggers when creating noise to test the basic sound sensor capabilities
  3. install Raspbian image (if not done already)
  4. setup up and connect via ssh
  5. install necessary software (python-dev) via

    apt-get install python-dev
  6. and install the python libraries requests, qhue and RPI.GPIO via

    pip install requests
    git clone
    cd qhue
    pip install RPI.GPIO

Step 4: Set Up the Script

Let's open a new script named and put in the below code.



import time
import RPi.GPIO as GPIO from qhue import Bridge

GPIO.setmode(GPIO.BOARD) # use board pin numbers # define pin #7 as input pin pin = 7 GPIO.setup(pin, GPIO.IN)

b = Bridge("", 'e254339152304b714add57d14a8fdbb') groups = b.groups # as groups are handy, I will contorll all

while 1: if GPIO.input(pin) == GPIO.LOW: i = 3 # number of iterations for l in range(1,i+1): # this is one of the temporary effects, see official docs # at b.groups[0].action(alert="select") #group 0 = all lights time.sleep(1) time.sleep(10)

Step 5: Fire It Up!

Just run the script via

sudo python

And trigger the sound input - if all went well, your lights should blink 3 times..

Congratulations, you just created a listener script to listen to your doorbell / any sound you wish!

Step 6: Set Up Autostart for Your Listener Script

We will be utilizing the Linux rc.local functionality and create a new shell script that will run the python part we just created in the previous step:

nano /home/pi/qhue/



sudo python /home/pi/qhue/

Now make this script executable by performing:

chmod +x

Open up the /etc/rc.local file

nano /etc/rc.local

and enter the following line before exit 0 to run the script at startup

sudo /home/pi/qhue/

Save the file and reboot your Raspberry Pi via

sudo shutdown -r now

Step 7: Summary / To-Do

This instructable outlines the very basics, I will add a few pictures and more details once I got the time to fine-tune this.

It is worth noticing that the distance to your sound source shouldn't be too far away, neither should you place the Pi in a spot where you would expect regular noise.

Hope you enjoyed the guide, any suggestions? Feel free to comment ;)


Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    14 Discussions


    Tip 1 year ago

    Be careful if you buy a 5V DC Module, it will output 5V and your raspberry wants to receive only 3.3V.

    It is safe to use a 'voltage divider' with only 2 resistors and one more wire:

    different values of resistors are ok (and even better) as long as:

    R2/(R1+R2) = 3.3V/5V = 0.66

    (I'm not an expert, please check info on this subject)


    3 years ago

    Really nice!
    But I have a question, has the sensor an digital output? Or is just analog?
    In the case that is just analog, is it safe to connect it directly to the raspberry?


    Reply 1 year ago

    I believe D0 is digital and A0 is analog... and both are outputs


    Reply 3 years ago

    Hey there! The sound sensor I've used is analog.

    I'm no expert here but I guess you should NOT hook it up directly. My setup is up and running since 14 months now though :)



    3 years ago

    I tried to do this but i'm having problems with the script.

    the if condition if GPIO.input(pin) == GPIO.LOW: is always true! so it's detecting sound all the time i already adjusted the sensitivity but nothing happens it keeps throwing alerts

    can you pls help me with this?


    Reply 3 years ago

    Hey there,

    you could try to test if the sound sensor works first.
    In the middle of the code try something like:

    while 1:

    Print GPIO.input(pin)

    To print the status of the sensor. Next trigger the sensor witrh a clap or something and see if the status changes. Also make sure you have connected the pins correctly.

    If found this tutortial, they have better pictures that show you how to connect the sensor to the GPIO from the Pi. Note that they are using pin #12 instead of #7 as I do. You could use their setup and change the pin number in my code to see if it works? :)
    Here's the instructable:




    Reply 1 year ago


    I'm just beginning with the GPIO so I'm not an expert at all, but I had the same issue with a simple click button and I can confirm it is related to "floating pins" and the need of pull up or pull down resistors.

    See the beginning "background" part, it is pretty clear:

    The tutorial is very nice to read though, thx


    2 years ago

    hello this is nice software . is it possible to use this sound card to recognize just alarm and performe some jobs like take picture from camera in case of alarm sound . please guide me . tnx


    Reply 1 year ago


    for the sound part it is not possible to analyze sound, no.

    It would need an analog module and use the analog pin out from this sensor.


    Reply 2 years ago

    Sure saeed, that should work too!

    In step 4 you could try to also import picamera library, replace the bottom part with the following:

    while 1:
    if GPIO.input(pin) == GPIO.LOW:
    filename = now.strftime("%Y-%m-%d %H-%M")
    camera = picamera.PiCamera()

    See some example code here:


    4 years ago

    Can i use it with my Milight bridge ? Or only coded for Hue?


    Reply 4 years ago

    This should work with any hardware that has an API you can access.

    I could think of a setup with FHEM ( ) that most definitely will be able to control your lights.


    4 years ago on Introduction

    This is so cool! I love finding ways to control internet connected things!