I am currently doing a Smoke Alarm System project using Python 3 and a Raspberry Pi. At the moment I am testing the MQ2 Smoke Sensor Code but when running it the smoke level always remains 0.
With the MQ2 Smoke Sensor I am using the MCP 3002 Analog to Digital Converter as mentioned in this tutorial. I have installed all necessary libraries for the converter to work but I don't know where the problem is. This is the code for the Sensor:
import time import botbook_mcp3002 as mcp # smokeLevel= 0 def readSmokeLevel(): global smokeLevel smokeLevel= mcp.readAnalog() def main(): while True: # readSmokeLevel() # print ("Current smoke level is %i " % smokeLevel) # if smokeLevel > 120: print("Smoke detected") time.sleep(0.5) # s main()