A new code library for HPMA115S0 particle sensor


In today’s blog post I will show you how to use my latest code library for the Honeywell HPMA115S0 particle sensor.

If you don’t need the explanations and you need only the library, the download link is https://github.com/Electronza/HPMA115S0.

The library takes a lot from my original post on HPMA115S0, and it should be regarded as an evolution of that blog post. What I did is to move most code inside the library; I also changed some functions names to better match what’s inside the HPMA115S0 datasheet. Furthermore, I wrote the code inside the library in a way that it works with both hardware and SoftwareSerial ports. Code examples for the two use cases are also provided.

The HPMA115S0 sensor requires 5V power, but it uses 3.3V logic levels on TX and RX lines. As such, a logic level converter like BOB-12009 is required when using the sensor with 5V boards like Arduino Uno and Mega, as I did in this blog post. On 3.3V boards like Arduino Due, the TX and RX lines can be directly connected to the board.

Using the library

Regardless if you use hardware or SoftwareSerial, the serial port for the sensor must be configured first for 9600 baud rate. If you use SoftSerial, you will have to define the SoftwareSerial first.

Things are simpler when using hardware serial (Serial2 in the examples below):

The rest of the code works the same way, no matter if either hardware of serial port is used.

The current version of the library provides the following functions:

  • HPMA115S0.start_measurement() – this functions turns on the fan and enters measurement mode
  • HPMA115S0.stop_measurement() – this functions turns off the fan and enters low power mode
  • HPMA115S0.stop_autosend() – This function turns off autosend mode.
  • HPMA115S0.enable_autosend() – This function turns on autosend mode.
  • HPMA115S0.read(float *p25, float *p10) – performs a readout of particle data; it returns the results as a float.

All functions return “1” if successful, and “0” otherwise.

The following are not (yet) implemented

  • Reading and parsing of data in autosend mode
  • Read Customer Adjustment Coefficient
  • Read Customer Adjustment Coefficient

I have tested the library with Arduino Uno, using software serial, and with Arduino Due using hardware serial. I would be happy to hear how it works on other boards, and if you have any issues.



  1. Avatar

    I think ther is and issue in the line 63, sometimes the string “measurement fail” prints in the same line of (“checksum fail”). Change the “Serial.print” to “Serial.println” solve the problem. 🙂

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.