Go Down

Topic: ks0159 motor problem (Read 166 times) previous topic - next topic


Hi, I have a smartcar ks0159 and when i try to run it one of the weel is moving the opposite way, i just copy the program is coming at the manual and everything will have to be correct. The car is going foward and the top left weel is moving backward and when is moving backward the well is moving forward.


#define IRSensorLeft    8   // left sensor input pin
#define IRSensorMiddle  9  // middle sensor input pin
#define IRSensorRight  10  // right sensor input pin
unsigned char IRSL;        // left sensor status
unsigned char IRSM;        // middle sensor status
unsigned char IRSR;        // right sensor status
#define E1  3   
#define E2  11   
#define M1  12           
#define M2  13       
void Sensor_IO_Config()
void Sensor_Scan(void)
  IRSL = digitalRead(IRSensorLeft);
  IRSM = digitalRead(IRSensorMiddle);
  IRSR = digitalRead(IRSensorRight);
void M_Control_IO_config(void)// initialization function of motor driver shield IO

void advance(void)     // move forward
    digitalWrite(M1,LOW);    // right wheel moves forward
    digitalWrite(M2, LOW);  // left wheel moves forward
    analogWrite(E2, 150);
void turnR(void)        // turn right
   digitalWrite(M1,LOW);  // left wheel moves forward
   digitalWrite(M2,HIGH); // right wheel moves backward
void turnL(void)        // turn left
   digitalWrite(M1,HIGH);   // left wheel moves backwards
   digitalWrite(M2, LOW);   // right wheel moves forward
void stopp(void)              // stop
    digitalWrite(M2, LOW);
    analogWrite(E1, 0);   
    analogWrite(E2, 0);  // both left and right wheels stop
void back(void)            // move backward
   digitalWrite(M1,HIGH);   // both left and right wheels move forward

void setup()
   M_Control_IO_config();        // initialization of motor driver shield IO
unsigned char old_IRSL,old_IRSM,old_IRSR;
void loop()
if(IRSL==0&&IRSM==0&&IRSR==0)advance(); if((IRSL==0&&IRSM==0&&IRSR==1)||(IRSL==0&&IRSM==1&&IRSR==1))turnL();


Then swap the wires to the top left wheel motor.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


I have tried to swap the wires, and modify High and Low but is still doing the same. I can´t write to Keyestudio because the website is not working and reading the manual of the car doesn´t says anything of the position of the motors or the wires.
moving forward-top left weel is moving backward.
moving backward-top left weel is moving forward.
moving right-back weel and top right weel are moving backward.
moving left-top right weel is moving backward


Don't change lots of things at once. Go back to the original code you posted and change nothing except for swapping over the positive and negative wires to the one motor that is turning the wrong way.

It will now turn the correct way. If it doesn't then you have not changed the right wires.


Go Up