1.GP2Y1010AU0F粉尘传感器连接图
2. GP2Y1010AU0F工作原理
工作原理
传感器中心有个洞可以让空气自由流过,定向发射LED光,通过检测经过空气中灰尘折射过后的光线来判断灰尘的含量。
3.源代码
main.py
# coding=UTF-8
import RPi.GPIO as GPIO
from ADC import ADS1015
from ADC import ADS_POINTER_CONFIG
import time
import math
import smbus
# import serial
COV_RATIO = 0.2 # //ug/mmm / mv
NO_DUST_VOLTAGE = 400 # //mv
SYS_VOLTAGE = 5000
density = 0.0
voltage = 0.0
# int adcvalue=0
def SendVideo():
ads1015 = ADS1015()
state = ads1015._read_u16(ADS_POINTER_CONFIG) & 0x8000 # 气体传感器连接确立
if (state != 0x8000):
print("\nADS1015 Error\n")
# 收集气体数据
GPIO.setmode(GPIO.BOARD)
IN1 = 16
GPIO.setwarnings(False)
GPIO.setup(IN1, GPIO.OUT) # 初始化二极管灯
GPIO.output(IN1, GPIO.LOW) # 关闭二级管灯
# ser = serial.Serial("/dev/ttyAMA0",9600)
# def Filter(m):
while 1:
GPIO.output(IN1, GPIO.HIGH) # 启动二极管灯
# AIN2_DATA=ads1015.ADS1015_SINGLE_READ(2)
time.sleep(0.00028) # 等待0.28ms
AIN2_DATA = ads1015.ADS1015_SINGLE_READ(2)
# AIN0_DATA=((AIN0_DATA*2-64)/2000.00+0.02)*2
time.sleep(0.00004) # 持续采集0.04ms
GPIO.output(IN1, GPIO.LOW) # 关闭二级管灯
time.sleep(0.00986)
voltage = (5000 / 1024.0) * AIN2_DATA * 1.1 * 2 # 计算气体浓度
if (voltage >= NO_DUST_VOLTAGE):
voltage -=