Honeywell PM2.5 particle sensor output with Arduino

Hello!

I am a student using Arduino for the first time, so I am not very good with it. Apologies for the stupid questions in advance :smiley:

I have been trying to use the Honeywell IH-PMC-002 particle sensor to analyze smoke machine/hazer smoke particles with Arduino for a school project. However, for some reason i am not receiving any output from the RX/TX ports. The sensor uses UART, but it is also possible to use L2C.

Here is the data sheet for the sensor
Honeywell IH-PMC-002 sensor data sheet

I have tried many variations of the code, but here is one of them:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
const int sensorProtocolPin = 3; // Control pin for selecting UART mode, connect to digital pin 2

void setup() {
  Serial.begin(1200);
  mySerial.begin(1200);  // Software Serial for sensor communication, set to 1200 baud
  pinMode(sensorProtocolPin, OUTPUT);

  // Set pin 2 (sensorProtocolPin) to HIGH for UART protocol
  digitalWrite(sensorProtocolPin, HIGH);

  // Initialize the sensor
  delay(1000); // Allow time for the sensor to start
}

void loop() {
  // Start measurement
  sendCommand(0x11);

  // Wait for the sensor to complete the measurement
  delay(5000); // Adjust this delay based on your sensor's documentation

  // Stop measurement
  sendCommand(0x10);
  delay(5000);

  // Request PM2.5 measurement
  sendCommand(0x00);

  // Wait for the sensor to respond
  delay(1000);

  // Read and print the response
  while (Serial.available() > 0) {
    int pm25 = mySerial.read(); // Read the PM2.5 measurement
    Serial.print("PM2.5 Measurement: ");
    Serial.println(pm25);
  }

  // Wait before making the next request
  delay(5000);
}

void sendCommand(byte command) {
  mySerial.write(command);
}

When I run the code with the sensor connected, there is no output at all. Is there something stupid in the code that could be messing up the output?

I also tried to use the PWM output pin to analyse the data, but I didn't really understand how it works. With the PulseIn command I got some output, but it made no sense at all.

Here is the code I tried to use to get the PWM values:

#define pwmpin 1

int pwmvalue;

void setup () {
  Serial.begin(1200);
  pinMode(pwmpin, INPUT);
}

void loop(){
  pwmvalue = pulseIn (pwmpin, HIGH);
  Serial.println (pwmvalue);
}

I would really appreciate any help regarding the situation, as I am kinda lost with this myself.

The commands are not just single bytes.

START: You send (hex) FE A5 00 11 B6
You receive FE A5 02 00 00 11 [CS]

The first thing to do is tell us you are using a proper, external, 5 volt supply for your Honneywell device.

So, is the program version you included the one you want help with?
And finally, make a block diagram showing your Arduino and the Honeywell and show how you are connecting the Arduino and ALL the Honeywell pin connections.

Thanks for the quick response!

For the power supply I am using the 5 volt output on the Arduino Mega board. Does it need to be external?

Yes, that is the code I would like to get help with.

Here is the diagram of the connections:

Oh I see!

How would I write the hex command in the code? Writing it just instead of 0x00 does not work.

sendCommand(0xFE);
sendCommand(0xA5);
sendCommand(0x00);
sendCommand(0x11);
sendCommand(0xB6);

You also have the TX and RX connections reversed

TX->RX
RX<-TX

Thanks! I will try that soon.

And oops, my bad. That's my mistake, only in the diagram.

Here is the code that I tried now. Still no output for some reason.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
const int sensorProtocolPin = 3; // Control pin for selecting UART mode, connect to digital pin 2

void setup() {
  Serial.begin(1200);
  mySerial.begin(1200);  // Software Serial for sensor communication, set to 1200 baud
  pinMode(sensorProtocolPin, OUTPUT);

  // Set pin 2 (sensorProtocolPin) to HIGH for UART protocol
  digitalWrite(sensorProtocolPin, HIGH);

  // Initialize the sensor
  delay(1000); // Allow time for the sensor to start
}

void loop() {
  
  // Start measurement
  sendCommand(0xFE);
  sendCommand(0xA5);
  sendCommand(0x00);
  sendCommand(0x11);
  sendCommand(0xB6);

  // Wait for the sensor to complete the measurement
  delay(5000); // Adjust this delay based on your sensor's documentation

  // Request PM2.5 measurement
  sendCommand(0xFE);
  sendCommand(0xA5);
  sendCommand(0x00);
  sendCommand(0x00);
  sendCommand(0xA5);

  // Wait for the sensor to respond
  delay(1000);

  // Read and print the response
  while (Serial.available() > 0) {
    int pm25 = mySerial.read(); // Read the PM2.5 measurement
    Serial.print("PM2.5 Measurement: ");
    Serial.println(pm25);
  }

  // Wait before making the next request
  delay(5000);
}

void sendCommand(byte command) {
  mySerial.write(command);
}

The Arduino is NOT a power supply! Did you see in the data sheet you linked to that your device needs 100ma maximum? The Arduino 5 volt pin can supply about 20% of that amount. Use a proper 5 volt supply and you will quickly see your other problems disappear!

Did you set the Serial monitor to 1200 bps as well? (default is 9600). Why even choose such a super low number? I prefer to set it to 115200.

Add a line like
Serial.println("Hello, world!");
in your setup() . That way you know whether prints sent by the Arduino actually show up.

I don't see your code send a wake-up pulse (in the form of a single byte with value 0xFF) to the sensor, as mentioned in the datasheet.

Oh, I did not know that. Feel stupid now. Thanks for the response!

I will be getting an external power supply as soon as possible.

Please don't say that. Stupid people do not ask for help.

100 mA should be no problem for the 5V pin of the Arduino, especially when running on USB power. It's becoming an issue only of the Vin is used with a high voltage, like 12V, as that may cause the regulator to overheat.

That 20 mA limit is for an output pin.

Nonetheless it's a good idea to use a proper 5V power supply (e.g. a mobile phone charger) for a finished project.

Oh! well in that case, I will continue trying trough the Arduino 5V pin for now. I should be able to get an external PSU later on. I tried adding the Hello world test, that comes trough normally. I also added the wake-up command (0xFF), but I don't think it should be needed, cause the sensor is by default not in the sleep mode according to the data sheet.

Regarding the baud rate situation, I thought I needed to set it to the 1200 the sensor itself uses. I have also tried it with the default 9600 baud rate.

Here is the picture of the IDE response I get.

It might be stuck in standby or sleep mode.
Why don't you power everything off then on.

Done! still nothing.

The sensor indeed needs 1200 bps.

That is however independent from what you choose for your other Serial connection - the one to the USB and Serial monitor. The two do not need to be the same.

I think everyone is out of suggestions

One more suggestion then.

Set the sensor in I2C mode, do an I2C address scan, see if it even shows up. If not, fix your wiring. If still not, sensor is probably defective.