--> A code library for HPMA115S0 particle sensor | Electronza

A 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.

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.

Name

Air quality,1,Arduino code library,2,Arduino projects,12,Casual stuff,1,ESP8266,2,PIC projects,1,Review,14,Tutorial,11,
ltr
item
Electronza: A code library for HPMA115S0 particle sensor
A code library for HPMA115S0 particle sensor
https://1.bp.blogspot.com/-AHoq83Yc_e0/YFC5KX4TacI/AAAAAAAABkQ/XBIfpe8oSCI-nNgaY729aQnRhNoofXTmwCPcBGAYYCw/w640-h480/sensor-honeywell-arduino.jpg
https://1.bp.blogspot.com/-AHoq83Yc_e0/YFC5KX4TacI/AAAAAAAABkQ/XBIfpe8oSCI-nNgaY729aQnRhNoofXTmwCPcBGAYYCw/s72-w640-c-h480/sensor-honeywell-arduino.jpg
Electronza
https://www.electronza.com/2019/03/hpma115s0-arduino-library.html
https://www.electronza.com/
https://www.electronza.com/
https://www.electronza.com/2019/03/hpma115s0-arduino-library.html
true
4275662725798500575
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content