Git Product home page Git Product logo

karserdsm501's Introduction

Arduino library for DSM501 dust sensor

Example

#define DUST_SENSOR_PIN_PM10  3  //Must be the pins that
#define DUST_SENSOR_PIN_PM25  2  //support interrupts

#define INTERVAL_COUNTDOWN 1000
#define INTERVAL_READ 30000

#include <KarserDSM501.h>
// ISRs forward declaration
void pm10_handleInterrupt();
void pm25_handleInterrupt();
// init pm10 and pm25 instances
KarserDSM501 pm10(DUST_SENSOR_PIN_PM10, pm10_handleInterrupt);
KarserDSM501 pm25(DUST_SENSOR_PIN_PM25, pm25_handleInterrupt);
// handle ISRs
void pm10_handleInterrupt() { pm10.handleInterrupt(); }
void pm25_handleInterrupt() { pm25.handleInterrupt(); }


unsigned long timer = 0;

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

void loop() {
  if (!pm10.isReady() && (millis() >= timer + INTERVAL_COUNTDOWN)) {
    Serial.println("DSM501 warm up: " + String(pm10.getReadyCountdown()));
    timer += INTERVAL_COUNTDOWN;
  } else if (millis() >= timer + INTERVAL_READ) {
    timer += INTERVAL_READ;
    Serial.println("pm10: "+String(pm10.readPM())+" pm2.5: "+String(pm25.readPM()));    
  }
}

Here is the console output

18:53:40.791 -> DSM501 warm up: 59
...
18:54:36.845 -> DSM501 warm up: 3
18:54:37.841 -> DSM501 warm up: 2
18:54:38.837 -> DSM501 warm up: 1
18:54:39.832 -> DSM501 warm up: 0
18:55:09.855 -> pm10: 21.39 pm2.5: 6.65
18:55:39.872 -> pm10: 20.31 pm2.5: 5.57
18:56:09.897 -> pm10: 28.64 pm2.5: 7.07
18:56:39.920 -> pm10: 17.89 pm2.5: 6.92
18:57:09.940 -> pm10: 25.84 pm2.5: 7.86
18:57:39.937 -> pm10: 23.35 pm2.5: 6.83
18:58:09.959 -> pm10: 29.80 pm2.5: 6.84
18:58:39.980 -> pm10: 18.68 pm2.5: 6.98
18:59:10.003 -> pm10: 27.84 pm2.5: 7.54

karserdsm501's People

Contributors

karser avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

abelha-app

karserdsm501's Issues

Incorrect values.

Hello. I came across your library and an example for taking readings from the dsm501 sensor. Your example is the best. But here's the problem when I add mqtt to your example. All indications become incorrect. I guess the problem is in time. But I can't figure out how to solve it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.