Interactive Lighting Demo

 

This builds upon the basic example with Hue lights, and shows more interesting methods of interacting with smart lighting that can be incorporated into a more elaborate home automation or interactive installation setup.

Hardware Components

  • Raspberry Pi with PiShield connected to local network
  • 3 Hue Colour Bulbs
  • Hue Bridge connected to the local network
  • The following sensors:
    • A Reach distance sensor
    • A Turn or Push sensor

Software Setup

The final code in this demo can be found here, but should be used with the other supporting utilities of the root folder, so the best way is to simply clone the entire project. If you’re using the preconfigured image, it should be in the ~/dev/HueControllerBash folder already!

How it works

There are three main components of the script:

1.) Calling the Hue utilities in the parent folder to do things like turn lights on/off, set lights to a certain colour, etc. The commands we use are:

HueOnOff.sh: turns a light on or off, and
HueColour.h: changes the colour of a light

2.) Grabbing the sensor values. Here we use wiringpi’s built in gpio utility. For example:

SENS1=`gpio -x mcp3004:100:0 aread 100`

will read the first channel of the A2D converter.

3.) Mapping the received sensor values into light behaviour. Here, we do the following:

    • The first sensor channel sets the brightness of all lights, and is a simple linear mapping that takes the input (0-1023) and scales it to Hue brightness values (0-255), and then set all the lights to that brightness:SENS1=`gpio -x mcp3004:100:0 aread 100`
      BRI1=`expr $SENS1 / 4`
      ...
      ./HueControllerBri.sh 2 $BRI1 &> /dev/null
      ./HueControllerBri.sh 3 $BRI1 &> /dev/null
      ./HueControllerBri.sh 4 $BRI1 &> /dev/null
    • The “colour presets” that a triggered by the Reach sensor. In this case, the sensor values increase as a hand moves towards it. From here we set three regions – furthest (all lights white lights), medium (multi-coloured lights), and closest (all lights red). Following shows the chain of if loops that perform this categorization:
      if [ "$SENS2" -gt 700 ];
      then
         ./HueColour.sh 2 Red &> /dev/null
         ./HueColour.sh 3 Red &> /dev/null
         ./HueColour.sh 4 Red &> /dev/null
      fi
      if [ "$SENS2" -lt 650 ]; then
         if [ "$SENS2" -gt 300 ];
         then
            ./HueColour.sh 2 Blue &> /dev/null
            ./HueColour.sh 3 Yellow &> /dev/null
            ./HueColour.sh 4 Red &> /dev/null
         fi
         if [ "$SENS2" -lt 250 ];
         then
            ./HueColour.sh 2 White &> /dev/null
            ./HueColour.sh 3 White &> /dev/null
            ./HueColour.sh 4 White &> /dev/null
         fi
      fi
      

 

Leave a Reply