reverse polarity/ spin a motor two directions, timing/ newbie

this is day two for me with arduino; I feel a sense of being lost, I have a personal science project/invention I am creating, long story short I need to spin an electric motor at about 300 rpm for about 4 seconds, than stop pause for about a second or two, than spin in the opposite direction for about 4 seconds, at the same speed; about 300 rpm. I bought a low speed electronic brushed-motor(AM55 540 Axial 55T) from my local hobby shop, I also bought an AE-5 waterproof forward/reverse ESC w/drag brake, a 7.2 volt 5000mAh battery, and an arduino uno starter kit. If you could point me in a direction to start out, maybe you already know ahead of time what particular problems I will be facing with this project, just some general advice, maybe some good tutorial videos that pertain to what I am doing, it would be a great help to me and greatly appreciated, thank you

Start with a few of the simple examples that come with the Arduino IDE, like Blink Without Delay, and make sure you understand everything in the example before beginning a motor control project.

Of course, you will also need to have a reasonable understanding of the C programming language, (better, C++).

An H-bridge motor driver can be used to drive the motor in either direction.

You can use PWM to control the speed (just like dimming an LED).

You'll need some sort of speed sensor (with feedback to your software) if you need to maintain the 300RPM speed with any accuracy. (BTW - That's slow for a non-loaded, non-geared down, DC motor.)

Hello,

I agree with the H-bridge suggestion. I tried the h-bridge on this post:

http://forum.arduino.cc/index.php?topic=198918.0

and it worked well. It is pretty easy to breadboard, or even free-form solder together from the schematics.

I used this bridge to drive a linear actuator designed to push a button and hold it for 15 seconds then release the button, in order to activate a water valve. Here is the code I used (which uses the same idea as "blink-without-delay"):

const int pushPin = 9;
const int pullPin = 10;

int pushState = LOW;
int pullState = LOW;

unsigned long pushTime = 0;
unsigned long pullTime = 0;
const int onTime = 5000;
unsigned long holdTime = 0;
const int flowTime = 15000;


void pushOn()
{
  digitalWrite(pushPin, HIGH);
}
void pushOff()
{
  digitalWrite(pushPin, LOW);
}
void pullOn()
{
  digitalWrite(pullPin, HIGH);
}
void pullOff()
{
  digitalWrite(pullPin, LOW);
}

void hold()
{
  digitalWrite(pushPin, LOW);
  digitalWrite(pullPin, LOW);
}

void setup()
{
  pinMode(pushPin, OUTPUT);
  pinMode(pullPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Begin Test");
  Serial.println();
}

////////////////////////////////////////////////////////////////

void loop()
{
  pushTime = millis();
  Serial.println("Push On");
  
  while((millis() - pushTime) <= onTime)
  {
    pushOn();
  }
  
  if((millis() - pushTime) > onTime)
  {
    pushOff();
    Serial.println("Push Off");
    
    Serial.print("Push Time = ");
    Serial.println(millis() - pushTime);
  }
  
  holdTime = millis();
  Serial.println("Flow On");
  
  while((millis() - holdTime) <= flowTime)
  {
    hold();
  }
  
  if ((millis() - holdTime) > flowTime)
  {
    Serial.print("Flow Time = ");
    Serial.println(millis() - holdTime);
    
    pullTime = millis();
    Serial.println("Pull On");
    
    while((millis() - pullTime) <= onTime)
    {
      pullOn();
    }
    
    if ((millis() - pullTime) > onTime)
    {
      pullOff();
      Serial.println("Pull Off");
      
      Serial.print("Pull Time = ");
      Serial.println(millis() - pullTime);
      Serial.println();
    }
  } 
  delay(5000);
}

The "flowTime" is the wait-time before reversing direction.

I haven't tried using PWM for anything yet, but it sounds like that could work for the speed/RPM control.

Good luck!

The OP has an ESC (electronic speed control), so another H-bridge is neither needed nor useful.

A cheap H-bridge won't work with that high current motor anyway.

is the H bridge drive in the same ball park as the ESC that I currently have in my possession?

Most aren't, and won't be useful.

Use your ESC and program the Arduino as if it were a servo.

anthonyporco:
... if anyone has any clue on where the knowledge I need is located,

It's located in the Learning pages of this site. Up there^^^.

Google "arduino esc motor control" for examples.

I also bought an AE-5 waterproof forward/reverse ESC w/drag brake,

ESCs are controlled just as if they are RC servos. ESCs usually have to be "armed" for safety reasons before they will accept commands. Search for ESC using the forum search box in the upper right of this page. Below is some simple servo control test code that might be of use for testing your ESC. Attacched is a of basic external power supply.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  } 
}

servo-wire.jpg

so I copied and pasted a code and got my motor spinning at different directions, and at different speeds depending on the number that I applied, but that's barely a dent in my final project. My task at hand is to spin this motor at a desired speed of my choice in one direction for 4 seconds----than pause for one second----than spin in the opposite direction for 4 seconds at the same speed (in both forward and reverse; same speed)--- I am basically making a blender but more scientific---I want to repeat this process for about 45 minutes---how do I go about that---Once I choose a desired speed through this code I copied, how do I go about using/programing those desired speeds into arduino to operate in the timing that I would like. How do I alternate between these two desired speeds/ how do I program the Arduino to do that? For example Lets say I like the speed I got when I entered "70" in the serial monitor (found under tools), and I liked the speed I got in the other direction when I entered "110", how do I get "70" to spin for 4 seconds----than stop for a second----than switch to speed "110" for 4 seconds----than stop for one second---than switch back to speed "70" for 4 seconds---than stop for 1 second----than switch back to speed "110" for about 4 seconds--- I need to keep this alternating speeds going for about 45 minutes