IoT Cookbook > Arduino Yun > Lights

Yun Lights component

The Arduino Yun Lights component allows the remote controls of up to 6 Tinkerkit LED modules via WAMP.

Note: This can be used without changes for any other modules which get addressed via digital write, e.g. the Tinkerkit relay module.

Arduino Yun Lights component hardware

Trying it out

The code for this can be found in the crossbarexamples GitHub repository under iotcookbook. You need to clone this (or download it as a ZIP file).

Open a shell for the component directory and start up Crossbar.io:

crossbar start

This also serves a frontend where you can trigger the lights at http://localhost:8080.

In lights_yun.js, add the URL of the machine on which Crossbar.io runs:

var connection = new autobahn.Connection({
    // replace with the url of your crossbar instance
    url: "ws://<URL OF YOUR CROSSBAR INSTANCE>/ws",
    realm: "iot_cookbook"
});

You need to set up the Yun for using AutobahnJS, including setting up Firmata on the MCU part of the Yun.

Transfer lights_yun.js onto the Yun, e.g. by doing

scp lights_yun.js root@<IP of your Yun>:~/

Then run lights_yun.js

node lights_yun.js

This should log

Arduino Yun Lights starting ...
Arduino connected (over /dev/ttyATH0, board version 2.3)
Connecting to router ...
Router connected. Session ID: 717010044
procedure 'io.crossbar.examples.yun.lights.set_light_state' registered
...

Once this is running, open the browser console for the frontend page and trigger the lights via the buttons.

Use the disco mode to get all of them blinking at once!

The API

The lights component exposes a procedure for toggling the lights under io.crossbar.examples.yun.lights.set_light_state.

This takes the Tinkerkit shield output label as its value, i.e. "O0" - "O5". (See for the code how this corresponds to the actual GPIO pins on the Yun.)

Using it

In your own project: