loading

Introduction

I have a burglar alarm and fire alarm, but no way of knowing if either are sounding unless I'm in the house. Rather than replace them with 'smart' alternatives, I plan to build a device to listen for loud noises, then determine if the loud noise is a fire or burglar alarm. If the burglar alarm or fire alarm is sounding, the device should send me an email. This instructable is a proof of concept created at Intel's IoT Ignition Lab using an intel edison, programmed using Node.js in the Intel XDK and grove seeed sensor kit.

I was lucky enough to be one of the ten winners in this competition and was invited to Intel's Swindon IoT Ignition Lab for a week to develop my idea into a working prototype. (http://www.gizmodo.co.uk/2015/06/win-all-youll-need-to-become-a-coding-expert-with-intels-iot-challenge/)

I'll hopefully explain how you can create one yourself and provide some useful resources for use on your next project.

How it works

  1. When you first turn it on, the intel edison takes a background noise reading
  2. It then moves into 'monitoring' mode - it sends a temperature and light level reading to the cloud every second. It also takes a sound reading every second, If the sound reading is 20dB greater than the background noise level it sends a variable 'alert level' to the cloud (Intel Enable IoT Cloud Service - which is free!).
  3. The cloud notices the change in variable 'alert level' and sends you an email to let you know your burglar / fire alarm is sounding (you could then check the temperature and light data to see if all is well).

Requirements

You will require the following items to recreate the sound alarm.

  • Intel edison and arduino breakout board
  • Grove Seeed intel edison arduino shield
  • Grove Seeed RGB LCD Display (https://software.intel.com/en-us/iot/hardware/sens...
  • Grove Seeed Analogue Microphone (https://software.intel.com/en-us/iot/hardware/sens...
  • Grove Seeed Light Sensor (https://software.intel.com/en-us/iot/hardware/sens...
  • Grove Seeed Temperature Sensor (https://software.intel.com/en-us/iot/hardware/sens...
  • Grove Seeed Momentary Push Button (https://software.intel.com/en-us/iot/hardware/sens...

You will also need

  • Some USB to micro-USB cables
  • A computer (64 bit) to program the intel edison - I use windows so this guide will focus on Windows, Linux and Mac versions of the software are available.
  • A wireless internet connection

You could quite easily replace the grove seeed branded components with any existing sensors or microphones you have from previous projects.

One last word...

This is my first instructable and my first Node.js project, there are probably a thousand different methods of achieving the same results and I'd welcome any feedback to improve performance or efficiency.

Step 1: Intel Edison Setup

Intel Edison Setup

If this is the first time you've used your edison, or written code to it using Intel's XDK software you'll need to install some drivers and software on your computer first.

There's a great getting started guide on intel's developer zone website, please follow all the steps on this page - https://software.intel.com/en-us/iot/library/ediso...

I've attached some screenshots with hints as you follow the guide.

If you follow all of the steps in the guide above you should have:

  • Installed the intel edison drivers on your computer
  • Installed intel XDK
  • Connected the intel edison to the wifi (via Putty)
  • Established a connection over wifi between intel XDK on your computer and the intel edison
  • (Optional) Set up the Intel XDK serial terminal to connect to the edison

Once that's all set up - move on to the next step!

Step 2: Set Up Enable IoT Cloud Service

IoT Enable Cloud Service

For this project you'll need to setup the edison to automatically send some data up to the cloud - I've chosen to use Intel's enable IoT because it's easy and free, but you could easily edit the code to send the UDP message to a different cloud analytics service provider.

You'll want to follow the guide below to create an enable IoT account (its free), register/activate your intel edison with your account and send a few sample data readings to the cloud to make sure it's all working OK.

https://software.intel.com/en-us/intel-iot-platfor...

For this project we're going to send up three variables to the cloud - temperature, light and the all important 'alert level'. Alert Level is a variable with no units, in normal situations it is at 0, when the sound level exceeds the threshold it changes to 2. We want to use this variable to trigger the cloud to send an email.

Register variables with Enable IoT

You'll need to register the variables we want to send to the cloud on both the edison and the enable iot website.

To register the variables with enable IoT:

  1. Navigate to to https://dashboard.us.enableiot.com/ui/ and log in with your account you created earlier.
  2. Navigate to the account page (bottom link on the menu bar on the left)
  3. Click on the 'Catalog' tab and Click the 'Add a New Catalog Item' button
  4. Create Catalog Items for Temperature, Light and Alert Level as per the screenshots.

Type the following lines into the serial terminal to register the variables with the edison.

  1. iotkit-admin register temp temperature.v1.0
  2. iotkit-admin register light lightsensor.v1.0
  3. iotkit-admin register alert alertlevel.v1.0

Send a couple of sample measurements to make sure all is OK - confirm they've arrived correctly to the cloud using the following lines of code into the serial terminal.

  1. iotkit-admin observation temp 35
  2. iotkit-admin observation light 50
  3. iotkit-admin observation alert 2

Then check back on the charts tab of enable IoT to check your observations have been uploaded correctly.

Finally, set up an email alert so you know when your burglar or fire alarm is sounding by following the steps below:

  1. Select the 'Rules' tab from the menu at the side of enable IoT
  2. Click 'Add a Rule'
  3. Enter the information as per the attached screenshot to alert you when the variable 'alert level' is equal to two.

Step 3: Connect Sensors to the Edison and Run the Code!

Now it's time to connect up your hardware!

  • Connect your microphone to analog pin 0
  • Connect your light sensor to analog pin 1
  • Connect your temperature sensor to analog pin 2
  • Connect your momentary pushbuttn to digital pin 2
  • Connect your LCD display to any IC2 port

Power it up and upload the code from the github repository below (noise_alarm_v2 at the time of writing).

https://github.com/chrisgreen39/SoundAlarm/

Copy the code into a new Intel XDK and upload to your board (see image attached)

For good measure I always run enter the following lines of code before running into the serial monitor (to stop and start iotkit-agent).

  1. systemctl stop iotkit-agent
  2. systemctl start iotkit-agent

Run the code from Intel XDK and you should run as follows:

  1. "Please set background noise level" and "Click button to start..."
  2. When you press the button connected to digital pin two it will take 50 samples of the background noise level and display the word "Listening.."
  3. It will then present you with a screen to say "Complete" and give a readout of the maximum noise level (in volts, not dB).
  4. Finally it will enter "Monitoring..." mode during which it dilligently uploads temperature and light data to the cloud. It is also listening out for noises 20dB louder than the background noise level.
  5. If there is a noise 20dB louder than the background noise level it changes the variable 'Alert Level' to 2 and sends this to the cloud. You will have set up an email notification on enable IoT for this, so should receive an email notification.
  6. The screen turns red to alert the user an alarm has been sounded. It continues to monitor sound, temperature and light in the background.

I've attached a video of it in action below (apologies for the background noise!).

Please also log on to your Enable IoT account click the 'Charts' tab and plot a graph of temperature and light. It's tremendously satisfying shining a torch at the light sensor and watching the response on the IoT Analytics Dashboard!

Step 4: Useful Code, Resources and Credits

Hopefully you've been able to successfully replicate the noise alarm on your edison. As proud as I am of my minor achievement, in it's current form it's not very useful. It does however showcase some very useful segments of code you may find useful in your next project, so I thought I'd highlight them below.

Code required to send observations to enable IoT:

I had some great help from the guys at intel and one other instructables user (magic_toaster/) to get this working. I've included all the Node.js code below you'll need to automate observations being sent to enable IoT. If you change the destination you're sending the UDP message to and it should work with other cloud analytics providers.

//Content for enable IoT
var dgram = require('dgram'); var client = dgram.createSocket('udp4');
// UDP Options
var options = {
    host : '127.0.0.1',
    port : 41234
};
var countmsg =0;
//Intel Enable Iot Send Observation Info.
function sendObservation(name, value, on){
    var msg = JSON.stringify({
        n: name,
        v: value,
        on: on
    });var sentMsg = new Buffer(msg);
    countmsg = countmsg + 1;
    console.log("Sending observation: " + sentMsg + " Len: " + sentMsg.length + " Count: " + countmsg); //add len to
    client.send(sentMsg, 0, sentMsg.length, options.port, options.host);
};
//End content for enable IoT

If you include the code above into your Node.js project all you need to do is call the function "sendObservation" in the manner below to send your observation to the cloud! Remember to set up your variable with iotkit-agent on the edison as well as your cloud analytics service as in STEP 3!

sendObservation("temp", temp, new Date().getTime());

Microphone Sampling

I struggled to write my own, reliable code for microphone sampling. Node.js doesn't lend itself to accurate timing like C does. In the end I 'borrowed' the code below from the intel IoT developer zone.

function getReading() {    var buffer = new upmMicrophone.uint16Array(128); //create buffer to store data
    var len = myMic.getSampledWindow(2, 128, buffer);  //fill buffer with sample data
    if (len)
    {
        var thresh = myMic.findThreshold(threshContext, 30, buffer, len); 
        if (thresh)
            reading = thresh;
        //myMic.printGraph(threshContext); - Although very pleasing, suppressed bar graph representation of sound level.
    }
}

Code Resources

The intel IoT developer zone is a fantastic resource, it contains example code for every imaginable sensor in C/C++, Node.js and Python! Whether your using grove seeed sensors or another brand be sure to check the example code there. I can't stress how useful it is - bookmark it now!

https://software.intel.com/en-us/iot/hardware/sens...

Credits

Finally, this would not have been possible without the really enthusiastic, knowledgeable and patient team at Intel's IoT Ignition Lab in Swindon. I arrived intending to write some simple code for the Intel Edison using the Arduino IDE, with some superb support and guidance I learnt to write code in Node.js and even made a start of rewriting the project in C!

<p>Can I do this with Intel Galileo Gen 2 ?</p>
<p>Good Project! It help me a lot!</p>
<p>nice</p>
<p>Cool edison project.</p>

About This Instructable

3,398views

44favorites

License:

More by chrisgreen39:Intel Edison Noise Alarm (Intel IoT) 
Add instructable to: