Example Code for Arduino-Simple Test

Use Arduino IDE to upload the following sketch to the microcontroller via the USB port. After uploading, the Cherokey should go backwards, forwards, turn 90 degrees to the left and turn 90 degrees to the right.

Software Preparation

Use Arduino IDE to upload the sketch. In Arduino IDE's board settings, use "Arduino UNO". Under COM settings, select the microcontroller's COM port (the COM port will vary on your computer).

Other Preparation Work

  • Make sure your COM port is correctly assigned to your microcontroller in the IDE or the program will not upload!
  • After code has been uploaded to the microcontroller, unplug the USB cable from the board.
  • Place the Cherokey on a flat surface and at ground level for safety.
  • Turn the Cherokey on using the switch at the rear.

Sample Code

int speedPin_M1 = 5;     //M1 Speed Control
int speedPin_M2 = 6;     //M2 Speed Control
int directionPin_M1 = 4;     //M1 Direction Control
int directionPin_M2 = 7;     //M1 Direction Control

void setup(){
}

void loop(){
    carAdvance(100,100);
    delay(1000);
    carBack(100,100);
    delay(1000);
    carTurnLeft(250,250);
    delay(1000);
    carTurnRight(250,250);
    delay(1000);
}

void carStop(){                 //  Motor Stop
  digitalWrite(speedPin_M2,0);
  digitalWrite(directionPin_M1,LOW);
  digitalWrite(speedPin_M1,0);
  digitalWrite(directionPin_M2,LOW);
}

void carBack(int leftSpeed,int rightSpeed){         //Move backward
  analogWrite (speedPin_M2,leftSpeed);              //PWM Speed Control
  digitalWrite(directionPin_M1,HIGH);
  analogWrite (speedPin_M1,rightSpeed);
  digitalWrite(directionPin_M2,HIGH);
}

void carAdvance(int leftSpeed,int rightSpeed){       //Move forward
  analogWrite (speedPin_M2,leftSpeed);
  digitalWrite(directionPin_M1,LOW);
  analogWrite (speedPin_M1,rightSpeed);
  digitalWrite(directionPin_M2,LOW);
}

void carTurnLeft(int leftSpeed,int rightSpeed){      //Turn Left
  analogWrite (speedPin_M2,leftSpeed);
  digitalWrite(directionPin_M1,LOW);
  analogWrite (speedPin_M1,rightSpeed);
  digitalWrite(directionPin_M2,HIGH);
}
void carTurnRight(int leftSpeed,int rightSpeed){      //Turn Right
  analogWrite (speedPin_M2,leftSpeed);
  digitalWrite(directionPin_M1,HIGH);
  analogWrite (speedPin_M1,rightSpeed);
  digitalWrite(directionPin_M2,LOW);
}

Result

The Cherokey should go backwards, forwards, turn 90 degrees to the left and turn 90 degrees to the right.

Additional Information

TROUBLESHOOTING TIPS:
Batteries must be connected to make the motors move! If the Cherokey is only plugged in with USB power through the microcontroller, the motors will be under powered and will not work!
If batteries are installed but the motors are not moving, make sure the switch at the rear of the Cherokey PCB is turned on
The Cherokey's direction may vary depending on the wiring of the motors. If you think the directions are wrong, try switching the positive and negative wires
If a problem persists, try editing the code to change the motor direction - covered in the Changing the Motor Direction in Code section below

Was this article helpful?

TOP