SunFounder GalaxyRVR Kit for Arduino, Release 1.0
speed will make the rover turn towards the left.
• The second way is by making both left and right motors rotate in the same direction (clockwise in this case),
which will make the rover spin to the left on its axis.
Let’s see how we can implement both ways in code:
Method 1: Different speeds on each side
#include <SoftPWM.h>
// Define the pins of motors
const int in1 = 2;
const int in2 = 3;
const int in3 = 4;
const int in4 = 5;
void setup() {
// Initialize SoftPWM
SoftPWMBegin();
}
void loop() {
// Set the left motors rotate counterclockwise in low speed
SoftPWMSet(in1, 40);
SoftPWMSet(in2, 0);
// Set the right motors rotate clockwise in higher speed
SoftPWMSet(in3, 0);
SoftPWMSet(in4, 200);
delay(2000); // Last for 2 seconds
}
In this code, we have decreased the speed of the left motors while keeping the right motors at a higher speed. This will
make the rover turn towards the left.
Method 2: Rotating all motors in the same direction
#include <SoftPWM.h>
// Define the motor pins
const int in1 = 2;
const int in2 = 3;
const int in3 = 4;
const int in4 = 5;
void setup() {
// Initialize SoftPWM
SoftPWMBegin();
}
void loop() {
// Set all motors to rotate clockwise
SoftPWMSet(in1, 0);
SoftPWMSet(in2, 255);
(continues on next page)
3.5. Lesson 5: Unleashing Mars Rover Mobility 49