Up to date guide for MQ-2 gas sensor usage with Raspberry Pi 4 model B.

MQ-2 module.
Sensor’s diagram.
Breadboard with MQ-2 sensor, a Logic Level Converter and an ADC.
Voltage divider formula.
Circuit for voltage division.
MQ sensor with voltage division at the analog output.
MCP3008 adc
Names of the MCP3008 legs
import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D5)

# create the mcp object
mcp = MCP.MCP3008(spi, cs)

# create an analog input channel on pin 0
chan = AnalogIn(mcp, MCP.P0)

print('Raw ADC Value: ', chan.value)
print('ADC Voltage: ' + str(chan.voltage) + 'V')



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store