User Tools

Site Tools


Launch of


Controlling a Force Sensor with Linino

In this example, we are going to make a force sensor producing an output voltage value directly proportional to the pression which is applied to the sensor itself.

To design our circuit schematic, we need the following electronic components :

  • two 10KΩ resistor
  • one 1KΩ resistor
  • force sensor

Alternatively, we can use just one 22KΩ resistor.

The Force 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 serial connection of two 10 KΩ resistor and a 1 KΩ one) and to an analogic input of the Linino ONE board (yellow wire) as well.

The Node Application

So, to create an application allowing us to control the force sensor leveraging Linino OS, you need to install the Node.Js platform and the Ideino IDE which makes available a set of embedded libraries allowing us to control the Linino ONE board pins by means of Node.Js itself. Please refer to this guide to perform a hassle-free installation of Node.Js and Ideino :

The code script we are going to write will be able to read the input analog voltage values we feed to the A0 pin of the Linino ONE and, according to certaing thresholds, to modify the image embedded in the linked web page.

In this particular example, the web page is made of four layers lighting up according to the strength intensity applied to the sensor.

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 pin0  = { pin: , value : 0 },
    html_img_id = 'force',
    force0 = '"/html/img/force0.jpg"',
    force1 = '"/html/img/force1.jpg"',
    force2 = '"/html/img/force2.jpg"',
    force3 = '"/html/img/force3.jpg"',
    force4 = '"/html/img/force4.jpg"';

pin0 represents the board analog pin A0 through which we usually read the voltage values fed by the force sensor to the board.

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

force<X> contains the remote path to the image we are going to embed in our web page.

Creating a web server

This code describes the creation of a http server listening on the port number 1337.

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

Please take care to insert the correct path of 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 A0 pin voltage values we have to invoke the analogRead function in which we have set five different thresholds according to which the path of the image file embedded in the web page is switched.

    board.analogRead(, function( data ) {    
        if(data < 200)
        if(data > 200 && data < 400 )
        if(data > 400 && data < 600 )
        if(data > 600 && data < 800 )
        if(data > 800)

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 force.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 work properly.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <meta http-equiv="content-type" content="text/html; charset=windows-1250">
    <script src=""></script>
    <script src=""></script>
    <script type="text/javascript">
      window.onload = connect('');
    <img id="force" src="/html/img/force0.jpg">    

/var/www/ · Last modified: 2014/11/17 06:32 by andrea

2014 © dog hunter llc and the Linino Community. is a dog hunter sponsored community project. Credits