Secure My Home built using the Intel IOT kit and Grove Starter Kit Plus. This app uses the sound, vibration and motion sensor and buzzes when an intruder enters the home or when noise level is higher than the usual limit.
The plan is to attach Camera module to take pictures on motion detection and send the data to IBM blue mix and notify users on their mobile devices using push notification.
// change this to false to use the hand rolled version
var useUpmVersion = true;
// we want mraa to be at least version 0.6.1
var mraa = require('mraa');
var version = mraa.getVersion();
if (version >= 'v0.6.1') {
console.log('mraa version (' + version + ') ok');
}
else {
console.log('meaa version(' + version + ') is old - this code may not work');
}
var upmBuzzer = require("jsupm_buzzer");// Initialize on GPIO 5
var myBuzzer = new upmBuzzer.Buzzer(5);
var chords = [];
chords.push(upmBuzzer.DO);
chords.push(upmBuzzer.RE);
chords.push(upmBuzzer.MI);
chords.push(upmBuzzer.FA);
chords.push(upmBuzzer.SOL);
chords.push(upmBuzzer.LA);
chords.push(upmBuzzer.SI);
chords.push(upmBuzzer.DO);
chords.push(upmBuzzer.SI);
var chordIndex = 0;
// Print sensor name
console.log(myBuzzer.name());
function SoundAlert() {
if (chords.length != 0) {
//Play sound for one second
console.log(myBuzzer.playSound(chords[chordIndex], 1000000));
chordIndex++;
//Reset the sound to start from the beginning.
if (chordIndex > chords.length - 1)
chordIndex = 0;
}
}
//setInterval(melody, 100);
// Print message when exiting
var upmMicrophone = require("jsupm_mic");
// Attach microphone to analog port A0
var myMic = new upmMicrophone.Microphone(0);
var threshContext = new upmMicrophone.thresholdContext;
threshContext.averageReading = 0;
threshContext.runningAverage = 0;
threshContext.averagedOver = 2;
var is_running = false;
// Infinite loop, ends when script is cancelled
// Repeatedly, take a sample every 2 microseconds;
// find the average of 128 samples; and
// print a running graph of the averages
while (1==1) {
console.log("in loop");
var buffer = new upmMicrophone.uint16Array(128);
var len = myMic.getSampledWindow(60, 128, buffer);
if (len) {
var thresh = myMic.findThreshold(threshContext, 30, buffer, len);
myMic.printGraph(threshContext);
if (thresh) {
console.log("Threshold is " + thresh);
SoundAlert();
displayAlert('Security Alarm');
}
else
{
console.log("Not in Threshold is " + thresh);
displayAlert('No Alert');
}
}
}
function displayAlert(message) {
var lcd, display;
if (useUpmVersion) {
lcd = require('jsupm_i2clcd');
display = new lcd.Jhd1313m1(0, 0x3E, 0x62);
}
else {
lcd = require('./lcd');
display = new lcd.LCD(0);
display.setColor(0, 60, 255);
}
display.setCursor(1, 1);
display.write(message);
}
// Print message when exiting
process.on('SIGINT', function () {
console.log("Exiting...");
process.exit(0);
});
Comments