Two weeks ago I received in my post box the Sabertooth 2 X 25A motor driver. I bought it because I have big plans for it in short and long terms. From the beginning, I’ll use it to drive indoor autonomous robots; then I will move on to build a high powered robot for all-terrain activities. I read about its performances, and I saw a lot of short YouTube movies with the motor driver used to control DC motors for high-powered robots such as RC lawn mowers, electric powered wheelchairs, electric vehicles, scooters, etc.. It can be used in almost any large robot under 130Kg (300lbs). So, I think it is perfect for my future projects.
With a lot of ideas in mind, I have some reasons to study the Sabertooth motor driver in details and see pretty much what it can offer at that price. Since I brought up the topic of price, the motor driver is priced at $124.99 on Amazon. Compared with other motor drivers that offer the same range of specifications, the 2 X 25A motor driver by Sabertooth is the best on the market for that price.
Anyway, in this post I’ve decided to show you how to set up the motor driver and control four DC motors with Arduino UNO. Many solutions found on the Internet were good for RC vehicles, but unacceptable for an autonomous robot. During this first phase I had some limitations in mind:
- the Arduino sketch should contain functions for moving forward, backward, turning left, right and stop;
- the Arduino sketch would be useful in future projects for autonomous robots. I don’t want a remote controlled robot;
- the Arduino UNO board should be powered by the motor driver;
None of the tutorial/project found around meet these conditions, so I started a brand new tutorial.
Let’s start
A summary of hardware components I’ve used in this tutorial:
- 1 X Arduino UNO ($21.91 on Amazon)
- 1 X Sabertooth 2 x 25A motor driver ($124.99 on Amazon)
- 4 X 6V DC motors attached to a mobile robot chassis (mobile robot kits between $42 and $138 on Amazon)
- 1 X 7.4V Li-poly Battery (price between $27 and $89 on Amazon)
The Sabertooth’s motor driver is designed for large robots, and it cannot be better than that. First, I started to dig deep into the datasheet, specifications, schematics, and how to control it via my Arduino UNO.
The second step was to set the operating mode with the onboard DIP switches. The easier way to control the DC motors was to use the ‘Simplified Serial Mode’ mode (DIP switches 1, 3, 5 and 6 set to ON, the remainder set to OFF).
Here is how it should look like the Sabertooth’s DIP switches:
The third step was to build the control system by connecting the motor driver with the DC motors, Arduino UNO, and the power supply.
- Sabertooth 0V to Arduino GND
- Sabertooth 5V to Arduino Vin
- Sabertooth S1 to Arduino TX pin
- 2 X DC Motors to M1A and M1B
- 2 X DC motors to M2A and M2B
- the battery to B+ and B-
The fourth step was to write the Arduino sketch.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/**
* @file        Sabertooth 2 X 25A Motor Driver.ino
* @author      IntoRobotics.com
* @version      V1.0
* @date        2016/06/03
* @description  this file is sample code for the Sabertooth 2 X 25A Motor Driver and Arduino UNO
*/
/*Sending a character between 1 and 127 will control motor 1.
1 is full reverse, 64 is stop and 127 is full forward.
Sending a character between 128 and 255 will control motor 2.
128 is full reverse, 192 is stop and 255 is full forward.
Character 0 (hex 0x00) is a special case. Sending this character will shut down both motors.
Source:http://www.robotmarketplace.com/products/images/Sabertooth2x25.pdf
*/
//simplifierd serial limits for each motor
#define SBT_MOTOR1_FULL_FORWARD 127
#define SBT_MOTOR1_FULL_REVERSE 1
#define SBT_MOTOR2_FULL_FORWARD 255
#define SBT_MOTOR2_FULL_REVERSE 128
//shut down both motors
#define SBT_ALL_STOPÂ Â 0
void setup() {
  Serial.begin(9600);
  killMotors();
}
void loop() {
  fastForward();//move fast forward for 3 seconds
  delay(3000);
  killMotors();
  fastReverse(); //move fast reverse for 3 seconds
  delay(3000);
  killMotors();
  turnLeft(); //turn left for one second
  delay(1000);
  turnRight(); //turn right for one second
  delay(1000);
  killMotors();
}
void fastForward(){Â Â //motors fast forward
    Serial.write(SBT_MOTOR1_FULL_FORWARD); Â
    Serial.write(SBT_MOTOR2_FULL_FORWARD);
    Serial.println(“motors fast forward”);
  }
void fastReverse(){Â Â //motors fast reverse
    Serial.write(SBT_MOTOR1_FULL_REVERSE); Â
    Serial.write(SBT_MOTOR2_FULL_REVERSE);
    Serial.println(“motors fast reverse”);
  }
  void turnLeft(){  //motor 1 full reverse and motor 2 full forward to turn left
    Serial.write(SBT_MOTOR1_FULL_REVERSE); Â
    Serial.write(SBT_MOTOR2_FULL_FORWARD);
    Serial.println(“motor 1 full reverse and motor 2 full forward to turn left”);
  } Â
  void turnRight(){  //motor 1 full forward and motor 2 full reverse to turn right
    Serial.write(SBT_MOTOR1_FULL_FORWARD); Â
    Serial.write(SBT_MOTOR2_FULL_REVERSE);
    Serial.println(“motor 1 full forward and motor 2 full reverse to turn right”);
  }
  void killMotors(){
    Serial.write(SBT_ALL_STOP);  //kill motors for 0.5 second
    Serial.println(“kill motors for half a second”);
    delay(500); Â
    }
|