JavaScript: Arduino Slide Controlling a Servo Tutorial

Welcome to the second tutorial in our series geared towards Arduino programming on Node.js, using the Johnny-Five framework. Get caught up here.

Johnny-Five is a Firmata based Arduino programming framework. See: JavaScript: Arduino Programming on Node.js.


In the previous tutorial, you created a program that gave you a simple REPL control interface to a servo motor. In this tutorial, you’ll add a slider to control the servo:

New Parts list:

Tutorial Requirements:

First, set up the hardware using this schematic as your guide:

Connect the following…

  1. Servo: Black > GND
  2. Servo: Red > 5v
  3. Servo: Signal > Digital PWM Pin 9
  4. Slider: Black > GND
  5. Slider: Red > 5v
  6. Slider: Signal > Analog 0
  7. Microcontroller > USB
  8. 9V Power

Assuming you’re using the actual repo, open up eg/slider-servo-control.js, or follow along here…

And that’s it!

Run node eg/slider-servo-control.js1 and try moving the slider up and down — the servo should rotate back and forth between 0-180 degrees (or whatever scalingRange was provided).

Remember to watch this space for more tutorials!


Note: There is a known issue in where the Firmata protocol layer has issues freeing itself on the serial line which results in the program hanging in the ready state. For now, ^C to kill the hanging program and simply run it again.

This entry was posted by Rick Waldron (@rwaldron) on May 24, 2012 in JavaScript, Node.js, Arduino, Johnny-Five and NodeBot.

Comments

Author

This entry was posted by Rick Waldron (@rwaldron) on May 24, 2012 in JavaScript, Node.js, Arduino, Johnny-Five and NodeBot.

Recent posts from this author

Related on the Bocoup Blog

Advertisement

Twitter

Google+