Arduino Uno: PM2.5 sensing revisited

17

Today it’s finally the time to revisit the blog post on using the Honeywell HPMA115S0 particle sensor with an Arduino Uno board. The basics of the operation of the HPMA115S0 and a preliminary version of this code that works with Arduino Due are published in this blog post, so please take a few minutes and read it.

After publishing that blog post, so many of you have asked me to come with a way to make this sensor work with an Arduino Uno. It’s relatively easy to do it, but one must overcome two minor issues:

  • Albeit the HPMA115S0 is powered from a 5V supply, it uses 3.3V logic. To make it work with an Arduino Uno, one must use a logic level converter. In this blog post, I used one BOB-12009 from Sparkfun.
  • The Arduino Uno has a single serial port, which is commonly used to communicate with the PC. The only way to make the PM2.5 sensor work with the Arduino Uno is to use SoftwareSerial, with some minor changes in the code and some quirks that are explained below.

Connections and schematic

The wires used in the blog post to connect the sensor were all red colored.  Getting the right way to connect things was a bit difficult for some people, so I tried to make things a bit easier this time.

HPM Series Particle Sensor pinout

HPM Series Particle Sensor pinout

In the above picture, we can see the sensor with its connector. The pin numbering is a bit odd, with PIN1 near the fan and PIN8 to the edge of the sensor. Only four pins are used in this project: Vcc, RX, TX, and GND.

HPM Series Particle Sensor - connection detail

HPM Series Particle Sensor – connection detail

The wires are still all red, but I’ve put some colored heat shrink tubing on some wires to increase visibility:

  • red is Vcc
  • yellow is TX – this goes to SoftwareSerial RX pin
  • blue is RX – this goes to SoftwareSerial TX pin
  • black is GND

The sensor is connected as follows:

Honeywell PM2.5 sensor Arduino Uno connections

Honeywell PM2.5 sensor Arduino Uno connections

We can see that the logic level converter receives both 5V (red wire) and 3.3V (orange wire) from the Arduino board. GND is connected both to the PM2.5 sensor and to the logic level converter. The sensor is powered from 5V (red wire going to pin2 of the sensor).

Pin11 of the Arduino Uno is SoftwareSerial TX pin and will go to the HV4 pin of the logic level converter. The opposite LV4 pin goes to pin7 of the HPMA115S0 sensor,

Pin10 of the Arduino Uno is SoftwareSerial RX pin and will go to the HV3 pin of the logic level converter. The opposite LV3 pin goes to pin6 (TX) of the HPMA115S0 sensor.

Beloe there are some pictures of the sensor connected to an Arduino Uno:

1 2
Share.

17 Comments

  1. Avatar

    Hello,

    I’d really like to try and do this, but I can’t see the code referred to on this or the other post – would you be able to send to me? Also – how long does this take to put together?

    Thanks!

  2. Avatar

    Greetings,

    I’ve been trying to use this schematic, but after combining all the parts, I get this output:
    “Start!
    Waiting for the first autosend.
    Timeout
    Stopping autosend…

    When I try to change the plugins a bit, it gives me a “waiting for cmd” output, which usually means there’s something wrong with RX and TX pins.

    Any idea what might be causing this?
    Feel free to contact me by Email, as this is an ongoing project.

    Thank you!

    • Teodor Costachioiu
      Teodor Costachioiu on

      I assume you have connected something wrong. I cannot replicate your situation.
      You can try to change the SerialPassthrough sketch to work with Software serial, see what the sensor is sending.

      • Avatar

        Hey, thanks for the reply.

        I’ve been trying to use that sketch, as well as switching the RX and TX pins to 2 and 3 as to not interfere with the ethernet shield’s SD capacity (I’ve changed the code accordingly), to no avail. Still no output.

        I used a different schematic previously, with a direct connection from the sensor to the board, which gave me an output, although it wasn’t reliable or steady.
        Do you think there’s a way to skip the level shifter and connect the sensor straight to the Uno (Trying to build a compact, small system), or would the best course of action be to get a different board? the Due, for instance?

        Appreciate it!

  3. Avatar

    I’m sure someone would eventually catch this, but in the interest of accuracy, I point out the following error in a wiring diagram.

    In the paragraph that begins “Below there are some pictures of the sensor connected to an Arduino Uno”, the top right picture (https://cdn.electronza.com/wp-content/uploads/2018/11/E2050312-214×140.jpg), has the orange wire connected to Arduino RESET and red wire connected to Arduino 3.3V. Instead it should be: orange wire connected to Arduino 3.3V and red wire connected to Arduino 5V.

    • Teodor Costachioiu
      Teodor Costachioiu on

      Hi Mark,
      You are right. I must have misplaced the wires when I did the photo session.
      For now, I have removed the images with the wrong connections, and I will reshoot them as soon as possible.

  4. Avatar

    Found a typo in the code. In read_measurement(), the line that says:
    if (((0x10000 – HEAD – LEN – COMD – DF1 – DF2 – DF3 – DF4) % 0XFF) != CS){
    should instead be:
    if (((0x10000 – HEAD – LEN – COMD – DF1 – DF2 – DF3 – DF4) & 0XFF) != CS){

    • Teodor Costachioiu
      Teodor Costachioiu on

      Hi Mark,

      In the datasheet, the checksum is computed as:
      CS = MOD ((65536-(HEAD+LEN+CMD+DATA)), 256)
      65536 is 0x10000
      256 is 0xFF
      In Arduino IDE the modulo operator is %

      Thus, we have
      if (((0x10000 – HEAD – LEN – COMD – DF1 – DF2 – DF3 – DF4) % 0XFF) != CS){
      ..
      }

  5. Avatar

    Hello,
    Thanks for the code, but I’m working with a mkrwan 1300 and it only has 1 uart port (and software serial is not available)
    I changed your code to use the regular uart, to know if the code works, I let a led go on before your func (start, stop, …)
    But the led never switches of. The code passes flush, but gets stuck at stop_autosend
    Any idea why?

    This is the code:

  6. Avatar

    Hi

    I copy pasted your code and tried to upload it to my Arduino Uno but I am getting the following error:

    “Sketch uses 5044 bytes (15%) of program storage space. Maximum is 32256 bytes.

    Global variables use 570 bytes (27%) of dynamic memory, leaving 1478 bytes for local variables. Maximum is 2048 bytes.”

    the code complied, but the orange error message is prompting up when im trying to upload/

    This is my first project with Arduino, your help would be much appreciated

    Best Regards

Leave A Reply

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