Arduino Uno- help with coding two DC motors, one after the other

Hi, everyone. I am in the process of building a "fire extinguishing robot" which basically should drive straight forward for ten feet, stop, and then flip on a fan motor to extinguish a candle mounted at 1 foot off the ground.

I have constructed the robot, however am having difficulty with the code. ( I know it should be simple, however I am new to the robotics as well as the code behind the robot.) The code I have right now is as follows, it will run two DC motors that i have wired into one set of +/- wires to fit into port A on the Arduino Uno. After it runs these motors for a certain amount of time, it will stop them, and then loop again.

My goal however, is to get port A to run the wheel motors, stop them, and then directly after they have been stopped, to start the port B fan motor which will hopefully run for about 10 seconds and then turn off.

I am worried that if I input Port B code directly after I have put a delay on Port A for x amount of time, the robot will wait x amount of time and then begin to run the tire motors again.

You can probably tell I am very confused, and any help would be greatly appreciated! Thanks :wink:

My current code...

void setup() {
// put your setup code here, to run once:
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
pinMode(8, OUTPUT); // hopefully initiates channel b motor pin
pinMode(13, OUTPUT); //hopefully initiates channel b brake pin

}

void loop() {
// put your main code here, to run repeatedly:
//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed

delay(45000); //milliseconds

digitalWrite(9, HIGH); //Engage the Brake for Channel A

delay(10000000);

// worried fan won't start until 10,000 seconds after motor stops, but we want the motor
//to stop then immediately turn the fan on and then stop the fan about 10-15 seconds later, and NOT LOOP THE PROGRAM
}

It you want the program to run once, code it in setup(), not loop ().

If you want it to run repeatedly, but wait for a particular condition before
restarting, you'll have to code for that condition, otherwise loop() will just loop().

Long values should be notated as long - on the Uno integers default to 16 bit, so large
values ought to be written as explicitly long:

  delay(45000L); //milliseconds
 
  digitalWrite(9, HIGH); //Engage the Brake for Channel A

  delay(10000000L);

You can also stop the program progressing further by infinite loop:

  while (true) {}

Hi,
What arduino controller are you using?
What are you using to control the motors?
How are the arduino and motors powered?

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom..... :slight_smile: