How to use the Motoruino

POWER LAYOUT
POWER SELECTOR
PWM POWER SELECTOR
MOTOR POWER SELECTOR
MOTOR DRIVER – L293D
PWM
ENABLE Pin
SERVO MOTORS


POWER LAYOUT

Each of the Motoruino pins (digital and analog) has a GND and a POWER pin assigned.

The power pins of PWM pins have the possibity to be changed between the regulated 5v and Vin (Voltage in that comes directly from an external power source), this is useful if you have servos or other devices that need more than 5V, check the PWM POWER SELECTOR.

As for the Analog inputs, having this rows of GND and V+ pins is usefull because sensors can be easily plugged.


POWER SELECTOR

Jumper Description
OFF: Without the jumper your Motoruino will be completly off.
EXT: With this setting, the Motoruino will be powered from an external source. Use any voltage between 6V and 12V.
USB: Use the jumper on the USB side, and the Motoruino will be powered from the 5V supplied by the computer.

“… The Arduino Diecimila can be powered via the USB connection or with an external power supply. The power source is selected by the PWR_SEL jumper: to power the board from the USB connection, place it on the two pins closest to the USB connector, for an external power supply, the two pins closest to the external power jack.

External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board’s power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector. A low dropout regulator provides improved energy efficiency.

The board can operate on an external supply of 6 to 12 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts …”\

(http://arduino.cc/en/Main/ArduinoBoardDiecimila)


PWM POWER SELECTOR

Board Jumper Description
+5V: This setting connects the PWM supplier pin to the regulated 5volts. It is the best option for most of the regular servos.
Vin (Voltage in): With this setting, the supplier pins of the PWM pins are directly connected to the external source. Use this option if you have lots of servo motors on your aplication, or ir your servos require more than 5v. Always check the datasheet of your servo motors.
Off: Remove the jumper if you don’t want to use the supply pin for the PWM pins. You might want to turn the servos off if you are debugging code, or testing other components on your project.

MOTOR POWER SELECTOR

Board Jumper Description
+5V: This setting connects the motor power to the regulated 5 volts.
Vin (Voltage in): With this setting, the motors are directly powered from the external power source. Use this option if your motors require more than 5 volts. Always check the datasheet of your motors.
Off: Remove the jumper to turn off the motors. You might want to turn the motors off if you are debugging code, or testing other components on your project.

MOTOR DRIVER – L293D:

Inputs and Outputs:

The L293D can control up to two DC motors. For this it has two inputs and two outputs, each one assigned to one motor.

Notice that the input side has three pins, but for now we will focus on just the two that are closer to each other. This two pins will recieve information from the microcontroller and route that information to the motors.

That information is actually voltage, you always need two assign 2 digital pins from the microcontroller to one motor. If one pin is set to HIGH and the other to LOW, your motor will spin in one direction at full speed, if you want to invert direction you set the first pin to LOW and the other pin to HIGH. If you need to change speed you will need to use PWM pins. We will go deeper into this later.

As for the outputs, we decided that could be usefull to have optional ways to connect motors, so it is up to you to decide if you will use the screw terminal, or the 2.54mm spacing pins, or the 2mm spacing pins.


Digital control:

Now that you know how to supply your motors, it is time to show you how 3 different ways to use the L293D (a.k.a.) H-Bridge.

With the L293D you can work with 2 motors rated to work between 3V and 12V, with a consumption of 0.6 Amp per motor.

To work with one motor we need to connect 2 digital outputs of the microcontroller to the inputs of the L293D.

Within this example you can use any of the Motoruino’s digital pins, with the exception of the pins 0 and 1, you can use them of course, but it is good to know that they are directly connected to the Serial port.

The image shows the ouput pins 3 and 4 which are connected to one side of the H-Bridge and will control Motor B, and outputs 8 and 9 which are connected to the other side of the H-Bridge and will control Motor A. When one pin is active and the other is inactive the motor will spin in one way. If we need to invert the rotation, we have to invert the pins activation.

// this example focus only on pins 3 and 4

int motorB1 = 3;
int motorB2 = 4;

void setup() {
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
}

void loop() {

// make the motor spin one way
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);

delay(1000);

//make the motor spin the other way
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, HIGH);

delay(1000);

}

This way the motor will spin on its fastest rotation and there is no way to control the speed.


PWM – Pulse Width Modulation

Analog Control:

If we need to control speed, we need to use PWM output pins.
First we must verify that we are using PWM capable output pins (3, 5, 6, 9, 10, 11).

In this example we are going to use pins 5 and 6 connected to one side of the H-Bridge (Motor B).

// in this example we are only using the pins 5 and 6 

int motorB1 = 5;
int motorB2 = 6;

void setup() {
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
}

void loop() {

// motor spins one way, and the speed can go from 0 to 255
analogWrite(motorB1, 127);
digitalWrite(motorB2, LOW);

delay(1000);

// motor spins the other way, and the speed can go from 0 to 255
digitalWrite(motorB1, LOW);
analogWrite(motorB2, 127);
delay(1000);

}

Notice that when we need to use PWM, the command is analogWrite() instead of digitalWrite().

You can know more about PWM on Arduino’s website.


ENABLE Pin:

Another way to control speed is connecting the ENABLE pin on the H-Bridge, to a PWM pin on the microcontroller, and the input pins on the H-Bridge to the output pins on the microcontroller, for this two pins doesn’t matter if they are PWM or not because we will use them in digital output mode.

Pins 2 and 3 are connected to the H-Bridge inputs on the Motor B side. The activation and desactivation of this two pins will define the motor direction (it doesn’t matter if they are PWM pins or not).

The pin 5 (PWM) is connected to the ENABLE pin on the H-Bridge. This PWM pin will set the speed, we have 255 degrees of speed, although most motors will start spinning with a minimum value of 50.

int motorB1 = 2;
int motorB2 = 3;

int enableB = 5; 

void setup() {
  pinMode(motorB1, OUTPUT);
  pinMode(motorB2, OUTPUT); 

  pinMode(enableB, OUTPUT);
}

void loop() {

  // set speed - 0 to 255
  analogWrite(enableB, 0);

  // set direction
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);

  delay(250);

  // set speed - 0 to 255
  analogWrite(enableB, 127);

  // set direction
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);

  delay(250);

  // set speed - 0 to 255
  analogWrite(enableB, 255);

  // set direction
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);

  delay(250);

}

In this picture you can see that the Motor A is connected too.


SERVO MOTORS:

Servo motors are fun and easy to use, they spin in a range of 180ยบ.

Just plug the servo to the desired digital pin, knowing that the Servo’s GND (black) and V+ (red) must be on the same line as the GND and V+ on the Motoruino. The signal cable (white, yellow or brown) must be close to the desired digital pin.

This is a basic example that comes with the Arduino software, and it makes a Servo sweep its range:

#include "" 

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

One Response to How to use the Motoruino

  1. Pingback: RooboLink | How to use the Motoruino

Comments are closed.