O'Reilly logo

Programming the BeagleBone by Yogesh Chavan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program to check light intensity

Write the following code in Cloud9 and save it as ldr.js. Run the program and check the output voltage. If the LDR is exposed to bright sunlight, you may get the output message—Looks like a bright sunny day. If this is not possible, point a torch on the LDR surface. You should see the voltage has increased. Based on voltage value, you can guess the light brightness and respond by sending an SMS/e-mail or turn on a smart bulb in case of low light condition. You can also change the intensity of bulb according to the light intensity detected. The code for ldr.js is as follows:

var b = require('bonescript'); var loopTime = 2000; var LDR = 'P9_38'; var loopTimer = setInterval(readVoltageLoop, loopTime); function readVoltageLoop() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required