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 serialCOV_RATIO = 0.2 # //ug/mmm / mv
NO_DUST_VOLTAGE = 400 # //mv
SYS_VOLTAGE = 5000density = 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 = 16GPIO.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.28msAIN2_DATA = ads1015.ADS1015_SINGLE_READ(2)# AIN0_DATA=((AIN0_DATA*2-64)/2000.00+0.02)*2time.sleep(0.00004) # 持续采集0.04msGPIO.output(IN1, GPIO.LOW) # 关闭二级管灯time.sleep(0.00986)voltage = (5000 / 1024.0) * AIN2_DATA * 1.1 * 2 # 计算气体浓度if (voltage >= NO_DUST_VOLTAGE):voltage -=