Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.