IoT Cookbook > Arduino Yun > Potentiometer Component

Yun Potentiometer component

The Arduino Yun Potentiometer component publishes events when the state of a Tinkerit potentiometer changes.

Arduino Yun Potentiometer 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).

You need to have at least one Tinkerkit potentiomete, which as a default should be connected to 'I0' on the Tinkerkit shield (pin 0).

Open a shell for the component directory and start up

crossbar start

This also serves a frontend where you can view the potentiometer data logged at http://localhost:8080.

In potentiometer_yun.js, add the URL of the machine on which 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 potentiometer_yun.js on the Yun, e.g. by doing

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

Then run potentiometer_yun.js using Node.js

node potentiometer_yun.js

This should log something like

Arduino Yun Potentiometer starting ...
Arduino connected (over /dev/ttyATH0, board version 2.3)
Connecting to router ...
Router connected. Session ID: 1431639925 registered

Once this is running, open the browser console for the frontend page and reload the page. You shoud see something like

potentiometer value currently is: 0 20

and when you turn the potentiometer something like

potentiometer value change: [0, 24]
potentiometer value change: [0, 26]
potentiometer value change: [0, 28]
potentiometer value change: [0, 31]
potentiometer value change: [0, 33]


The component provides one procedure which takes the pin the potentiometer is connected to as an argument and returns the current potentiometer value (0 - 100), and publishes to one topic which provides the pin of the potentiometer where the value change occured adn the current potentiometer value (0 - 100).

Using it

Adjust the pin and topics as needed, add potentiometers.