Go Down

Topic: Basic Motor help (With motor shield) (Read 1 time) previous topic - next topic

zhongyan

I'm very new with all this so bear with me. I've got an freetronics board (Arduino Uno clone) and basically want to hook up a basic DC motor to the motor shield. However right now after looking through all the tutorials it doesn't appear to run. I've done a bit of basic programming in C and maybe I'm missing something.

Code: [Select]
const int pwm_cha = 3;
const int dir_cha = 12;
const int brake_cha = 9;
const byte motor_speed = 255;

void setup()
{
    pinMode(pwm_cha, OUTPUT);
    pinMode(brake_cha, OUTPUT);
    digitalWrite(pwm_cha, HIGH);
    digitalWrite(brake_cha, LOW);
    pinMode(dir_cha, OUTPUT);
    digitalWrite(dir_cha, LOW);
}

void loop()
{
  analogWrite(pwm_cha, motor_speed);
  delay(2000);
  analogWrite(pwm_cha, 0);
  delay(2000);
}

This is what I've tried uploading to the board but when I connect my battery (9V) it doesn't do anything whilst connected via USB and if it isn't the motor jitters a bit and stops straight after. I'm more than likely missing something very basic but having no past experience I don't have much of an idea. Here's a picture of my setup -> http://imgur.com/3ppbHBL. Essentially what I want is a basic template that lets me know the motor is under my control, like "run motor for x seconds". Thanks in advance.

MarkT

You neglect to reveal which motor shield...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

zhongyan

Sorry, it's a 2-Channel H-Bridge Motor Driver Shield by freetronics.

jack wp

Please provide a URL to your motor shield. I don't want to google and find the wrong one.

Basicly motor controls use 3 signals.
For motor A it would be ENA, IN1, IN2.
For the motor connected to the output for A to run, you need to have IN1 and IN2 different. To say not both HIGH, and not both LOW. Depending on which is HIGH and the other one of course being LOW, it determines the direction of the motor. Then making ENA high will run the motor. For speed control, you can use PWM on the ENA pin.

Do you see these three pins on the shield? What pins of the arduino are each connected to?

Cactusface

Hi  zhongyan,
                     What are you powering it with?  even small DC motors can require a few 100 ma of current, Tell me it's not that tiny 9v battery!!  you need 4 x AA cells at least. When the USB is connected the Uno runs from that, otherwise in uses power from the socket or vin, via an on-board 5V reg. THe driver on the shield is more then likely to be a L293/298 which uses transistors for the H bridge so you lose almost 1.5V across them too.

Hope this helps, give me a shout, done the odd buggy-bot or 2.

Regards

Mel.
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

johnft


Sorry, it's a 2-Channel H-Bridge Motor Driver Shield by freetronics.


Hi  zhongyan

You can't power the motor shield and board directly from USB.
If you're trying to run the whole lot from that 9V battery - check the voltage, as others have said the voltage drop through the IC won't help (and that battery won't last long either!)
For more see - http://www.freetronics.com/pages/hbridge-motor-driver-shield-quickstart-guide
http://www.freetronics.com

Go Up