A code library for HPMA115S0 particle sensor

Mar 19, 2019 0 comments

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.

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.
#include <hpma115s0.h>
#include <SoftwareSerial.h>

bool my_status;
float p25;
float p10;

SoftwareSerial mySerial(10, 11); // RX, TX
HPMA115S0 my_hpm(mySerial);

//...

void setup() {
  //...
  mySerial.begin(9600);
  //...
}

//...

Things are simpler when using hardware serial (Serial2 in the examples below):
#include <hpma115s0.h>

bool my_status;
float p25;
float p10;

HPMA115S0 my_hpm(Serial2);

//...

void setup() {
  //...
  Serial2.begin(9600);
  //...
}

//...

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.

Comments

Related Posts

{{posts[0].title}}

{{posts[0].date}} {{posts[0].commentsNum}} {{messages_comments}}

{{posts[1].title}}

{{posts[1].date}} {{posts[1].commentsNum}} {{messages_comments}}

{{posts[2].title}}

{{posts[2].date}} {{posts[2].commentsNum}} {{messages_comments}}

{{posts[3].title}}

{{posts[3].date}} {{posts[3].commentsNum}} {{messages_comments}}

Recent Comments

Contact Form