IoT project using Intel Edison, SmartLiving, sensors (light, gas) and actuators (step motor, LED bar).
The Blinds are controller manually by the user on his SmartLiving space, or they can be automatically controlled based on the information received from the light sensor. The blinds also work like a visual alarm when the gas level detected is higher than a certain threshold.
var smartliving = require('smartliving');
var mraa = require('mraa');
var Uln200xa_lib = require('jsupm_uln200xa');
var LEDBar = require("jsupm_my9221");
var myUln200xa_obj = new Uln200xa_lib.ULN200XA(4096, 8, 9, 10, 11);
var myLEDBar = new LEDBar.MY9221(2, 3);
var analogPin0 = new mraa.Aio(0); //setup access analog input Analog pin #0 (A0) LIGHT SENSOR
var analogPin1 = new mraa.Aio(1); //setup access analog input Analog pin #1 (A1) GAS SENSOR
var analogValuePin0;
var analogValuePin1;
var v_Pin0 = [500, 500, 500, 500];
var darkness_avg = 0;
var i = 0;
var j = 0;
var state = false; //Boolean to hold the state of Led
myUln200xa_obj.goForward = function()
{
myUln200xa_obj.setSpeed(2);
myUln200xa_obj.setDirection(Uln200xa_lib.ULN200XA.DIR_CW);
myUln200xa_obj.stepperSteps(768);
};
myUln200xa_obj.reverseDirection = function()
{
myUln200xa_obj.setDirection(Uln200xa_lib.ULN200XA.DIR_CCW);
myUln200xa_obj.stepperSteps(768);
};
myUln200xa_obj.stop = function() //Must be called, not included here !!!
{
myUln200xa_obj.release();
};
myUln200xa_obj.quit = function() //Must be called, not included here !!!
{
myUln200xa_obj = null;
Uln200xa_lib.cleanUp();
Uln200xa_lib = null;
console.log("Exiting");
process.exit(0);
};
smartliving.credentials = require('./credentials');
// Set up the Light Sensor
smartliving.addAsset(
"0",
"Light sensor",
"Controls the lights of the house, using a light sensor",
"int",
function(){
console.log("Light sensor enrolled")
}
);
// Set up the darkness indicator
smartliving.addAsset(
"1",
"Darkness indicator",
"Send darkness indication",
"int",
function(){
console.log("Darkness indicator enrolled")
}
);
// Set up the LED Actuators
smartliving.addAsset(
"2",
"LED Actuator",
"LED Actuator",
"bool",
function(){
console.log("LED Actuator enrolled")
},
function() {
if (state) {
myUln200xa_obj.goForward();
myLEDBar.setBarLevel(0, true);
}
else {
myUln200xa_obj.reverseDirection();
myLEDBar.setBarLevel(8, true);
}
state = !state; //invert the ledState
}
);
smartliving.connect();
setInterval(function(){
analogValuePin1 = analogPin1.read();
console.log('Gas Level : ' + analogValuePin1);
if (analogValuePin1 > 200)
{
setTimeout(function()
{
myLEDBar.setBarLevel(0, true);
}, 1000);
myLEDBar.setBarLevel(8, true);
}
else
{
analogValuePin0 = analogPin0.read();
v_Pin0[i] = analogValuePin0;
darkness_avg = 0;
for (j = 0; j < 4; j++) {
darkness_avg += v_Pin0[j];
}
darkness_avg /= 4;
smartliving.send(analogValuePin0, "0")
smartliving.send(darkness_avg, "1")
i = i + 1;
if (i > 3){
i = 0;
}
}
}, 3000);
Comments
Please log in or sign up to comment.