当前位置:网站首页>Detailed tutorial on the use of smoke sensor (mq-2) (based on raspberry pie 3B +)

Detailed tutorial on the use of smoke sensor (mq-2) (based on raspberry pie 3B +)

2022-04-23 14:04:00 one billion twenty-nine million one hundred and seventy-nine th

Experience :
Most of the Internet is about mq-2 Code for , The realized function judges whether there is smoke value , The specific smoke value cannot be read . Because raspberry pie can't read analog signals directly A0 value , So we have to help PCF8591( Read the smoke value adc) Read , This PCF8591 Quite critical , You have to use .
Hardware preparation :
Raspberry pie 3b+、mq-2、PCF8591( Read the smoke value adc) DuPont line
PCF8591 Here's the picture :
 Insert picture description here
Physical connection :

PCF8591 Connect with raspberry pie :
 Insert picture description here
mq-2 With raspberry pie and PCF8591 Connect
mq-2 PCF8591 Raspberry pie
vcc------------------------3.3v
gnd-----------------------gnd
AOUT–A0
Key connections are shown in the figure :
 Insert picture description here
Set raspberry pie :
open I2C Interface
Open the raspberry pie terminal , Enter the following command to enter the configuration interface
sudo raspi-config
choice Interfacing Options -> I2C ->yes start-up i2C Kernel driver
 Insert picture description here
Code up :

import time
from smbus import SMBus

address = 0x48

MODE0   = 0x00  #Channel0 = AIN0
                #Channel1 = AIN1
                #Channel2 = AIN2
                #Channel3 = AIN3

MODE1   = 0x10  #Channel0 = AIN3-AIN0
                #Channel1 = AIN3-AIN1
                #Channel2 = AIN3-AIN2

MODE2   = 0x20  #Channel0 = AIN0
                #Channel1 = AIN1
                #Channel2 = AIN3-AIN2

MODE3   = 0x30  #Channel0 = AIN1-AIN0
                #Channel1 = AIN3-AIN2

CHNL0      = 0x40  #Using Channel0
CHNL1      = 0x41  #Using Channel1
CHNL2      = 0x42  #Using Channel2
CHNL3      = 0x43  #Using Channel3

DAouputEn  = 0x40

PCF8591 = SMBus(1)

while True:
    value0 = PCF8591.read_byte(address)
    PCF8591.write_byte(address, CHNL0)
    time.sleep(2)

Running results
 Insert picture description here
The concrete effect and specific information can be viewed at WeChat official account. :
 Insert picture description here

版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401297935.html