Skip to content

Latest commit

 

History

History
76 lines (46 loc) · 1.94 KB

instructions.md

File metadata and controls

76 lines (46 loc) · 1.94 KB

Move

Move a DC motor

Bits you'll need

image image image

The code in this project will also work with other output bits that move including the fan and vibration-motor

Assembling the circuit

Connect power bit to d0 on Arduino bit, d5 on Arduino bit to dc-motor bit. Flick the switch next to d5 to pwm.

image

You might also like to use a wire between d5 and the dc-motor to give you more flexibility to position the motor, or a motor-mate to attach some paper to the motor so you can see it moving more easily.

Code

var five = require("johnny-five"), 
  board, motor;

board = new five.Board();

board.on("ready", function() {

  motor = new five.Motor(5);

  motor.start();
  
  board.wait(5000, function() {
      motor.stop();
  });

  this.repl.inject({
    motor: motor
  });
});

You can find a copy of this code in move/move.js

Run the code from the terminal e.g.

node move/move.js

What you'll see

The motor will spin for 5 seconds and then stop.

The board object's wait method can be used to shedule something to happen. The first parameter is the delay in milliseconds, and the second is a function specifying what to do after waiting for the specified time.

What to try

Flicking the switch on the dc-motor module will switch the direction the motor is spinning.

Use the REPL to start or stop the motor:

motor.start() 
motor.stop()  
motor.isOn    // property indicates whether it is moving

You can also control the motor speed:

motor.speed(50)  // slow
motor.speed(120) // mid-speed
motor.speed(255) // full speed