Skip to main content

Gas detection for Raspberry Pi using ADS1x15 and MQ-2 sensors

Project description

Gas detection

Latest Version Total Downloads License Build Status

Gas detection for Raspberry Pi using ADS1x15 and MQ-2 sensors.

Description

The MQ-2 sensor can detect multiple gases (CO, H2, CH4, LPG, propane, alcohol, smoke) and outputs analog voltage. This project can convert it to digital using ADS1015 or ADS1115 and filter out the target gases.

The sensor can be inaccurate so don't use those measurements if you need them for security purposes. Use some professional measurement device if you need to do this.

Usage

The detection class uses ADS1115 and it's I2C address 0x48 by default. It assumes the sensor is connected to P0. You can also pass them to arguments.

The ro value is about 1000, but it needs to be calibrated. This is done automatically if it is not specified. The calibration must be done in good fresh air to make measurements more accurate. Alternativly, you can save the calibration value and later pass it as ro argument.

from gas_detection import GasDetection

detection = GasDetection()

You can then read percentage of gases in parts per million (ppm). The measurements are returned as dictionary and gas be accessed by GAS_XX constant.

ppm = detection.percentage()

print('CO: {} ppm'.format(ppm[detection.CO_GAS]))
print('H2: {} ppm'.format(ppm[detection.H2_GAS]))
print('CH4: {} ppm'.format(ppm[detection.CH4_GAS]))
print('LPG: {} ppm'.format(ppm[detection.LPG_GAS]))
print('PROPANE: {} ppm'.format(ppm[detection.PROPANE_GAS]))
print('ALCOHOL: {} ppm'.format(ppm[detection.ALCOHOL_GAS]))
print('SMOKE: {} ppm\n'.format(ppm[detection.SMOKE_GAS]))

You can also look to example file for more examples. For more details how the values are calculated you can read tutorial on Raspberry Pi Tutorials.

Versioning

This library uses SemVer for versioning. For the versions available, see the tags on this repository.

License

This library is licensed under the GPLv3+ license. See the LICENSE file for details.

A lot of code has been taken from Raspberry-Pi-Gas-Sensor-MQ. Thank you @tutRPi and others who contributed to that repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gas-detection-1.0.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

gas_detection-1.0.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file gas-detection-1.0.1.tar.gz.

File metadata

  • Download URL: gas-detection-1.0.1.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.4.8

File hashes

Hashes for gas-detection-1.0.1.tar.gz
Algorithm Hash digest
SHA256 58925d283c74fc1675e2514cfdecf319d050506fcb1205ad448dcf848a0ae642
MD5 5fe5600054597ade838c705972b690d1
BLAKE2b-256 43bed2665e67b7305bcd07380f87f92c7f776d13f87bb799134afc7b6bbe110d

See more details on using hashes here.

File details

Details for the file gas_detection-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gas_detection-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.4.8

File hashes

Hashes for gas_detection-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a006743162fa06b0d3549dd62a7441a47e59fe47a0dd50f20e0f782d3376fadd
MD5 afa76b299c651b8bb1840b139ad36b4f
BLAKE2b-256 ef8ee1267e4ea2ed2048eb307e2510eaede70e547deac421a14a8c22423b1109

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page