Hello,
I've built a machine that runs a DC 6 - 15 volt motor http://uk.rs-online.com/web/p/dc-geared-motors/0420596/ forward for roughly 45 seconds then in reverse for the same period. I've also added in a stop between each transition.
I'm using a L293D H bridge to facilitate the forward and reverse. I've attached a diagram of wiring. The code I'm using is
int enablePin = 11;
int input1pin = 10;
int input2pin = 9;
int potPin = 0;
boolean polarity = true;
void setup() {
// put your setup code here, to run once:
pinMode(enablePin, OUTPUT);
pinMode(input1pin, OUTPUT);
pinMode(input2pin, OUTPUT);
}
void loop() {
int speed = analogRead(potPin) / 4;
polarity = true;
setMotor(speed, polarity);
delay(46000); //43 seconds
analogWrite(11, LOW);
delay(1000);
analogWrite(11, HIGH);
polarity = false;
setMotor(speed, polarity);
delay(43000); //43 seconds
analogWrite(11, LOW);
delay(1000);
analogWrite(11, HIGH);
}
/*
- Sets motor to a speed and a polarity
*/
void setMotor(int speed, boolean polarity) {
analogWrite(enablePin, speed);
digitalWrite(input1pin, polarity);
digitalWrite(input2pin, ! polarity);
}
Initially it ran well but has since stopped running consistently. It will now run for two periods of 45 seconds then slow significantly, then stop. I've tried a new motor but this does the same thing. The small motor 6/9v that came with the starter kit runs fine but has insufficient torque for the machine I have constructed. I'm wondering if there is insufficient current going to the motor? I wondered if maybe I need to power the motor separately from the Arduino board? If so is there a simple way of doing this?
I should mention that initially I had the motor running forward and then into reverse without stopping. I thought this had damaged the motor, but since trying a new motor found this not to be the case. Could I have damaged the board instead?
I'm relatively new to electronics and this is my first project using an Arduino board. I apologise for not using all the terminology.
I'd really appreciate any help given, the machine is a piece of Artwork I intend to exhibit at the end of the week!!!
Sarah