I ran into a problem this morning. I built a simple light-tracking robot, entered and uploaded the code. Everything went just fine. Wires and jumper wires were all in place, motor function went fine as intended, batteries were supplying power, I mean everything was perfect. This is an Arduino Uno.
It was not until this morning when I realized my L LED light is not blinking. So, I double checked by code, and uploaded it to the Arduino once again. (Nothing is wrong with the code). I found out the LED was only flashing when connected to the editor on my computer. Once detached, the light faded away. Even though the ON LED is green supported by the battery. Thus, my two motors were put in a halt.
1ST CODE:
// declare variables for motor control pins
int Motor1Speed = 10;
int Motor1Control1 = 9;
int Motor1Control2 = 8;
int Motor2Speed = 11;
int Motor2Control1 = 13;
int Motor2Control2 = 12;
// declare variable for motor speed (0-255)
int speed = 255;
// declare variable for delay time in milliseconds
int delayTime = 1000;
void setup() {
// setup code that only runs once
// set motor control pins as outputs
pinMode(Motor1Speed, OUTPUT);
pinMode(Motor1Control1, OUTPUT);
pinMode(Motor1Control2, OUTPUT);
pinMode(Motor2Speed, OUTPUT);
pinMode(Motor2Control1, OUTPUT);
pinMode(Motor2Control2, OUTPUT);
// set speed for both motors
analogWrite(Motor1Speed, speed);
analogWrite(Motor2Speed, speed);
}
void loop() {
// code that loops forever
// set both wheels to spin forward for delayTime milliseconds
digitalWrite(Motor1Control1, HIGH);
digitalWrite(Motor1Control2, LOW);
digitalWrite(Motor2Control1, HIGH);
digitalWrite(Motor2Control2, LOW);
delay(delayTime);
// stop for delayTime milliseconds
digitalWrite(Motor1Control1, LOW);
digitalWrite(Motor1Control2, LOW);
digitalWrite(Motor2Control1, LOW);
digitalWrite(Motor2Control2, LOW);
delay(delayTime);
}
2ND CODE:
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
Any ideas on why this is happening?