Breadboard for "Motor - H-Bridge"


Fritzing diagram: motor-hbridge.fzz


Run this example from the command line with:

node eg/motor-hbridge.js
  IMPORTANT!!! This example is not intended for off the shelf
  H-Bridge based motor controllers. It is for home made H-Bridge
  controllers. Off the shelf controllers abstract away the need
  to invert the PWM (AKA Speed) value when the direction pin is set
  to high. This is for controllers that do not have that feature.

var five = require("johnny-five"),
  board = new five.Board();

board.on("ready", function() {
  var motor;
      Motor A
        pwm: 3
        dir: 12

  motor = new five.Motor({
    pins: {
      pwm: 3,
      dir: 12
    invertPWM: true

    motor: motor

  motor.on("start", function() {

  motor.on("stop", function() {
    console.log("automated stop on timer",;

  motor.on("forward", function() {

    // demonstrate switching to reverse after 5 seconds
    board.wait(5000, function() {

  motor.on("reverse", function() {

    // demonstrate stopping after 5 seconds
    board.wait(5000, function() {

  // set the motor going forward full speed


Component Classes in this example:

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub