Example Code for Arduino-Motor Control (Sabertooth)
Last revision 2025/12/31
Use this code to control the HCR move with Sabertooth motor control.
Code on Arduino Nano control the motor: If use the Sabertooth motor control, the motor can be control by serve.h perfect.
Hardware Preparation
- Main controller: Arduino Mega ADK/2560
- Motor controller: Arduino Nano
- Motor driver: Sabertooth dual 12A motor driver
- Two DC motors with 51:1 Gearbox 8000 rpm
- Two encoders with 13 PPR
- 2 wheels (and one caster wheel)
- Three bumper sensors
- Five Sharp GP2D12 infrared sensors
- Six URM04 v2.0 Ultrasonic Sensors
- GMR board
- Switch system
Software Preparation
- Development tool: Arduino IDE 1.0.x or higher
- Library:
Servo.h(included in Arduino IDE)
Wiring Diagram


Other Preparation Work
-
Insert the Mega and Nano on the GMR board, and connect the output of the switch system to the power supply of the motor controller and the GMR board.

-
Turn off the switch.
-
Connect the circuits as the connection diagram, connect two motors, the motor controller we will test it first.
-
The codes of the motor control should be used in Nano and the codes of the bumpers and IR sensors should be used in Mega ADK. The communication between Nano and Mega ADK is I2C.
Sample Code
#include <Servo.h>
Servo Lmotor;
Servo Rmotor;
float Lspeed = 0; //from 0-180, 0 means max speed forwards, 180 means max speed backwards 90 means stop
float Rspeed = 0; //from 0-180,
void setup()
{
Lmotor.attach( 9, 1000, 2000);
Rmotor.attach( 10, 1000, 2000);
}
void loop()
{
Lmotor.write(Lspeed);
Rmotor.write(Rspeed);
delay(500);
} // use this code to control the HCR move
Result
Test the speed and the direction of the motor. Make sure the motor will run suit your need.
Was this article helpful?
