Skip to content

ondras12345/pm-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Particulate Matter Sensor

An SPS30-based outdoor particulate matter sensor for Home Assistant.

3D model of custom PCB and SPS30 sensor in a 3D printed enclosure 3D view of assembled PCB 3D view of assembled PCB Photograph of installed outdoor particulate matter sensor

This repository contains hardware designs and firmware for a PCB that connects to the UART interface on an SPS-30 sensor and allows it to be used via a half-duplex RS-485 link. It is designed to be put in one enclosure with the sensor and receive both power and commands via a standard UTP cable with RJ-45 connectors (but it does not use Ethernet).

The PCB is populated with a switch mode power supply module, an RS-485 transceiver and an ATtiny2313 microcontroller. The data out pin of the transceiver is connected straight to the SPS-30's Rx pin, the SPS-30's Tx pin is connected to the Rx pin of the MCU, and the MCU's Tx is connected to the transceivers data input.

In normal mode, the transceiver is put in receive mode, and the remote master is free to send any commands to the sensor. When the sensor sends a response, the bytes are buffered in the MCU. The MCU then switches the transceiver to transmit mode and empties its buffer. Finally, the normal (receive) mode is restored, and the device is ready to receive the next command from the master.

The Sensirion UART protocol is half-duplex in nature, so the use of a half-duplex physical link should not introduce any issues.

The software directory contains a program that makes a Linux server with a USB to RS485 converter to talk to the sensor and periodically publish readings to an MQTT topic, where they can be picked up by Home Assistant.

Notes

Design goals

  • No nontrivial firmware without OTA in the attic.
    • I have already made one device that requires me to stand on a ladder while flashing firmware. I'm not making that mistake again.
    • This means no custom modbus converters (thats not a trivial firmware task), no CC2530 zigbee, ...
  • No Wi-Fi
    • Either wired (preferred, power will need wires anyways) or zigbee.

Communication interface

  • The sensor has I2C and UART.
  • I2C: there is an esphome library, but the MCU would have to be within 10 cm of the sensor.
  • UART: master-slave, we can probably make it work half-duplex over RS-485 based on the 0x7E start/stop byte
    • UART is fixed @ 115200 baud
    • need UART-friendly crystal: 3.6864 MHz

Choice of microcontroller

  • I needed an ATtiny with UART. While the ATtiny2313 is seriously outdated, I have several of them in stock, so I chose to use it.

Motivation

  • In the winter, the outside air in our village is often polluted with wood smoke. I wanted my Home Assistant instance to be able to detect this and suggest the best time to open the windows.

About

SPS30-based PM2.5 particulate matter sensor with RS485

Topics

Resources

License

Stars

Watchers

Forks