Arduino Motor Controlling without a H-Bridge

Related Posts Plugin for WordPress, Blogger...CLICK TITLE FOR MORE INFORMATION





Yet, another project from me. This time, it's about controlling a DC motor, BUT withOUT a H-bridge. It'll use the keyboard to control the motor.

For your reference:
'a' - FORWARD
's' - REVERSE
'd' - BRAKE*
'f'  - FREE-RUN*

*The difference between Brake and Free-run is that the Brake function shorts the motor to Ground and finally you'll get to brake. The Free-run function just disconnects the motor terminals with the Arduino and you'll still get to stop but it takes longer as its inertia is still present.



I've used:
Arduino Uno

Breadboard

Jumper Wires

DC Motor

Here is the sketch for the project:



int ad=8;  //anode terminal of the motor
int cd=7;  //cathode terminal of the motor
int incom; //incoming bytes


void setup(){
  Serial.begin(9600); //baud rate - 9600
}


void loop(){
  if(Serial.available()){ //if there is incoming bytes
    incom=Serial.read();  //that equals to incom
  }
  switch(incom){
    case'a': //if 'a' is pressed
    pinMode(ad,OUTPUT);
    pinMode(cd,OUTPUT);
    digitalWrite(ad,HIGH);
    digitalWrite(cd,LOW);
    Serial.println("FORWARD"); //the motor goes forward
    break;
    case's': //if 's' is pressed
    pinMode(ad,OUTPUT);
    pinMode(cd,OUTPUT);
    digitalWrite(ad,LOW);
    digitalWrite(cd,HIGH);
    Serial.println("REVERSE"); //the motor goes backwards
    break;
    case'd': //if 'd' is pressed
    pinMode(ad,OUTPUT);
    pinMode(cd,OUTPUT);
    digitalWrite(ad,LOW);
    digitalWrite(cd,LOW);
    Serial.println("BRAKE"); //the motor brakes
    break;
    case'f': //if 'f' is pressed
    pinMode(ad,INPUT);
    pinMode(cd,INPUT);
    Serial.println("FREE-RUN"); //the motor goes to free-run mode
    break;
    default:
    Serial.println("Please key in command"); //writes this if no command is present
    delay(1000);
    break;
  }
}

Finally the video. Enjoy!



by Weng Fei


3 Responses so far.

  1. You must be careful with the output current. It is recommended that Arduino I/O pins should only drive up to 40mA per pin. More than that might damage the I/O pin. Most motors will need more than 40mA especially during start-up.

  2. Unknown says:

    get cheap arduino board in http://smartics.com.my

  3. Unknown says:

    hey, made an update for a better transition between forward and reverse. If you ground both pins before you switch you will reduce back emf etc.


    int ad=8; //anode terminal of the motor
    int cd=7; //cathode terminal of the motor
    int incom; //incoming bytes


    void setup(){
    Serial.begin(9600); //baud rate - 9600
    }


    void loop(){
    if(Serial.available()){ //if there is incoming bytes
    incom=Serial.read(); //that equals to incom
    }
    switch(incom){
    case'a': //if 'a' is pressed
    pinMode(ad,OUTPUT);
    pinMode(cd,OUTPUT);
    digitalWrite(ad,LOW);
    digitalWrite(cd,LOW);
    digitalWrite(ad,HIGH);
    Serial.println("FORWARD"); //the motor goes forward
    break;
    case's': //if 's' is pressed
    pinMode(ad,OUTPUT);
    pinMode(cd,OUTPUT);
    digitalWrite(ad,LOW);
    digitalWrite(cd,LOW);
    digitalWrite(cd,HIGH);
    Serial.println("REVERSE"); //the motor goes backwards
    break;
    case'd': //if 'd' is pressed
    pinMode(ad,OUTPUT);
    pinMode(cd,OUTPUT);
    digitalWrite(ad,LOW);
    digitalWrite(cd,LOW);
    Serial.println("BRAKE"); //the motor brakes
    break;
    case'f': //if 'f' is pressed
    pinMode(ad,INPUT);
    pinMode(cd,INPUT);
    Serial.println("FREE-RUN"); //the motor goes to free-run mode
    break;
    default:
    Serial.println("Please key in command"); //writes this if no command is present
    delay(1000);
    break;
    }
    }

Leave a Reply

Popular Posts