Skip to content

Instantly share code, notes, and snippets.

@Resseguie
Created November 25, 2014 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Resseguie/4c4a554eae159a819875 to your computer and use it in GitHub Desktop.
Save Resseguie/4c4a554eae159a819875 to your computer and use it in GitHub Desktop.
spark-io sensor example
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