User Tools

Site Tools


Launch of


Controlling a Tilt Sensor with Linino

In this example we are going to use a device called tilt sensor. Inside the sensor are present a couple of marbles acting as electrical contact when the sensor is set in vertical positioning (closed switch). By tilting the sensor itself, the marbles don’t establish a real electrical contact so the sensor can be thought as an open switch.

The tilt sensor is a two pin device. One of them is directly fed by the circuit power supply while the other one is connected to the system ground by a resistor (we have used in our experiment a 10 KΩ resistor) and to an digital input of the Linino ONE board (yellow wire) as well.

Components :

  • one 10 KΩ resistor
  • tilt sensor

The Node Application

To develop an application, with the aim of creating a dynamic web page that shows the orientation of the Linino ONE card using the values returned by the tilt sensor, is necessary install Node.js platform and Ideino IDE which provide a set of libraries that allow to controll Linino ONE Board pin by Node.Js itself. By following the wiki page: is possible install Node.js platform and Ideino IDE by a simple sh script. After installing everything normally at url http://linino.local:2424 will be the Ideino IDE:

After logging-in to Ideino IDE with your root password, create a new project by clicking on the Combo-Box button located in the top-right side of the screen :

Once the new project is opened, we have to create a new javascript file to write a web server listening on a given port. The following code describes all the necessary steps.

Create a board object and a html object with the ideino-linino-lib :

var board = require('ideino-linino-lib').Board,
       html = require('ideino-linino-lib').Htmlboard,
       fs = require('fs'),
       http = require('http'),
       url = require('url'),
       path = require('path');

Javascript variables definition :

var pin8  = { pin: , value : 0 },
      html_img_id = 'magnet',
      board_up = '"/html/img/board_up.jpg"',
      board_down = '"/html/img/board_down.jpg"';

pin8 represents the board digital pin D8 through which we usually read the digital values fed by the tilt sensor to the board.

html_img_id is the “tag img” of the html page we are going to interact with.

board_up/board_down contains the remote path to the image we are going to embed in our web page.

Creating a Web Server

This code describes the making of a http server listening on the localhost port number 1337 :

    var file, page;
    http.createServer(function(req, res) {
        if(req.url.indexOf(".jpg") != -1 ){
            page = path.join(__dirname,'html','img',path.basename(req.url));
            file = fs.readFileSync(page);
            res.writeHead(200, {'Content-Type': 'image/jpeg'});
            page = path.join(__dirname,'html','page-server-side-write-tilt.html');
            file = fs.readFileSync(page); 
            res.writeHead(200, {'Content-Type': 'text/HTML'});

Please take care to insert the correct path the html web page into the file object of the javascript code. This is a crucial point for the proper setup of your work environment.

To read the D8 pin digital values, we firstly have to invoke the pinMode function to set the input to a given pin and after that we set a conditional statement with the digitalRead function. According to the data collected by the pin of the board, the image embedded in the web page will be switched :

board.pinMode(, board.MODES.INPUT);   
board.digitalRead(, function( data ){
        if(data.value === 0)

The Html Page

Once you’re logged into ideino, open the examples project and then create a subfolder named “html”. The next step is to create a html file which in this case will be called as page-server-side-write-tilt.html. In addition, create another subfolder named “img” that will be containing our images to embed into the web page.

Please take care to insert the IP address of you board into the “src” field of the html page instead of the dynamic dns resolution of the boards itself, otherwise your project won’t properly work :

    <meta http-equiv="content-type" content="text/html; charset=windows-1250">
    <script src=""></script>
    <script src=""></script>
        body {
            background-color: rgb(230, 230, 230);
        div {
            text-align: center;
        img {
            position: absolute;
            width: 524px; /*the image width*/
            height: 164px; /*the image height*/
            top: 50%;
            left: 50%;
            margin-left: -262px;
            margin-top: -82px;
    <script type="text/javascript">
      window.onload = connect('');
        <img id="magnet" src="/html/img/board_up.jpg">

wiki/tiltsensor.txt · Last modified: 2019/05/28 11:22 (external edit)