Arduino nano + PMS7003 particles sensor

Straight to the codes.
We’re going to get PMS7003 values and print them to serial monitor.

compile and download these codes to arduino nano

#include "PMS.h"
#include <Wire.h>
PMS pms(Serial);
PMS::DATA data;
void setup()
{
    Serial.begin(9600);
}

void loop()
{
  if (pms.read(data))
  {
    Serial.print("PM 1.0 (ug/m3): ");
    Serial.print(data.PM_AE_UG_1_0); 

    Serial.print(", PM 2.5 (ug/m3): ");
    Serial.print(data.PM_AE_UG_2_5); 

    Serial.print(", PM 10.0 (ug/m3): ");
    Serial.print(data.PM_AE_UG_10_0); 
    Serial.println();           
  }  

open serial monitor on Arduino IDE, set the baudrate to 9600 bps, you’ll see the beautifull data coming from PMS7003.
that’s it, pretty simple wight?

Hey!! i want those values grabbed to my raspi zero for my weather station
easy, i can connect PMS7003 sensor serial pin to my raspi UART. but wait, there’s logic level difference between my arduino nano pin I/O and PMS7003.
so, i think the safest way is using usb connect to raspi usb. in my case when i plugged nano to raspi, it will immediately recognized by raspi.

 
pi@raspberrypi:~ $ lsusb 
Bus 001 Device 006: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 001 Device 004: ID 1546:01a7 U-Blox AG [u-blox 7]
Bus 001 Device 003: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 002: ID 2109:2813 VIA Labs, Inc. VL813 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

take a look at

[Bus 001 Device 006: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC]

in my case nano will be on ttyUSB0

pi@raspberrypi:~ $ grep -i 'tty' /var/log/syslog*
/var/log/syslog.1:Nov 20 19:17:23 raspberrypi kernel: [434783.042818] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0
/var/log/syslog.1:Nov 20 19:18:42 raspberrypi kernel: [434861.956242] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
/var/log/syslog.1:Nov 20 19:19:13 raspberrypi kernel: [434892.390729] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0

pi@raspberrypi:~ $ ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Nov 20 19:22 /dev/ttyUSB0

let’s get on the python script

#!/usr/bin/env python3
import serial
import time
import sys

#Serial takes two parameters: serial device and baudrate
nano = serial.Serial('/dev/ttyUSB0', 9600)
nano.flushInput()

while True:
    data = nano.readline()
    strs = data.decode().strip())
        print(strs)
    time.sleep(1)

run it, python tne_code_abobe.py

PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 40, PM 10.0 (ug/m3): 49
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 40, PM 10.0 (ug/m3): 50
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 40, PM 10.0 (ug/m3): 50
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 39, PM 10.0 (ug/m3): 50
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 39, PM 10.0 (ug/m3): 50

that’s it 🙂

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *