0

I am newbie who is learning how to using the sensor on the raspberry pi 3b module. Recently i have a project is need to use the MQ2 smoke sensor for detect the smoke. And i have follow this website http://www.learningaboutelectronics.com/Articles/MQ-2-smoke-sensor-circuit-with-raspberry-pi.php tutorial. But it doesn't work.And the error message on the below.

enter image description here

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

if_name_=="_main_":
main()

0 down vote accept

Thank you for joan the answer.Its work.

After that, i test the mq2 sensor by using on fire paper. But it always print "Current smoke level is 0"

Is it the code or other problem? Does anyone have same problem..??

2
  • 1
    What is the result of the command ls /dev/spi*? – joan Jan 18 '17 at 17:00
  • ls: cannot access /dev/spi* : No such file or directory, does it mean i miss some step on spi? – hotszcheung Jan 18 '17 at 17:02
3

You need to enable SPI.

The simplest way is to use sudo raspi-config and look under Advanced Options. You will probably need to reboot for the change to take effect.

Alternatively add the line dtparam=spi=on to /boot/config.txt and reboot.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.