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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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!


matthew-campbell (author)2017-11-21

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

GachoudP (author)2017-11-06

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

gas14 (author)2017-10-17


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



GachoudP made it! (author)2017-10-04

Everything installed, got a

Traceback (most recent call last):
File "/home/pi/Sensly/", line 66, in <module>
AvRs_MQ7 = AvRs_MQ7 + MQ7.Get_RS(MQ7cmd)
File "/home/pi/Sensly/", line 58, in Get_RS
self.RS = ((float(self.MaxADC)/float(self.Get_rawdata(cmd))-1)*self.RLOAD)
File "/home/pi/Sensly/", line 46, in Get_rawdata
IOError: [Errno 121] Remote I/O error

when trying to calibrate it. Latest raspbian & dev_install worked with i2cdetect looking good... help me please!!


GachoudP made it! (author)GachoudP2017-10-04

bad soldering, go to i2c bus error, enabled it into raspi-config->interfacing options after soldering again all connections that were bad!

Traceback (most recent call last):
File "", line 29, in <module>
MQ2 = Sensor('MQ2',R0[0],RSAir[0]) # name, max adc value, Calibrated R0 value, load resistance
File "/home/pi/Sensly/", line 36, in __init__
i2c = I2C.SMBus(1)

Now waiting for next error....

GachoudP made it! (author)2017-10-04

Checkout for bad solderings!!!!!

jimdimcc (author)2017-08-11

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?

thedublineric (author)jimdimcc2017-08-24

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

thedublineric (author)2017-08-13

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.

PaulH454 (author)2017-07-14

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.

RichardH321 (author)2017-02-06

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.

RichardH321 (author)RichardH3212017-02-09

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.

RichardH321 (author)RichardH3212017-02-09

Went ahead and ran the script anyways, it created the new .csv file, all readings are 0,0,0,0,0,0,0,0 for every 30 seconds for the past 20 minutes.

Now I must really ask is this hardware really works?

UPDATE: After recalibration it seems to measure MethanePPM, but everything else is still 0.

relloyd (author)RichardH3212017-04-12

Same here!

AltitudeTech (author)RichardH3212017-02-13

The Kernel panic may have been caused by the apt-get update, upgrade and dist-upgrade commands, the reason we add this to the script is to make sure the raspberry pi is at the latest version. This is to ensure that the raspberry pi is a close to our in lab test conditions as we cannot guarantee that the install will work on earlier versions. We are sorry that you have had these issues. There is a potential to recover your information by plugging your SD card into a computer running a linux os.

In response to your second comment, would it be possible to screen shot the path you save it to and the file explorer view of the file location by opening a separate terminal and using the command scrot -s then clicking on the window you want to screen shot. This will help us find the issue.

In terms of the not working it seems like the program or the board is hanging could you please try restarting the entire system and try again. If this doesn’t work could you tell me which raspberry pi you are using?

Finally in terms of the output my first question would be where you did calibrate the sensors? Also I think I should point out that majority of the gases detected with the exception of CO2 shouldn’t be picked up normally if they are it would mean your home is has dangerous gases. If you would like to test the response of the sensors, you can you lighter gas to ensure that the sensor are responsive

Hope this help and sorry for the delayed response

RichardH321 (author)AltitudeTech2017-02-14

I'm pretty sure the updater caused it yes. But nonetheless it was your install script running it :)

The calibration mostly worked after a few reboots, I still have an issue that if the code runs for a while even if it had values instead of 0 after a 20minutes it goes wild and all becomes 0. I however had to modify your script to make it work with our script and as I converted some code, I noticed the reason is that after a few (didn't count them, I would say around 10-20) queries (in my script I query every seconds instead of 30 seconds) the SenselyHAT is just not responding and throws an IOError on sensor reading and to me it seems until the pi is restarted it won't be able to connect to it. I don't know though that the fact that the package arrived with the 40 pin gpio bent or something else causing it. Other than plugging the parts together was hard didn't seem to matter that much in the workings of the device.

As to the measured gases I honestly don't know which and how much should be in my air. I understand that it is normal that the values are 0, I was just hoping for something (which later came in a single cell having values) It just seems crazy to me that the air in the city I live in has 0 dangerous gases. I'm happy to hear that that's normal.

I haven't ran the lately, but with the basically same code I did for my script, it seems to me that measurements are being made though. I'll attach a shot of the table I have. there is a part where the data just died after running the code, then when I restarted the pi it worked again. it's in a 'safe' place without movement so I doubt disconnection could have happened, however the cabled attachment unit falls apart really-really easily for me, but I always check that it's plugged together when I leave the unit to measure.

Any help would be appreciated regarding this, since this is the last thing that seems to be nagging me.

RichardH321 (author)RichardH3212017-02-28

Wow you guys are not quick at all. Anyways the device is now totally not responding to anything. I get IOError tried rebooting it multiple times but nothing.

Traceback (most recent call last):

File "/home/pi/Sensly/", line 80, in <module>

sensor = BME280(mode=BME280_OSAMPLE_8)

File "/home/pi/Sensly/", line 114, in __init__


File "/home/pi/Sensly/", line 119, in _load_calibration

cal1 = self._device.read_i2c_block_data(BME280_I2CADDR, 0x88, 24)

IOError: [Errno 110] Connection timed out

This is the error I get now, 2 weeks ago it was only coming on just after a few queries now it's not even doing anything... Is there a way to connect more quickly with you guys since a monthly response is not good when the device is faulty. Seems like it's a waste of money at the moment.

jbrannon80 (author)2017-03-11

Both of the instructables for Sensly I am having issues with the crontab step. I follow the instructions to add the commands to run the calibration or the Plotly python script at reboot but neither one is working. What am I doing wrong? I am using the Sensly.img that was provided.

saguna (author)2017-02-28

Hi there, I want more information on ordering the Sensly Hat, I sent an email to the email id provided on the website and I also tried calling the phone number but have not received a reply. I would need 4-5 hats.

AltitudeTech (author)2017-02-17

Here is the Plotly Graph setup instructions for Sensly The Raspberry Pi Hat.

FrankM195 (author)2017-01-30

Since calibration did not lead to sensible values, I tried to analyze the code to find some values which generate at least some relative curves. I send the data to IBM Watson IoT to draw the charts. Below image shows basically the CO2 curve. At 17:30 I entered the room, which means, it measures 'something'. I wonder where these periodic spikes come from. Is this the heating cycle of the sensor? Any chance to remove this (other than using a 30 min average)?
The MQ7 sensor seems to be completely unusable. The value chances periodically with factor 10000. Anything I missed?

AltitudeTech (author)FrankM1952017-02-03

Hi Frank, Sorry for the delayed reply.

The reason for this is that the MQ7 requires a special heating cycle to detect Carbon Monoxide. This cycle is 60 seconds at 1.4V and 90 seconds at 5V. The Sensor is ready to be read during the 5V stage so to prevent it being read during the 1.4V stage we set the value it outputs during this stage to a number that would not give any ppm reading. This is why you get those very high rs/r0 values on the MQ7. Could you please let me know in what envrionment you calibrated the Sensors in?

FrankM195 (author)2017-01-21

Ok, tried twice and ended up with kernel panic. Do you have a link to the promised image from your website? Maybe that works better.

FrankM195 (author)FrankM1952017-01-24

Tried the image at with the same result. No success. Kernel panic. Any additional steps I should do which I am not aware of?

AltitudeTech (author)FrankM1952017-01-26

What disk imager did you use to create the SD card? We recommend Win32 Disk Imager if this doesn't work could you please screen shot the problem

FrankM195 (author)AltitudeTech2017-01-30

I use plain command line on Mac. However, it tried multiple times and it worked twice with the disc image. I had not success with the install script. Not sure what's wrong but I have a working system now.

AltitudeTech (author)FrankM1952017-01-24

We have just updated the link.

AltitudeTech (author)2017-01-25

Hi VladmirS22

As with most electrochemical cells they tend to drift over
time so will need recalibration approximately every 3- 6 months. That is the
best way to ensure long term accuracy.

There is a pre-heating/burn-in phase required to remove the
protective coating the sensors have when we receive them from the manufactures
but this is typically 48 hours and only has to be done once. After that we
typically recommend heating the sensor for 15 minutes to stabilize readings
before logging any data.

Also temperature does affect the sensor readings hence why
the datasheet provides a curve to relate the change in temperature to the rs/r0
value which is used to calculate PPM. The reason we have located the BME280 so
close to the sensors is to account for the increased temperature caused by the
proximity of the three sensors and use this to correct the rs/r0 value. This
way we can have more than one sensor on our board

VladimirS22 (author)2017-01-21

in fact now i noticed that the Temperature sensor is put 2-3 cm from the heaters. my experience with emitted heat is that a USB2Serial cheap that radiates 60mW (12mA @ 5V) increases the ambient temperature in radius 2cm by 2 degrees (Celsius). Eventually i had to put it 10 cm away to avoid the interference of those 60mW.

so to make this design work, i believe the Temperature sensor should be connected with at least 20 cm jumper wires

AltitudeTech (author)VladimirS222017-01-24

We are not ignoring your message just need a little time to confirm all the answer. We will get back very soon.

VladimirS22 (author)2017-01-21

could you comment how the long-term stability is handled? My experience with a simillar CO2 sensor (the TGS4161 [1]) showed that even if it is calibrated, it's sensivity tends to decrease with the number of times it is heated. And the initial calibration also get's off once it is stopped for a day or so. And in addition it may take up to 2-3 days heating until the sensor can report correct data. Having in mind that the TGS4161 costs 20+ eur, and the MQ-series sensors are 1-2 Eur, i wouldn't expect much difference.

Also i wonder - keeping those 3 heaters so close to each other (emiting ~2.5w of energy) doesn't it also affect the readings, as those electrochemical sensors tend to be sensitive to ambient temperature


Swansong (author)2017-01-04

This would be really helpful in densely populated areas :)

About This Instructable




Bio: Altitude Tech LTD is founded by professionals and students in the area of robotics, electronics and product design, which makes the team the heart of ... More »
More by AltitudeTech:IOT BIT 4G, 3G & GSM V1.5 Hat for the Raspberry PiPlotly Graph for Sensly The Raspberry Pi HatIOT BIT (Formally Known As PiAnywhere V1.31) 4G & LTE Hat for the Raspberry Pi
Add instructable to: