I'm an arduino noob and I'm trying to interface some javascript with arduino. For now all I'm trying to do is move a servomotor in a direction if a js variable is under a certain value and moving it the other way if it's above that value. I don't have a clue about how i should tackle this, so I'd appreciate any help. I do have the servomotor moving part and the javascript part, I just don't know how to put them together.
Asked
Active
Viewed 178 times
-3
-
Your question casts a doubt about the research effort you have put so far. In addition to asking SO, you must have tried google, and probably you found (as I just did by googling "arduino javascript") Breakout, Johnny-five, node-ardx.org, and some other projects and blogs... or maybe not. – PA. Oct 19 '14 at 07:11
-
Yes, I was just looking on johnny-five and node-ardx, but honestly I'm not very good with node (I only did client-side js) and I'm not sure if I'm really gonna try and pick up two things at the same time – Mihai Bujanca Oct 19 '14 at 07:18
1 Answers
1
For now all I'm trying to do is move a servomotor in a direction if a js variable is under a certain value and moving it the other way if it's above that value.
Here's how you can accomplish this with Johnny-Five:
- Make sure you have node and npm installed
- With the Arduino IDE, upload StandardFirmata (File -> Examples -> Firmata -> StandardFirmata) to the Arduino, close the IDE
npm install johnny-five
- create a new JS file, save the following in it:
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var servo = new five.Servo(11);
this.repl.inject({
move: function(value) {
var angle = 0;
if (value > 0) {
angle = 180;
}
servo.to(angle);
}
});
});
- With the USB cable plugged in to the board and computer, run the above program in your terminal. Once it's running, call
move(n)
wheren
is any number. Numbers greater than 0 will move the servo to 180°; numbers less than or equal to 0 will move the servo to 0°.

Rick
- 1,391
- 8
- 11