0
votes

I am making a hand gesture controlled tank.I made a code to test the dc motors on Arduino UNO, but the problem is that motors are just vibrating and not moving. The code is:

#include <AFMotor.h>

AF_DCMotor motor1(1, MOTOR12_1KHZ); 
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

void setup() {


motor1.setSpeed(255);  
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}

void loop() {

// Serial.print("tien");

motor1.run(FORWARD);     
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(10);

//Serial.print("lui");

motor1.run(RELEASE);      
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(10);


motor1.run(BACKWARD);     
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(10);

//Serial.print("tack");

motor1.run(RELEASE);      
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(10);
}

I don't know why it isn't moving. I checked it replacing the wires, but same is happening. I checked them individually connecting to the batteries and they are working pretty well. Please HELP!!

2
Are the motors under load? Have they stalled? - Attie

2 Answers

0
votes

If you set the delay to 10 ms, this is what happens: -motor moves clockwise for 10 ms -motor stops for 10 ms -motor moves counter clockwise for 10 ms -motor stops for 10 ms -loop

And since 10ms (milliseconds) is a very small amount of time it appears that the motor is vibrating.

To make it move, increase the delay to something like 1000 ms which is 1 second.

0
votes

It is supposed to work like that. Give it another shot. You can also try removing the MOTOR12_1KHZ. Also try removing the parts containing RELEASE and BACKWARD, this way it will be simplified and there can be less chances of error. If that works, then go for adding more parts slowly.