Paul Langdon
Published

Example: Light Sensor

Sample Light Sensor on Intel Edison in Node.js

BeginnerProtip1,175
Example: Light Sensor

Story

Read more

Code

Read lux (light level) and write to console

JavaScript
// Load Grove module
var groveSensor = require('jsupm_grove');

// Create the light sensor object using AIO pin 0
var light = new groveSensor.GroveLight(0);

// Read the input and print both the raw value and a rough lux value,
// waiting one second between readings
function readLightSensorValue() {
    console.log(light.name() + " raw value is " + light.raw_value() +
            ", which is roughly " + light.value() + " lux");
}
setInterval(readLightSensorValue, 1000);

Credits

Paul Langdon

Paul Langdon

49 projects • 316 followers
Working as a cloud architect for an IoT hardware company

Comments