Skip to content

Small Motor Controllers for the Mini ROV

hydrogen602 edited this page Feb 9, 2019 · 3 revisions

Intro

Each segment of the motor controllers can control two DC motors, and is completely separate from other segments. Each segment requires a positive and ground power connector for 5V, and features two inputs and outputs per motor. They can only take a max current of 1A (uncertain, please verify).

Connections

The power connectors are marked + and - and are found in the corner of a segment. These connect to 5V.

The data input lines are marked IN1 and IN2, and two pairs are found in each segment. These connect to an Arduino or Raspberry Pi, and can take 3V or 5V. IN2 has to be attached to a PWN-enabled pin, while IN1 does not.

On the opposite of IN1 and IN2 are the two output connectors. Again there are two pairs of them, and these correspond to the pair of IN1/IN2 connectors directly opposite to them. The connectors attach to the DC motors, and which wire attaches to which connectors only influences the direction the motors spin, so if opposite rotation is desired, flip them.

Arduino Code Example

int IN1 = 9; // <- labeled on the controller
int IN2 = 10; // <- labeled on the controller

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  digitalWrite(IN1, HIGH); // <- controls the direction of rotation
}

void loop() {
  analogWrite(IN2, 205);
  /* 
   * 2nd argument should be between 0-255
   * It controls speed
   * If IN1 is HIGH, then 255 is stop and 0 is max speed
   * If IN1 is LOW, then 0 is stop and 255 is max speed
   * 
   */
}

Python Code Example

import RPi.GPIO as GPIO
from time import sleep

IN1 = 21 # GPIO pin number to IN1
IN2 = 20 # GPIO pin number to IN2

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(IN1,GPIO.OUT)
GPIO.setup(IN2,GPIO.OUT)

GPIO.output(IN1, GPIO.LOW) # <- controls the direction of rotation
p = GPIO.PWM(IN2, 50)
p.start(50) # <- controls speed. The value should be between 0 and 100

# when IN1 is set to LOW, 0 is stop and 100 is max speed
# when IN1 is set to HIGH, 100 is stop speed and 0 is max speed

sleep(120) # run for two minutes
p.stop()
GPIO.cleanup()

Clone this wiki locally