This small IoT project (Internet Of Things) shows how to switch on/off a LED by evaluating the signal of a slider used as a commander.
You need:
- Arduino Uno R3;
- LED on the pins
GND
and13
; - slider on the pins
A0
(the signal) and the couple5V
andGND
for the power supply.
The slider I've been using is a Bourns Inc. PTA6043-2015DPB103 POTENTIOMETER, SLIDE, 10K, 20%, 0.25W
. From the datasheet you could find out:
- Pin 2: the slide gang;
- Pin 1, 3: GND and 5V.
You can find the PDF datasheet here at the Bourns website.
The source code is written in javascript for the Node.js platform. The main library is Johnny-Five.
To get started you need:
- The Arduino IDE running the Firmata package (File -> Example -> Firmata -> StandardFirmata);
- Check that the Arduino board is properly connected via USB to your computer (under linux run
lsusb | grep Arduino
on the command line to check the board is connected and running); - Select the Arduino UNO board from the IDE (Tools -> Board -> Arduino UNO);
- Select the COM port from the IDE (Tools -> Serial Port -> /dev/ttyACM0);
- Upload the Firmata source code to the board via the Arduino IDE clicking on the Upload button.
At this point the Node.js code running on your laptop (basically the Johnny-Five npm module) will use the Firmata code running on the board as an API.
From the command line you should be able to run the source code using the node
command:
$ node slider-with-led.js
1435411275762 Device(s) /dev/ttyACM0
1435411275780 Connected /dev/ttyACM0
1435411279120 Repl Initialized
>> off: 0.39100684261974583
on: 0.5865102639296188
on: 0.6842619745845552
on: 0.5865102639296188
on: 0.6842619745845552
on: 0.8797653958944281
on: 0.6842619745845552
on: 0.6842619745845552
off: 0.2932551319648094
(^C again to quit)
>>
1435411290860 Board Closing.
$
The schematic and the breadboard schema have been generated using Fritzing (you can load the .fzz
file from the doc
folder).
A big thank you to the guys of the NodeBots of London meetup for organising the hacklab I've been to in June 2015.