A new code library for HPMA115S0 particle sensor

8

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.

Share.

8 Comments

  1. Avatar

    hi!
    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. 🙂

  2. Avatar

    Hi,
    1st THANKS FOR THIS!
    I’m using this library with Arduino nano ATMEGA 328P I’m using D7 AND D8 (PIN10 & PIN11) as Rx & Tx
    I didn’t get anything on the serial monitor the wiring is as you described except I’m not using a level shifter I used voltage divider for Arduino tx to switch it to 3.3V AND I wired the Tx of PARTICLE COUNTER 3.3V to the Rx of Arduino , is this the reason why I’m not receiving anything from the particle counter ?

    • Teodor Costachioiu
      Teodor Costachioiu on

      Try to use pins D10 and D11 as in my original code. An Arduino board should “understand” 3.3v as logical high, but a logic level convertor is the best approach.

  3. Avatar

    thanks for your reply,
    I did as what you said but it’s the same nothing coming from the particle counter
    I will try to get the level shifter and see If it’s gonna work

  4. Avatar

    both Tx of particle counter and tx of arduino are sending pulses (I did check this by a led ) but I have nothing on the serial monitor neither an error message except the void setup message “HPMA115S0 software serial example”

    • Teodor Costachioiu
      Teodor Costachioiu on

      You can try to modify the SerialPassthrough example to work with SoftwareSerial. Try to manually send commands to the sensor,
      Also, please note that 10 and 11 in the code are as in D10 and D11 in Arduino, and not pins 10 and 11 of ATMEGA328P.

  5. Avatar

    Hi,
    the pins are correct there are pulses getting out from Arduino Tx to the P.C and vice versa, and thanks for your suggestion.

Leave A Reply