How to Interface Winsen ZH06 Laser Dust Sensor with Arduino

Learn how to interface the Winsen ZH06 laser dust sensor with Arduino for monitoring PM1.0, PM2.5 and PM10 air quality parameters.
Interfacing Winsen ZH06 Dust Sensor with Arduino CIRCUITSTATE Electronics Featured Image Landscape

Environmental monitoring is one of the easiest DIY projects you can undertake, thanks to the availability of compact, low-power, and affordable sensors. These sensors include temperature sensors, pressure sensors, humidity sensors, ambient light sensors, gas sensors, and more. Among these, air quality sensors are particularly important when it comes to monitoring the air you breathe. Air quality is influenced by various factors, including the composition of gases and the type and quantity of particles in the air. In this tutorial, we will explore how a low-cost air quality sensor can provide valuable insights into the air you breathe. You will learn about the working principle of the sensor and how to seamlessly interface it with your favourite Arduino boards.

Particulate Matter

Particulate Matter (PM) are microscopic particles of solid or liquid matter suspended in the air. The particles and the air together is called the aerosol. PM is commonly specified by their size in micrometer (um), since they are very small. The following illustration shows the sizes of commonly found particles including biological bacteria and viruses.

The amount PM in the air we breath is extremely important to a healthier life. Since the particles are very small, they can deeply penetrate through our lungs and reach all internal parts of our body through the bloodstream. Such foreign materials in the bloodstream are almost always harmful to our health in some way and can lead to severe lifestyle diseases like heart disease, lung disease and cancer which lead to premature deaths ☠️. So it is very important to make sure that the air we breath are free from are free from harmful PM. The easiest way to achieve this is to keep our surroundings clean by keeping the sources of PM to a minimum. The next step is to avoid exposure to PM contaminated air by using respirators (not masks) and powered air purifiers. Most commercial air purifiers you can buy today include a special sensor to measure the density of PM in the air. The density of PM is specified in microgram per cubic meter (ug/m3). The densities of PM of size in the range of 1 um, 2.5 um and 10 um are the most widely used metrics to indicate the quality of air in terms of PM densities. These are called PM1.0, PM2.5 and PM10 respectively. The following chart shows the safe and hazardous levels of PM densities.

Inhalable Particulate Matter and Health(PM2.5 and PM10) California Air Resources Board
Particulate matter size comparison. Source: California Air Resources Board

Today, we are introducing you a PM density sensor called ZH06 from a company called Winsen. Winsen makes gas and air quality sensors. The ZH06 uses a laser to measure the densities of PM1.0, PM2.5 and PM10 in the air. You can interface this sensor easily with any Arduino boards and make an air quality monitoring device for your own use. We will show you everything you need to know about the sensor and the code.

Winsen ZH06

The Winsen ZH06 is a laser dust sensor that can measure PM1.0, PM2.5 and PM10 densities. You can buy this sensor for around INR 1.7K from places like Robu. It is a compact and self contained sensor with serial data output and PWM output. So it is easy to interface it with any of your microcontroller boards.

Specifications

SpecificationValue
ModelZH06/ZH06-I
Detection Range0.3-10 um
Effective Range0-1000 ug/m³
Detection Interval1 s
PM2.5 Detection Accuracy0-100 ug/m³: ±15 ug/m³
101-1000 ug/m³: ±15% Reading
(Test Condition: 25 ±2°C, 50 ±10% RH, TSI8530, Cigarette, GBT18801-2015)
Preheating Time30 s
OutputUART TTL Output (3.3V level)
PWM Output (3.3V level)
Working Voltage4.9~ 5.5 V (DC)
Logical Voltage3.3V
Working Current<120 mA
Dormancy Current<20 mA
Response TimeT90 < 45s
Working Humidity0~80% RH (No Condensation)
Working Temperature-10~60 °C
Storage Temperature– 30~70 °C
Dimensions47 x 37 x 12.2 mm (L x W x H)
Weight<30g
MTTFContinuous > 10000H

Working Principle

The working principle of the laser-based dust or particulate density sensors is based on light scattering. When light passes through a medium that contains the particles, the light is scattered when the size of the particles is equal to or more than the wave length of the light itself. This is called Mie Scattering. A light source like laser is a good source of same wavelength and coherent light. The laser light is allowed to pass through a sealed chamber that sustains a continuous flow of ambient air with the help of a fan. A photodetector sensor is placed near the chamber to measure the intensity of the scattered light. When there is more amount of particles in the air, the intensity of the scattered light will be higher. Using special algorithms, these intensities can be approximated to the density of the particles in the air. A particulate sensor can be designed to measure the intensity of the scattered light or the unscattered light. In both cases, the intensities will indicate the density of the particulates in the air. Using different wavelengths, or using different algorithms, we can measure the densities of different sized particles. This process is illustrated below.

Laser Dust Sensor Working Principle Illustration by CIRCUITSTATE Electronics
Laser dust sensor working principle

Pinout

Winsen ZH06 Laser Dust Sensor Pinout
ZH06 pinout. Observe the location of the first pin.
Pin #NameFunction
1VDDPositive supply
2GNDNegative supply
3NCNot connected
4RXDUART Receive pin
5TXDUART transmit pin
6NCNot connected
7NCNot connected
8PWMPWM output
ZH06 pinout with wire colors.

The sensor comes with an 8-pin, 1.25 mm Molex PicoBlade series SMD right-angle connector (Molex 532610871) on the sensor and a compatible double-sided cable (Molex 510210800).

Wiring

Interfacing Winsen ZH06 Dust Sensor with Arduino Wiring with ESP32 by CIRCUITSTATE Electronics
Wiring ZH06 with ESP32

We are going to use a FireBeetle-ESP32E board from DFRobot for demonstrating the capabilities of the sensor. We just need to connect four wires from the sensor to the microcontroller board. Wire up the sensor according to the following table. If you are planning to use a different microcontroller board, you can wire it up accordingly.

ZH06FireBeetle-ESP32E
VDDVCC
GNDGND
RXDD11 (GPIO16)
TXDD10 (GPIO17)

Since the sensor came with a double-sided cable, we had to cut one end and solder a 2.54 mm header pins in order to connect it to a breadboard.

CSE_ZH06 Library

68747470733a2f2f736f6369616c6966792e6769742e63692f4349524355495453544154452f4353455f5a4830362f696d6167653f6465736372697074696f6e3d3126666f6e743d4b6f486f26666f726b733d31266973737565733d31266c6f676f3d68747470732533412532462532467777772e6369726375697473746174652e636f6d25324677702d636f6e74656e7425324675706c6f6164732532463230323425324630352532464349524355495453544154452d522d456d626c656d2d32303035323032342d322e737667266e616d653d31267061747465726e3d43697263756974253230426f6172642670756c6c733d31267374617267617a6572733d31267468656d653d4175746f

To make it easy to interface the sensor with any Arduino-compatible boards, CIRCUITSTATE has made a custom library called CSE_ZH06 for the Arduino platform. This open-source library can be downloaded from our GitHub or directly installed from the Arduino Library Manager. The library is also available through PlatformIO.

CSE_ZH06 library supports both hardware serial ports and software serial ports. For boards with only one hardware UART port, you may want to use that for general debugging or programming the board. That means, we can not connect the sensor to that port. In such cases, we can use the SoftwareSerial library to use any free GPIO pins for the TX and RX functionalities. ESP32 has multiple hardware serial ports that can be mapped to almost all of the GPIO pins, giving more flexibility in the wiring. If you are using a different board, check if it has multiple hardware serial ports. Boards like Arduino Uno, Nano etc, only have single hardware serial ports that are used for programming. You need to use software serial ports with such boards.

Arduino Code

Following is the Read_PM_Data example included in the CSE_ZH06 library. This program reads the PM1.0, PM2.5 and PM10 densities and print the values to the serial monitor every second. We are using he Serial1 port of ESP32 for talking to the sensor while the default Serial (Serial0) is used for printing the values. The CSE_ZH06 library depends on the CSE_MillisTimer library, also from CIRCUITSTATE. Make sure to install it before compiling the example.


//======================================================================================//
/*
  Filename: Read_PM_Data.ino
  Description: Reads the PM data from the Winsen ZH06 laster dust sensor using the `CSE_ZH06` library.
  Framework: Arduino, PlatformIO
  Author: Vishnu Mohanan (@vishnumaiea, @vizmohanan)
  Maintainer: CIRCUITSTATE Electronics (@circuitstate)
  Version: 0.0.1
  License: MIT
  Source: https://github.com/CIRCUITSTATE/CSE_ZH06
  Last Modified: +05:30 20:40:55 PM 23-12-2024, Monday
 */
//======================================================================================//

#include <Arduino.h>
#include <CSE_ZH06.h>

// Define the serial port pins here.
#define  PIN_SERIAL_TX1  16
#define  PIN_SERIAL_RX1  17

CSE_ZH06 pmSensor (Serial1);  // Create a CSE_ZH06 object to access the sensor

// Setup runs once.
void setup() {
  Serial.begin (115200);  // Initialize the debug serial port
  Serial1.begin (9600, SERIAL_8N1, PIN_SERIAL_RX1, PIN_SERIAL_TX1); // Initialize the sensor serial port

  pmSensor.begin(); // Initialize the sensor
}

// Inifinite loop.
void loop() {
  if (pmSensor.getPmData()) {
    Serial.println ("Data received. Printing data..");
    Serial.print ("PM1.0: ");
    Serial.print (pmSensor.pm1);
    Serial.println (" ug/m3");

    Serial.print ("PM2.5: ");
    Serial.print (pmSensor.pm25);
    Serial.println (" ug/m3");

    Serial.print ("PM10: ");
    Serial.print (pmSensor.pm10);
    Serial.println (" ug/m3");
    Serial.println();
  }
  
  else {
    Serial.println ("Data not received. Retrying..");
  }

  delay (1000);

  // pmSensor.sleep();
  // delay (3000);

  // pmSensor.wake();
  // delay (3000);
}
Read_PM_Data.ino

The sensor supports multiple modes and we are using the Question & Answer (Command & Response) mode here. The following image shows the command we need to send and the expected reply format from the sensor. You can check the datasheet of the sensor for more details on the commands.

Winsen ZH06 Laser Dust Sensor PM Value Request Format
ZH06 Question & Answer mode data format.

After uploading the code, you can open the serial monitor and get the PM values.

Data received. Printing data..
PM1.0: 6 ug/m3
PM2.5: 8 ug/m3
PM10: 9 ug/m3

Data received. Printing data..
PM1.0: 6 ug/m3
PM2.5: 8 ug/m3
PM10: 9 ug/m3

Data received. Printing data..
PM1.0: 6 ug/m3
PM2.5: 8 ug/m3
PM10: 9 ug/m3

Data received. Printing data..
PM1.0: 6 ug/m3
PM2.5: 8 ug/m3
PM10: 9 ug/m3

Data received. Printing data..
PM1.0: 6 ug/m3
PM2.5: 8 ug/m3
PM10: 9 ug/m3

Data received. Printing data..
PM1.0: 6 ug/m3
PM2.5: 8 ug/m3
PM10: 9 ug/m3
Serial Monitor
Winsen ZH06 Laser Dust Sensor Reading Data VS Code Serial Monitor
PM values printed to the Serial Monitor in VS Code

Hope this tutorial informative for you. We will come with more tutorials in the future. We are also planning to build an air quality monitor device with this sensor. Stay tuned for that. Happy Coding! 😉

  1. Particulate Matter (PM) – US EPA
  2. Particulate Matter Sensing for Air Quality Measurements – Sensirion
  3. Winsen ZH06 – Product Page
  4. Buy Winsen ZH06 – Robu.in
  5. Winsen-ZH06-Datasheet-V1.2 [PDF]
  6. Winsen-ZH06-Datasheet-V1.1 [PDF]
  7. CSE_ZH06 – CIRCUITSTATE – GitHub
  8. CSE_MillisTimer – CIRCUITSTATE – GitHub
  9. Molex PicoBlade 532610871 – 1.25 mm Header Horizontal SMD
  10. Molex PicoBlade 510210800 – 1.25 mm Receptable
Share to your friends
Vishnu Mohanan

Vishnu Mohanan

Founder and CEO at CIRCUITSTATE Electronics

Articles: 96

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.