Home Code Raspberry Pi and MQ-3 Gas sensor

Raspberry Pi and MQ-3 Gas sensor

by shedboy71

The MQ3 Gas Sensor module is useful for gas leakage detection (in home and industry). It is suitable for detecting Alcohol, Benzine, CH4, Hexane, LPG, CO. Due to its high sensitivity and fast response time, measurements can be taken as soon as possible. The sensitivity can be adjusted by using the potentiometer on the module.

My sensor was wired up as follows


This is a very basic example

import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
def readadc(adcnum):
# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
if adcnum > 7 or adcnum < 0:
return -1
r = spi.xfer2([1, 8 + adcnum << 4, 0])
adcout = ((r[1] & 3) << 8) + r[2]
return adcout
while True:
value = readadc(0)
volts = (value * 3.3) / 1024
print ("%4d/1023 => %5.3f" % (value, volts))

Some things to note here, the sensor relies on a heater – so the heater is supposed to be powered to allow this to occur, you should allow this to happen before taking readings, I have seen 1 hour to 24 hours quoted.

The ADC value is not a linear line meaning that a higher value is not the same as a higher reading, lets look at this graph


To accurately calculate the values requires more complex code – this is the best example but its for an MQ-2 , https://github.com/tutRPi/Raspberry-Pi-Gas-Sensor-MQ




Mq-3 Gas sensor specs
MQ-3 Alcohol Ethanol Sensor Breath Gas Ethanol Detection

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More