This Arduino library provides support for working with the DSM501 particulate matter sensor. It allows you to easily interface with the sensor and read particulate matter concentrations.
- Download this repository as a ZIP file.
- In the Arduino IDE, go to
Sketch > Include Library > Add .ZIP Library...
. - Select the downloaded ZIP file.
- The library is now installed and ready to use.
-
Include the library at the top of your Arduino sketch:
#include "DSM501.h"
-
Create an instance of the DSM501 class and specify the pin number and an interrupt handler function:
int sensorPin = 2; // Replace with your actual sensor pin DSM501 dsm501(sensorPin, yourInterruptHandler);
-
Implement your interrupt handler function. This function will be called on each state change of the sensor's output pin:
void yourInterruptHandler() { dsm501.handleInterrupt(); }
-
In your Arduino setup() function, initialize the sensor:
void setup() { Serial.begin(9600); // Other setup code... dsm501.isReady(); // Warm-up the sensor }
-
In your loop, you can read particulate matter concentrations:
void loop() { float pmConcentration = dsm501.readPM(); // Do something with the concentration value (e.g., display it or send it over a network) delay(1000); // Adjust the delay as needed }
For a complete example sketch, check the examples folder in this repository.
If you would like to contribute to this library, please create a fork of the repository, make your changes, and submit a pull request. Your contributions are greatly appreciated!
This library is released under the MIT License.