Step 1

Make a directory inside your "tessel-code" folder: enter mkdir ambient into your command line, then change directory into that folder: cd ambient

Step 2

Plug the ambient module into Tessel port A with the hexagon/icon side down and the electrical components on the top, then plug Tessel into your computer via USB.

Step 3

Install by typing npm install ambient-attx4 into the command line.

Step 4

Save this code in a text file called ambient.js:

// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

/*********************************************
This ambient module example console.logs
ambient light and sound levels and whenever a
specified light or sound level trigger is met.
*********************************************/

var tessel = require('tessel');
var ambientlib = require('ambient-attx4');

var ambient = ambientlib.use(tessel.port['A']);

ambient.on('ready', function () {
 // Get points of light and sound data.
  setInterval( function () {
    ambient.getLightLevel( function(err, lightdata) {
      if (err) throw err;
      ambient.getSoundLevel( function(err, sounddata) {
        if (err) throw err;
        console.log("Light level:", lightdata.toFixed(8), " ", "Sound Level:", sounddata.toFixed(8));
      });
    });
  }, 500); // The readings will happen every .5 seconds
});

ambient.on('error', function (err) {
  console.log(err);
});

Step 5

In your command line, tessel run ambient.js
Watch light and sound values appear in your terminal! Try clapping or shining a flashlight at it.

Bonus: Change the code so the sound trigger activates with just a whisper.

To see what else you can do with the ambient module, see the module docs here.

Step 6

What else can you do with a ambient module? Try a community-created project.


What are you making? Share your invention!

If you run into any issues you can check out the ambient forums.

Choose another module

Or if you're all set, move on to Wifi.

Fork on Github