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() ...