Hello,
I am testing the four wheel drive for a robot I am building so I made a simple code that turns the motors forwards and backwards just to test that they are connected and working. Unfortunately....the motors only go forward as if they get to the part of the code they go forward and decide to not reverse direction. This only happens however, when I disconnect the arduino mega from my computer. If I run the code with it plugged into my laptop, the motors actually change directions, bet the second I unplug it from USB it only goes forwards. I have both motors i'm using connected to a variable bench power supply. My code is as follows:
#define RM_FWD 2
#define RM_BWD 3
#define RM_ENA 9
void setup() {
// put your setup code here, to run once:
pinMode(solenoid, OUTPUT);
pinMode(RM_FWD, OUTPUT);
pinMode(RM_BWD, OUTPUT);
pinMode(RM_ENA, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(RM_ENA, 500);
digitalWrite(RM_FWD, HIGH);
digitalWrite(RM_BWD, LOW);
delay(5000);
digitalWrite(RM_FWD, LOW);
digitalWrite(RM_BWD, HIGH);
delay(5000);
}
Any help would be appreciated as I have no clue what could be causing it to behave differently when connected through USB......