Blog

Build your own GlowOrb, so you’ll always know when to open a window

Share this post:

Visual alerts show when the carbon dioxide levels are getting high in meeting rooms at IBM’s IoT HQ in Munich. They use the building’s carbon dioxide sensors combined with GlowOrbs, designed and made by IBM’s Andy Stanford-Clark, to highlight when it is time to open a window.

I decided to make an “at home” version. I discovered most carbon dioxide sensors are rather expensive. The cheapest carbon dioxide sensor I found was the Rehau USB Stick Ambient Air Sensor. Not only does this detect carbon dioxide, it also detects many volatile organic compounds (VOCs) such as ethanol, alcohol, benzene etc. I discovered, and I am blaming the cat for this, it can also work as a fartometer.

By using Watson IoT Quickstart platform, the sensor can be in one location and the GlowOrb in another – they both talk to the cloud using WiFi and MQTT.

This recipe is a how to to make your own. Please be aware this is for hobby and experimental use only – do not rely on this for safety critical systems, fire detectors etc.

Equipment required for the fartometer

Cost about £60 plus power supplies:

  • Rehau USB Stick Ambient Air Sensor (£28 from Amazon UK).
  • Raspberry Pi Zero W and adapters and latest Raspbian image (£20)
  • GlowOrb made from Wemos D1, Wemos LED shield, ping pong ball and a matchbox. (£10)
  • IBM Watson IoT Quickstart platform can be used for free – you do not need a Bluemix account.

Software

  • This is available on github
  • Python code for Raspberry Pi: AirStick_WIoTV6.py
  • Code for GlowOrb: RehauVOCGlowOrbv2.ino

Rehau USB Stick Ambient Air Sensor

The USB sensor outputs the “VOC reading”. This is a numerical value but it does not tell you which gas is detected, just a value. The higher the value the “dirtier” the air. For the purposes of this recipe, I have used 600 as high. As it is a USB device, it only needs to be plugged in to a Pi (or other computer that can run python scripts).

Raspberry Pi

The Raspberry Pi is used to take the sensor readings and publish them to the cloud. I used a PiZeroW, this has inbuilt WiFi but needs an “OTG” adaptor for the USB.

1. Make sure the Pi is connected to the internet.

2. Python is pre-installed on the Raspbian Jessie image. However, a couple more libraries are required: pyusb and ibmiotf. You can install these typing these two commands onto the command line on the Pi:

  • sudo pip install pyusb
  • sudo pip install ibmiotf

3. If you have problems installing ibmiotf, you may need to do the following:

  • sudo pip install –upgrade setuptools
  • sudo pip upgrade-pip

and then retry.

4. You also need to copy the file AirStick_WIoTPV6.py onto the Pi. This can be downloaded here.

5. When the software is complete, plug the VOC sensor into one of the Pi’s USB ports.

6. On the command line, type:

  • sudo python ./AirStick_WIoTPV6.py yyyyy
  • The yyyyy is the device ID and is the name you have chosen to call your Airstick data. This device ID is also used as the COMMAND_TOPIC in the code for the Wemos. Choose something original that is unique to you.

7. You should now get a list of VOC numbers. If you breathe on the sensor, you should find the number goes up, and the colour of the LED on the USB stick changes.

8. To get the Pi to automatically start running the python script when it boots up, edit the rc.local file:

  • sudo nano /etc/rc.local
  • and add at the bottom but above “exit”
  • /usr/bin/python /home/pi/AirStick_WIoTPV6.py yyyyy
  • Save, quit and reboot. It should now run without any extra input from you.

GlowOrb

I copied the idea of GlowOrbs from Andy Stanford-Clark. A GlowOrb consists of a Wemos D1, a Wemos LED shield, a ping pong ball and box to hold it all together. The shield is soldered to the D1. The ping pong ball, with a slice cut from the bottom, diffuses the light from the LED. I used a matchbox but you could make a 3D printed case, as Andy has done.

Image: Glowbox orb

Image: Glowbox orb

The Wemos D1 connects via WiFi to the cloud. For this recipe, I am using IBM’s Watson IoT Quickstart platform.

There is no requirement for you to signup for this. It is, as the name suggests, a way to quickly start getting data from a device connected to the internet.

You need to tell the WeMos to talk to the Watson IoT Quickstart Platform:

1. Use the latest open-source Arduino software (IDE), which you can download here.

2. The following libraries will also be needed. The instructions to install a library are given here.

  • PubSubClient” and “Adafruit_NeoPixel” are easily accessible.
  • The link to the library is here.
  • You will also need to install the ESP8266 WiFi board by following these instructions, which installed the adafruit-huzzah-esp8266.
  • Now you need to repeat using the board manager to install the WeMos D1.

3. You need to make a change to the PubSubClient.h file. It should be in your Arduino installation in a subdirectory called libraries/PubSubClient/src

4. Open the file using a text editor. Look for “‪#define MQTT_KEEPALIVE 15” and change the 15 to 60. Save the change.

5. Restart the Arduino software.

6. Plug the WeMos into your computer using a USB cable.

7. In the Tools menu:

  • Select the “WeMos D1 R2 & mini” board in the board manager menu. If it is not there, restart the Arduino software and try again.
  • Select CPU frequency: 160MHz
  • Select Flash Size 4M (3M SPIFFS)
  • Select: Upload speed 115200
  • Port: Make sure this is the port the WeMos is plugged in to.

8. Download and open the Arduino file RehauVOCGlowOrbv2.ino

9. In the code replace the SSID and password with the WiFi details you require.

10. You need to change the ClientID . Change the xxxxx to something unique in the Arduino sketch line:

#define CLIENTID “a:quickstart:xxxxx”

11. You need to change the COMMAND_TOPIC. Replace yyyyy with the same name you chose for the device ID on the python code on the line:

#define COMMAND_TOPIC “iot-2/type/VOCmeter/id/yyyyy/evt/reading/fmt/json”

12. Now save and upload the sketch to the Wemos.

Image: Glowbox using Wemos

Image: Glowbox using Wemos

13. The LED on the shield should flash magenta when the Wemos is trying to connect to the local WiFi and cyan when trying to connect to the Watson IoT Quickstart Platform. Once connected the LED turns off until the GlowOrb receives a VOC reading.

Image: Magenta GlowOrb

Image: Magenta GlowOrb

If the Pi and sensor are plugged in, the GlowOrb should now glow green if the VOC reading is less than 600, and red if above. This threshold is arbitrary and can be changed on this line:

#define THRESHOLD 600

Other information:

The data sheet for the sensor is here but it only seems to be available in German.

For instructions on how to connect a Wemos D1 to IBM Bluemix account, read this article.

Learn more

Learn more about what Watson IoT can do for you, or visit our blog.

Acknowledgements

Thanks to IBM’s Bill Hymas who wrote the python code to extract the sensor VOC reading and to Andy Stanford-Clark for adapting this for use with MQTT and Watson IoT Quickstart Platform. Thanks also to Andy for the inspiration, debugging and ideas.

More Blog stories
By Chris O'Connor on October 30, 2018

The Get Connected quiz: are you ready to transform your business?

I hope you’ve gotten connected with me these last several weeks. I was talking to a colleague about why I wrote these. And it really comes down to one thing: IoT is taking place all around us. Are you and your company participating in the digital transformation, and impacting the physical world? Or are you […]

Continue reading

By Chris O'Connor on October 18, 2018

There’s a new superhero in town: DATA, keeping your workers safe

Welcome to a new edition of our Get Connected series about worker safety. Today, we are going to discuss the most important aspect of your organization: your people and their ability to safely be dispatched to keep the assets in your environment running. With 178 work related accidents every 15 seconds, and 374 million non-fatal injuries […]

Continue reading

By Lisa DeLuca on October 1, 2018

How innovative technologies help an aging population stay healthier and happier

The developed world is grappling with the challenges of an aging population. By 2050, it’s estimated that at least 40 percent of the population in Germany, Italy, Japan and Singapore will be over the age of 60. For the United Kingdom, Canada, United States and Brazil, it’s anticipated that proportion will stand at 30 percent. […]

Continue reading