Sensly Hat for the Raspberry Pi Air Quality & Gas Detector





Introduction: Sensly Hat for the Raspberry Pi Air Quality & Gas Detector

Sensly is a portable pollution sensor capable of detecting the pollution levels in the air using its onboard gas sensors to collect information about the various gases present. This information can be fed directly to your smartphone for real-time push notification updates. Sensly uses industrial sensors that assure an accurate reading of the office, home, or work environment. Being aware of this data helps you to take action and bring the pollution levels down around you.

Our team at Altitude Tech LTD are big fans of the Raspberry Pi mini computer. We’re really keen to help the Raspberry Pi community develop their own Sensly device and start working on experiments whilst learning about different types of gases. We’ve developed the Sensly Hat for the Raspberry Pi. Initially launched on Kickstarter, we’re excited to provide this innovative development product to makers.

How To Use The Sensly HAT

Imagine using the Sensly Raspberry Pi HAT to:

  1. Build you own weatherproof case and monitor air quality in remote locations
  2. Monitor the air quality around your home
  3. Use it for school experiments.

Step 1: Parts in the Box

Start with getting everything you need.

  • Sensly HAT
  • BME 280 temperature, humidity and pressure sensor module
  • Sharp PM10 Sensor
  • PM10 Cable
  • 40 Pin Raspberry Pi header

Step 2: Putting Sensly All Together

Let’s put it all together

  • Put the 40 pin header into the pin holes on the Sensly HAT then place the Sensly HAT onto the pi
  • Place the BME 280 module on to the Sensly HAT ensuring the pins match up. Look under the module to know which direction it should be facing.
  • Plug the PM Sensor Cable into the port labeled PM Header
  • Once this is done, we can power on the Raspberry Pi.
  • Due to the power draw of the Sensly Hat when fully operational it is recommended that you use a raspberry pi charger to power your pi.

Step 3: Extra Parts

Getting everything for your raspberry pi

  • Raspberry pi 2 or 3
  • Monitor
  • Keyboard and mouse
  • Internet Connection
  • HDMI Cable
  • Raspberry Pi 3 charger
  • Latest version of Raspbian Jessie

Step 4: Setting Up the Raspberry Pi

The guide to setup a raspberry pi if you need from the raspberry pi foundation

Latest version of Raspbian Jessie can be found on the link below.

Step 5: Download the Software

Setting up the Raspberry Pi to connect to the Sensly HAT.

There are a few ways to do this, first you can download the Raspbian image here . This will be preconfigured to work. Secondly, you can download the install script from

Firstly we need to download the install scripts using the command. Make sure you are in your home directory

Then we change directory to the Sensly_Install folder

  • $ cd /path/to/Sensly_Install

Next, we need to make the install script executable.

  • $ chmod u+x ./

Finally we run the script. There will be some prompts that you will need to type in Y to confirm you want to continue

  • $ sudo ./

Once completed it your pi will restart. To confirm that everything is working we can run the following command.

  • $ i2cdetect -y 1

You should be able to see positions 05 and 76 on the screen

Step 6: Calibrate the Gas Sensors

Now we need to calibrate the Gas Sensors to be able to calculate the PPM. To do this we need to put the Sensly HAT in a clean air environment. This could be outside or if you have the facilities, in synthetic air. While the air you put it in will affect the accuracy of the sensors it will not affect precision so if you are looking to track changes in your air quality Sensly will be suitable. The Sensly HAT comes pre-loaded with the calibration firmware, so we can simply run the calibration script to find the R0 values for each Gas sensor. To be able to put Sensly in the calibration environment we need to be able to run the calibration script when the Pi boots up. For this, we can use the command crontab.

Type into the terminal the following commands

  • $sudo crontab –e

If you have never run crontab before then you will need to choose which editor that you want to use to edit it with, I normally use nano so I pick option 2. Next, we need to put the following command into the file

  • $ @reboot sudo python /path/to/

Then we close the file using Ctrl+x then Y. This will mean every time you start up your Pi it will run the calibration script.

You can now take it to you clean air environment and leave it for between half an hour, to an hour. The longer the better.

Once this is finished you should have a file named Sensly_Calibration_"date"_"time".csv where "date" will be replaced with the current date stored on the Raspberry pi and "time" is replaced with the current time. This file will contain the R0 values calculated during the calibration phase averaged every 5 minutes. Since the script logs a running average, you take the last entry in the file as the R0 values for the MQ2, MQ7 and MQ135. This will then be put into the file. to enable us to calculate the PPM values for each gas detected

Step 7: Running the Sensly HAT

To be able to run Sensly in full operation mode we need to update the firmware to get it out of Calibration mode. This is done by running the script

  • $ cd /path/to/Sensly_Install/
  • $ sudo ./

Once completed we can now run our main python script. But first, we need to download it from the GitHub repo.

  • $ git clone
  • $ python /path/to/

Finally, to enable you to run the script automatically we then run the crontab command again.

  • $ crontab -e

Then add this to the end of the file while removing our earlier entry

  • @reboot python /path/to/

Now every time you boot your pi the Sensly HAT should be logging data to a csv file. The final step is to take the R0 values you obtained during the calibration step and put them in the highlighted the last screen shot.

The next instructable we will be releasing will show you how to link this up with plotly.

Step 8: Final Steps

Please share your data as it will help us build better updates for Sensly.

If you think you have the skills to write a great Instructable using Sensly then purchase one from our store and if we like it we will refund your money and even send you more goodies!

3 People Made This Project!


  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • Science of Cooking

    Science of Cooking

We have a be nice policy.
Please be positive and constructive.




I don't know why but all written data values to zero.
Do you find how to do to resolve this problem ?

All written data values to Zero.PNG

Still having problems even after I installed the stuff from your GitHub

Made a fix for calibration and working on the rest, checkout for the branch on gitHub


I'm struggling with this hat

I'm using a pi zero W last raspbian image

non of the python is working

neither or or calibration are not collocting any data

is there any specific options to do ?

root@raspberrypi:/home/pi/Sensly_Install# BOOT0=1

root@raspberrypi:/home/pi/Sensly_Install# ./

Traceback (most recent call last):

File "", line 427, in <module>['port'], conf['baud'])

File "", line 71, in open

timeout=5 # set a timeout value, None for waiting forever

File "/usr/local/lib/python2.7/dist-packages/serial/", line 240, in __init__

File "/usr/local/lib/python2.7/dist-packages/serial/", line 272, in open


File "/usr/local/lib/python2.7/dist-packages/serial/", line 438, in _reconfigure_port

[iflag, oflag, cflag, lflag, ispeed, ospeed, cc])

termios.error: (22, 'Invalid argument')

^CCan't init. Ensure that BOOT0 is enabled and reset device

^C^CTraceback (most recent call last):

File "", line 474, in <module>


File "", line 110, in releaseChip


File "", line 98, in reset



Everything installed. Got through Kernel Panic issue. i2cdetect looks good. Now (Can't init), (Heating completed > Remote I/O error), and (Remote I/O error) errors out. Anyone got any suggestions?

Hi there, how did you overcome the kernel panic issue?

I ran the installer script from GitHub and it's now trashed my Pi 3. Kernel panic on every boot. The link to your pre-configured image doesn't seem to work either. Please advise.

I ordered a Sensly Hat 2 weeks ago for this instructable. Order is still "processing" and the company is not responding to emails or calls.

Well, I also got a Kernel Panic on a RPi3+Raspbian OS. My bad that I didn't save my SD image before trying, but I thought this would be just a simple install without killing my rpi OS. Really sad about that.

This totally worked fine before running the, I had my postgres server running there for weeks without an issue. I use win32diskimager to write the image.

Any way to recover from this easily? I'm trying to do that just now, but I have a feeling that sd is gone in heaven.


I just went ahead and downloaded the image and went on with the steps. calibration is not running on reboot even though I added the line and exchanged the path to the correct path. But ran that manually and seemed to atleast work that way. Now running is giving the following output:

~/Sensly_Install $ sudo ./
Bootloader version 31
Chip id: 0x444 (Unknown)
Extended erase (0x44), this can take ten seconds or more
Traceback (most recent call last):
File "", line 450, in <module>
File "", line 210, in cmdEraseMemory
return cmd.cmdExtendedEraseMemory()
File "", line 242, in cmdExtendedEraseMemory
self._wait_for_ask("0x44 erasing failed")
File "", line 80, in _wait_for_ask
raise CmdException("Can't read port or timeout")
__main__.CmdException: Can't read port or timeout

Did you guys ever test the code you released? Crashing OSes and consumers constantly hitting walls is not something you want as an end product.