Created
November 25, 2014 04:03
-
-
Save Resseguie/4c4a554eae159a819875 to your computer and use it in GitHub Desktop.
spark-io sensor example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var five = require("johnny-five"), | |
Spark = require("spark-io"), | |
board, sensor; | |
// Create Johnny-Five board connected via Spark | |
board = new five.Board({ | |
io: new Spark({ | |
token: process.env.SPARK_TOKEN, | |
deviceId: process.env.SPARK_DEVICE_ID | |
}) | |
}); | |
board.on("ready", function() { | |
sensor = new five.Sensor({ | |
pin: "A7", | |
freq: 1000 | |
}); | |
sensor.on("data", function() { | |
// TMP36 | |
var mV = this.value * (3300/1024); | |
var celsius = (mV - 500) / 10; | |
var fahrenheit = celsius * (9 / 5) + 32; | |
console.log(celsius + "°C", fahrenheit + "°F"); | |
}); | |
}); | |
// @markdown | |
// - [TMP36 - Temperature Sensor](https://www.sparkfun.com/products/10988) | |
// @markdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment