ESP8266MOD code for ZPHS01B sensor

I tried the following code on ESP8266MOD for the ZPHS01B sensor module.

#include <Wire.h>

// ZPHS01B sensor address
#define ZPHS01B_ADDR 0xFF


void setup() {
 Serial.begin(9600);
 Wire.begin();
}


void loop() {
 // Request 5 bytes of data from the ZPHS01B sensor
 Wire.beginTransmission(ZPHS01B_ADDR);
 Wire.write(0x01);
 Wire.write(0x86);
 Wire.write(0x00);
 Wire.write(0x00);
 Wire.write(0x00);
 Wire.write(0x00);
 Wire.write(0x00);
 Wire.write(0x79);
 Wire.endTransmission();


 // Wait for sensor to complete measurement
 delay(100);


 // Read data from sensor
 Wire.requestFrom(ZPHS01B_ADDR, 9);
 byte data[26];
 for (int i = 0; i < 26; i++) {
   data[i] = Wire.read();
 }


 // Convert raw sensor data to meaningful values
 float temperature = ((data[11] * 256 + data[12]) - 435) / 100.0;
 float humidity = data[13] * 256 + data[14];
 float pm25 = (data[4] * 256 + data[5]) / 10.0;

 // Print sensor data to serial monitor
 Serial.print("Temperature: ");
 Serial.print(temperature);
 Serial.println(" C");
 Serial.print("Humidity: ");
 Serial.print(humidity);
 Serial.println();
 Serial.print("PM2.5: ");
 Serial.print(pm25);
 Serial.println(" ug/m3");


 // Wait before taking next measurement
 delay(5000);
}

And getting the below-mentioned output seems to be a garbage value or something I can't interpret. Kindly help me out here

�k�d@�O@������Temperature: 655.35 C

Humidity: 655.35 %

PM2.5: 6553.50 ug/m3

Temperature: 655.35 C

Humidity: 655.35 %

PM2.5: 6553.50 ug/m3

Here is the link to the ZPHS01B Datasheet for your reference.

hi,

please share the working code,

awaiting for your reply sonaliiii

I couldn't solve the issue but am still working on it. I would really appreciate your help regarding the same. Let's help out each other by sharing your piece of code where you are getting the issue, in that way may be I will be able to find out the error and solve the same.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.