Run this example from the command line with:

node eg/sensor-photon-weather-shield-moisture.js
var five = require("johnny-five");
var Photon = require("particle-io");
var board = new five.Board({
  io: new Photon({
    token: process.env.PARTICLE_TOKEN,
    deviceId: process.env.PARTICLE_PHOTON_1
  })
});

var period = process.argv[2] || 1000;

board.on("ready", function() {
  console.log("Connected");

  var moisture = new five.Sensor({
    pin: "A1",
    enabled: false
  });
  var power = new five.Pin("D5");

  moisture.on("data", function() {
    if (power.isHigh) {
      console.log("Moisture: ", this.value);
      power.low();
      moisture.disable();
    }
  });

  this.loop(period, function() {
    if (!power.isHigh) {
      power.high();
      moisture.enable();
    }
  });
});


Additional Notes

For this program, you'll need: Particle Photon SparkFun Photon Weather Shield SparkFun Soil Moisture Sensor

 

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