Project tutorial
Home-made Nest Protect with Linino

Home-made Nest Protect with Linino

Prevent fires with a connected smoke alarm

  • 1,161 views
  • 0 comments
  • 3 respects

Components and supplies

Ard yun
Arduino Yun
×1
Smoke sensor
×1
Light sensor
×1
Stepper motor
×1
Relay (generic)
×1
Hydraulic pump or hydraulic electrovalve
×1

About this project

Collect all materials used in the last projects, put them together in a pot and make a super mega project of home automation, which will be based on the detection of the smoke sensor.

Before starting, get some hints from our last project:
Irrigated according to Functional weather conditionsProtect House as Kevin McCallister in “Home Alone”

The project has been designed to interact with all others sensors. Starting from the smoke detector, we set out the sequence of events.
If there is smoke, there will be two steps that the program will run.

  • If the value is between 500 and 800, we will be enabled:
  1. A stepper motor that will move a hand (or any other object you lmay prefer) as a visual signal.
  2. A LED will start flashing, but only if the brightness of the room is low.
  • If the value is greater than 800 we will be enabled:
  1. A stepper motor that will move a hand (or any other objetct you may prefer) as a visual signal.
  2. A LED will begin to flash, but only if the brightness of the room is low.
  3. An hydraulic electrovalve to shut off any fire.

NB. Made sure that the LED works only with low-light conditions, however, by changing the code, you can always enable it, in the presence of smoke. The LED can be replaced with a light bulb, just control a relay with pin D13.

Everything we need:

Warning: embedding parts within the project story has been deprecated. To edit, remove or add more parts, go to the "Hardware" tab. To remove this list from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Hardware" tab).
Ard yun
Arduino Yun
Smoke sensor
Light sensor
Stepper motor
Relay (generic)
Hydraulic pump or hydraulic electrovalve

Now think of the code and then we’ll see how to assemble the whole thing.
As usual, we create a new project with Ideino Workspace. We call it “SmokeSensor.”

In package.json file, the only dependency is related to the module node-static, which we use to send our data detected by the sensor of smoke, to a web page.

The javascript code:

Code

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

var linino = require('ideino-linino-lib'),
    board = new linino.Board(),
    html = new linino.Htmlboard();
var static = require('node-static');
var file = new static.Server('./');
 
var myVar,
    myVar2,
    ctrl = true,
    ctrl2 = true;
 
function servoMove() {
    return setInterval(function() {
        if (ctrl) {
            board.servoWrite('S9', 50);
            ctrl = false;
        } else {
            board.servoWrite('S9', 180);
            ctrl = true;
        }
    }, 1000);
}
 
function ledblink() {
    return setInterval(function() {
        if (ctrl2) {
            board.digitalWrite('D13', board.HIGH);
            ctrl2 = false;
        } else {
            board.digitalWrite('D13', board.LOW);
            ctrl2 = true;
        }
    }, 1000);
}
 
function sensorlight() {
    var data = board.analogRead('A0');
    if (data < 200) {
        if (typeof(myVar2) == 'undefined')
            myVar2 = ledblink();
    } else {
        board.digitalWrite('D13', board.LOW);
        clearInterval(myVar2);
        myVar2 = undefined;
    }
}
 
board.connect(function() {
 
    require('http').createServer(function(request, response) {
        request.addListener('end', function() {
 
            file.serve(request, response);
        }).resume();
    }).listen(1337);
 
    board.pinMode('D11', board.MODES.OUTPUT);
    board.pinMode('D12', board.MODES.OUTPUT);
    board.pinMode('D13', board.MODES.OUTPUT);
    board.pinMode('S9', board.MODES.SERVO);
 
    board.analogRead('A1', function(data) { //get data from SmokeSensor
        console.log('Smoke: ' + data);
        html.write('prog', 'value', data);
        html.write('num', 'value', data);
 
        if (data > 500 && data <= 800) { //enable LEDblink and ServoMove
            sensorlight();
            if (typeof(myVar) == 'undefined')
                myVar = servoMove();
        } else if (data > 800) { //enable LEDblink, ServoMove and fire hydrant
            sensorlight();
            if (typeof(myVar) == 'undefined')
                myVar = servoMove();
            board.digitalWrite('D11', board.HIGH);
            board.digitalWrite('D12', board.HIGH);
        } else {
            board.digitalWrite('D11', board.LOW);
            board.digitalWrite('D12', board.LOW);
            board.digitalWrite('D13', board.LOW);
            clearInterval(myVar2);
            myVar2 = undefined;
            clearInterval(myVar);
            myVar = undefined;
        }
    });
 
});

As described in the code comments, you can change the values ​​of the smoke detector.

The html page:

Code

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 
    <head>
        <meta http-equiv="content-type" content="text/html; charset=windows-1250">
        <script src="http://linino.local:2424/js/linino/socket.io.js"></script>
        <script src="http://linino.local:2424/js/linino/ideino-linino-lib-client.js"></script>
 
        <style>...</style>
    </head>
 
    <body>
        <script>
            window.onload = connect('linino.local');
        </script>
        <p align="center">
            <input type="label" id="num" class="label2" value="">
            <progress id="prog" class="label" value="" max="1000"></progress>
        </p>
 
    </body>
 
</html>

The Web page will look more or less like this:

The sketch made ​​with Fritzing, for the connection of the various components:

Ready! Start the project and hope you should NEVER need it !


Code

code.txtJavaScript
var linino = require('ideino-linino-lib'),
    board = new linino.Board(),
    html = new linino.Htmlboard();
var static = require('node-static');
var file = new static.Server('./');

var myVar,
    myVar2,
    ctrl = true,
    ctrl2 = true;

function servoMove() {
    return setInterval(function() {
        if (ctrl) {
            board.servoWrite('S9', 50);
            ctrl = false;
        } else {
            board.servoWrite('S9', 180);
            ctrl = true;
        }
    }, 1000);
}

function ledblink() {
    return setInterval(function() {
        if (ctrl2) {
            board.digitalWrite('D13', board.HIGH);
            ctrl2 = false;
        } else {
            board.digitalWrite('D13', board.LOW);
            ctrl2 = true;
        }
    }, 1000);
}

function sensorlight() {
    var data = board.analogRead('A0');
    if (data &lt; 200) {
        if (typeof(myVar2) == 'undefined')
            myVar2 = ledblink();
    } else {
        board.digitalWrite('D13', board.LOW);
        clearInterval(myVar2);
        myVar2 = undefined;
    }
}

board.connect(function() {

    require('http').createServer(function(request, response) {
        request.addListener('end', function() {

            file.serve(request, response);
        }).resume();
    }).listen(1337);

    board.pinMode('D11', board.MODES.OUTPUT);
    board.pinMode('D12', board.MODES.OUTPUT);
    board.pinMode('D13', board.MODES.OUTPUT);
    board.pinMode('S9', board.MODES.SERVO);

    board.analogRead('A1', function(data) { //get data from SmokeSensor
        console.log('Smoke: ' + data);
        html.write('prog', 'value', data);
        html.write('num', 'value', data);

        if (data &gt; 500 &amp;&amp; data &lt;= 800) { //enable LEDblink and ServoMove
            sensorlight();
            if (typeof(myVar) == 'undefined')
                myVar = servoMove();
        } else if (data &gt; 800) { //enable LEDblink, ServoMove and fire hydrant
            sensorlight();
            if (typeof(myVar) == 'undefined')
                myVar = servoMove();
            board.digitalWrite('D11', board.HIGH);
            board.digitalWrite('D12', board.HIGH);
        } else {
            board.digitalWrite('D11', board.LOW);
            board.digitalWrite('D12', board.LOW);
            board.digitalWrite('D13', board.LOW);
            clearInterval(myVar2);
            myVar2 = undefined;
            clearInterval(myVar);
            myVar = undefined;
        }
    });

});
code.txtHTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

    <head>
        <meta http-equiv="content-type" content="text/html; charset=windows-1250">
        <script src="http://linino.local:2424/js/linino/socket.io.js"></script>
        <script src="http://linino.local:2424/js/linino/ideino-linino-lib-client.js"></script>

        <style>...</style>
    </head>

    <body>
        <script>
            window.onload = connect('linino.local');
        </script>
        <p align="center">
            <input type="label" id="num" class="label2" value="">
            <progress id="prog" class="label" value="" max="1000"></progress>
        </p>

    </body>

</html>

Comments

Similar projects you might like

Control a Parrot AR Drone with Linino

Project tutorial by Giando

  • 4,808 views
  • 2 comments
  • 16 respects

Linino Christmas with Lifx

Project tutorial by Giando

  • 1,147 views
  • 0 comments
  • 1 respect

Ask Wolfram and Linino Answers!

Project tutorial by Giando

  • 649 views
  • 1 comment
  • 1 respect

3D Controller Bot

Project tutorial by 4 developers

  • 11,832 views
  • 1 comment
  • 42 respects

Protect Your Room with Fingerprints for Under $20

Project tutorial by Srivishnu Piratla

  • 6,502 views
  • 2 comments
  • 22 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 297,273 views
  • 98 comments
  • 706 respects
Add projectSign up / Login