using the Ardruino with DC motors

What stock board? You haven't told us any thing about it.

its just the board that came on the r/c car that I have to use. We had to use a car bought for $20 to make this thing.

nope you dont require four wires a h bridge is capable of acheiving it using two only but nothing is clear and how are you connecting the h- bridge ?

Does it have any markings on it? Any ICs you can identify? This a good picture of an H-bridge http://csel.cs.colorado.edu/~bauerk/legorobots/images/H-bridge4.gif To turn the motor one direction, transistors 1 & 3 turn on, so current flows from top left to bottom right. To turn the other direction, transistors 2 & 4 turn on. So your stock board might have 4 transistor drivers, with 1 control line to turn on 1 & 3, and a 2nd for 2 &4. Or it might have a H-bridge controller that drives, or even contains, the transistors.

So, what have you got?

I figured it out. I was only connecting to 1 and 3 on each Hbridge. Thanks for all the help! This robot is ready for the competition as soon as I get it programmed. Hopefully the 8AA batteries will last the full 3 minutes. Kinda doubt it though.

Glad to help out. Can you go with 8 C-Cells or D-Cells instead? I don't what overall size you are dealing with. Or maybe two of the squarish 6v lantern batteries connected in series? Those have 4 each F-cell size or something in them if one can believe the youtube videos.

Unfortunately no. The competition rules require everyone to use NiMH AA batteries. But it runs reasonably fast on those. The car can be no more than 1'x1'x1'.

I'm having some trouble again however. I have the ardruino wired to the batteries. The motors have a switch, but apparently the ardruino gets power all the time, so I'm not sure how to keep the program from running until I switch on the motors.

Are you using pins 2 or 3? Code them to have internal pullups turned on and use them as a wakeup interrupt. Press one (short to gnd) to have it go into powerdown sleep mode, the other to wake up & run. Or just read one every once in a while & go to sleep from there.

Be sure to include these
#include <avr/sleep.h> // powerdown library
#include <avr/interrupt.h> // interrupts library

This code goes before void setup() with the pin definitions stuff as needed

//***************************************************
// *  Name:        pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
  /* This brings us back from sleep. */
}

//***************************************************
// *  Name:        enterSleep
void enterSleep()
{
  /* Setup pin2 as an interrupt and attach handler. */
  attachInterrupt(0, pin2Interrupt, LOW);
  delay(50); // need this?
  /* the sleep modes
   SLEEP_MODE_IDLE - the least power savings
   SLEEP_MODE_ADC
   SLEEP_MODE_PWR_SAVE
   SLEEP_MODE_STANDBY
   SLEEP_MODE_PWR_DOWN - the most power savings
   */
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
  sleep_enable();                       // setting up for sleep ...
  sleep_mode();                         // now goes to Sleep and waits for the interrupt

  /* The program will continue from here after the interrupt. */
  detachInterrupt(0);                 //disable interrupts while we get ready to read the keypad 

  /* First thing to do is disable sleep. */
  sleep_disable(); 

  // then go to the void Loop()
}

this goes in void loop() after you’ve decided to sleep

enterSleep(); // call Sleep function to put us out

the code will continue running from this point on after waking up.

so I can input these sleep mode commands straight into my program? the motors are running off of pins 0 and 2 for forward motion and 4 and 5 for turning.

Yes - where else would they go? I would just make sure the motors are commanded off first; if active high, write the outputs low.

I like keeping pins 0 & 1 not used for application stuff so that any monitoring I do via the serial port is not competing with the application, and I can program without having to disconnect anything on the board. Doesn't always work out, but I try anyway.

2 & 3 are the hardware interrupt pins, so you have one of them free anyway.

I couldn't get that code figured out so I just went and bout a switch and hard wired it just before the DC connector. But I can't get the arduino to delay for any period of time before it starts spinning the motors... Heres my code, I can't seem to find anything wrong with it.

int fmotor = 0; int foffmotor= 2; void setup() { pinMode(fmotor, OUTPUT); pinMode(foffmotor, OUTPUT); Serial.begin(9600); } void loop() { delay (4000); digitalWrite(fmotor, HIGH); delay (4000); digitalWrite(foffmotor, HIGH);

}

use the # button for code

int fmotor = 0;
int foffmotor= 2;
void setup()
{
 pinMode(fmotor, OUTPUT);
 pinMode(foffmotor, OUTPUT);
 Serial.begin(9600);
}
void loop()
{
 delay (4000);
 digitalWrite(fmotor, HIGH);
 delay (4000);
 digitalWrite(foffmotor, HIGH);

}

well the code is not that clear what are you trying to do ? wellll if you set a delay before switching on a motor as it seems in the sketch it should work and remember the other pin should be set low

Try this

#include <avr/sleep.h>      // powerdown library
#include <avr/interrupt.h>  // interrupts library

int pin3 = 3; // our interrupt pin
int fmotor = 0;
int foffmotor= 2;

//***************************************************
// *  Name:        pin3Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin3Interrupt()
{
  /* This brings us back from sleep. */
}

//***************************************************
// *  Name:        enterSleep
void enterSleep()
{
  /* Setup pin3 as an interrupt and attach handler. */
  attachInterrupt(0, pin3Interrupt, LOW);
  delay(50); // need this?
  /* the sleep modes
   SLEEP_MODE_IDLE - the least power savings
   SLEEP_MODE_ADC
   SLEEP_MODE_PWR_SAVE
   SLEEP_MODE_STANDBY
   SLEEP_MODE_PWR_DOWN - the most power savings
   */
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
  sleep_enable();                       // setting up for sleep ...
  sleep_mode();           // now goes to Sleep and waits for the interrupt

  /* The program will continue from here after the interrupt. */
  detachInterrupt(0);                 //disable interrupts while we get ready to read the keypad

  /* First thing to do is disable sleep. */
  sleep_disable();

  // then go to the void Loop()
}

void setup()
{

   pinMode(pin3, INPUT);                 // our sleep interrupt pin
  digitalWrite(pin3, HIGH); // internal pullup enabled - pull this low to wake up

  pinMode(fmotor, OUTPUT);
 pinMode(foffmotor, OUTPUT);

 digitalWrite(fmotor, LOW); // add this, assuming LOW = motor off
 digitalWrite(fmotor, LOW); // add this, assuming LOW = motor off

 Serial.begin(9600);
}
void loop()
{
// wait 4 seconds, turn on motor 1 for 4 seconds
 delay (4000);
 digitalWrite(fmotor, HIGH);
 delay (4000);
 digitalWrite(fmotor, LOW);  // now stop it

// wait 4 seconds, turn on motor 2 for 4 seconds
 delay (4000);
 digitalWrite(foffmotor, HIGH);
 delay (4000);
 digitalWrite(foffmotor, LOW); // now stop it
 
// go to sleep

   enterSleep();                             // call Sleep function to put us out
// program resumes from here to go back to top of void loop()

}

I uploaded your exact code but it still ran. Infact it just ran without stopping.

I didn't wire correctly to the h-bridges so for them to stop I have the forward moving motor stop I have to have both pin 0 and 2 on. Otherwise It will move regardless of it being HIGH or LOW. its weird...

hmm this dosent look like a code problem i think you wired the h-bridge wrong show how did yyou connect them schematics or a pic of the actual setup ? or get your self a h bridge ic like the l293 or l298

I would go get an H-bridge but its due on Tuesday. So i'm just tryin to figure out how to delay the program from running till I can put the car down on the ground

I don't think we can do anymore without seeing your wiring. Can you send a close up, not blurry picture? Use macro mode and show the motor board in detail.

my dinky little digital camera isn’t good enough to take a picture of the board without it being fuzzy. :frowning:

So i'm just tryin to figure out how to delay the program from running till I can put the car down on the ground

there are many ways ! set a delay in the program at the beginning LIKE

void main()
{
dealy(10000)// thats a ten secon delay ( the arduino measures time in microseconds)
then do what ever .....}

or use a push button ? lIke

void main()
{
if( digitalRead(pushbotton)=1)
{
void drive();
}
}
//here specify the drive function.....
void drivve
{
digitalWrite (motor1pion1,HIGH);
blah blah....
return;
}

He's already got code to turn the motors off and a 4 second delay before they are commanded on, and they go anyway. Gotta be a wiring problem.

 digitalWrite(fmotor, LOW); // add this, assuming LOW = motor off
 digitalWrite(fmotor, LOW); // add this, assuming LOW = motor off

 Serial.begin(9600);
}
void loop()
{
// wait 4 seconds, turn on motor 1 for 4 seconds
 delay (4000);
 digitalWrite(fmotor, HIGH);