Using Johnny-Five with Grove's Air quality sensor component on the Intel Edison Arduino Breakout. This shield and component will work with any Arduino pin-out compatible hardware platform.

Run this example from the command line with:

node eg/grove-gas-tp401-edison.js
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
  io: new Edison()
});

board.on("ready", function() {

  // Plug the Air quality sensor
  // module into the Grove Shield's A0 jack
  var gas = new five.Sensor("A0");
  var startAt = Date.now();

  // Plug the Piezo module into the
  // Grove Shield's D6 jack.
  var alarm = new five.Piezo(6);

  gas.on("change", function() {
    // According to this document:
    // https://software.intel.com/en-us/iot/hardware/sensors/grove-air-quality-sensor
    // The sensor needs 2-3 minutes for "warm up"
    //
    if (isWarming()) {
      return;
    }

    var ppm = toPPM(this.value);

    if (ppm > 400) {
      if (!alarm.isPlaying) {
        alarm.frequency(five.Piezo.Notes.d5, 5000);
      }
    }
  });

  function isWarming() {
    return (Date.now() - startAt) < 180000;
  }

  function toPPM(value) {
    // https://www.seeedstudio.com/wiki/images/e/eb/TP-401A_Indoor_Air_quality_gas_sensor.pdf
    return 25 * value / 1023;
  }

  function quality(ppm) {
    // Adapted from:
    // http://iotdk.intel.com/docs/master/upm/classupm_1_1_t_p401.html
    if (ppm < 50) {
      return "Fresh Air";
    }
    if (ppm < 200) {
      return "Normal Indoor Air";
    }
    if (ppm < 400) {
      return "Low Pollution";
    }
    if (ppm < 600) {
      return "High Pollution - Action Recommended";
    }
    return "Very High Pollution - Take Action Immediately";
  }
});

Additional Notes

For this program, you'll need: Intel Edison Arduino Breakout Grove Base Shield v2 Grove - Buzzer Module Grove - Air quality sensor

  • [Grove - Air quality sensor](http://www.seeedstudio.com/depot/Grove-Air-quality-sensor-p-1065.html

 

Component Classes in this example:

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub