loading

This tutorial shows how to connect a pm2.5 sensor with raspberry pi.

SDS021 is used as the pm2.5 sensor, SDS011 sensor should be the same way.

Step 1: Edit the System File for Using the Serial Port

  • Set the debug serial port to normal serial port in raspberry pi
  1. Edit file /boot.cmdline.txt, delete the red characters

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

After deleted, the result should be something like :

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Save and exit this edit

  1. Edit file /etc/inittab

Open the file and coment the last line of the file:

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

  1. Power off raspberry pi

Step 2: Connect the Sensor

Connect the sensor as the image shows

Step 3: Coding

Python code

# -*- coding: utf-8 -*-
import serial import time t = serial.Serial('/dev/ttyAMA0',9600) t.setTimeout(2) while True: time.sleep(0.5) retstr = t.read(10) if len(retstr)==10: if(retstr[0]==b"\xaa" and retstr[1]==b'\xc0'):#check header char checksum=0 for i in range(6): checksum=checksum+ord(retstr[2+i])#check checksum if checksum%256 == ord(retstr[8]): pm25=ord(retstr[2])+ord(retstr[3])*255 pm10=ord(retstr[4])+ord(retstr[5])*255 print "pm2.5:%d pm10 %d"%(pm25,pm10)

Step 4: Running Screen Shot

<p>Hi,</p><p>Very nice setup! One question, have you tried linking it with Domoticz for Raspberry Pi? I'd like to purchase this sensor, but I would be good to know if Domoticz supports it as it's a nice tool for managing data of your own weather station.</p><p>Regards,</p><p>Radek</p>
<p>Hello. I would like to ask something related to the screenshot in Step 4. May I know what is the unit for the PM2.5 in your screenshot? The data sheet for SDS021 says that the range of measurement that can be recorded using the sensor is within 0.0-999.9 &mu;g /m3. Is your reading within that range? Thank you.</p>

About This Instructable

2,843views

3favorites

License:

More by jiangshan00000:Using Pm2.5 Sensor With Raspberry Pi make an arduino wifi air monitor 8051 C development using FREE compiler SDCC  
Add instructable to: