I have a motor that input voltage is 3-9 volts. As I understand when you do a analogWrite a PWM pin 0-255 is clamped from 0 to 5 volts. I tried doing a analogWrite(dcMotorPin, 255) to see if it would run at 5 volts. I have the red wire plugged into 5 volts, black wire plugged into ground, and white wire plugged into Pin 3, my dcMotorPin. On the other side of the pwm cable is a motor controller board I bought from a hobby shop that I would assume with this turns the PWM into a voltage to drive the motor. I have been able to drive the motor with PWM with a PIC using this motor board but not with the Arduino. This is my code btw.
int dcMotorLeftPin = 3; // Analoug pin for PWM DC Motor
void setup()
{
pinMode(dcMotorLeftPin, OUTPUT); // sets analog pin as output
}
I would be very surprised if you could get the motor to turn from a pic chip.
A 5 volt motor will take at least half an amp. The Arduino pins can supply at most 40mA. You need a driver circuit to provide this high current (and the drivers are controlled via PWM). Take a look at ladyada's motor shield or the freeduino motor shield.
Well I didn't control it from a PIC it was from a PWM out on an Innovation first board. That went from the innovation first board to the motor controller board to the motor. I have the same setup but Arduino board in place of the innovation first board. Here are the specs of the motor if this helps.
Voltage Operating Range: 3~9VDC
Nominal Voltage: 6V constant
No-Load Speed: 160 ± 16rpm
No-Load Current: Approx.140mA
Rated Speed: Approx.180rpm
Rated Current: Approx. 900mA
Rated Torque: Approx. 1.2kg-cm
Output Power: Approx. 2Watt
At Max. Effciency: Approx. 45% c
10.Stall Torque: Approx. 5.2kg-cm
Motor Speed: 5000 ± 50rpm
Gear Ratio: 31:1
Shaft Brush: Sintered oiled bronze
Gear Material: Steel/Bronz hobbing gears
Max. allowable moment Torque : 18 kg-cm
Temperature Range: -10C ~ 60C
Relative Humidity: 20% to 85%RH
Insulatiion Strength: 20M[ch937], 500VDC
Dielectric Strength: AC250V, 60Sec. Min.
Connector: JST PHR-2
The big metal thing is the frame that holds the dc motor, you can see the output shaft and hub of the motor. The green board on its side is the motor controller board and obviously there is the arduino. Is my setup wrong? The 3 alligator clips are as follow. (Black is in Ground, Red is in 5 volts, White is in Pin 3) they connect/correspond to the Brown Red and Yellow wires of the motor controller board. Then there is the black and red wires connecting to the dc motor.
AVR outputs are current limited to 20mA or so. your motor needs 140mA with no load.
You will need an L293D chip or mosfet or something.
The rated current is 900mA, so it's probably 2-3A in a stall. An L293D won't be able to cope with that, it might work if you run the outputs in parallel.
I just googled the motor controller. It was from sozbots.com that no longer exits. I bought the controller in 2004 heh, or at least it was manufactured then. Here is the info on it http://www.lynxmotion.com/Product.aspx?productID=90&CategoryID=10 and here is the datasheet on it. http://www.lynxmotion.com/images/data/hb-03.pdf Can't believe I bought it for 50 bucks back then. I am pretty confused on how to hook up a simple DC motor, I am sure I am doing something wrong thats probably simple. I appreciate everyones comments
I hooked up a 7.2 volt battery where it says + and - should go on the motor controller board. I am confused however. Right now my computer is powering my Aurino through the USB cable. But when I plug in the 7.2 bolt battery the arduino is powered on. I have a 5v Ground, and Single (pin 3) wire from the arduino going to the motor controller board. I tried this with just the single cable because I didn't want two power sources to "collide - epp sorry im not an EE". I know the motor controller board is functional because it blinks when I connect power from the 7.2 volt battery to it and then turns off (the leds) like it should. I think something is wrong with my PWM single or something or my connections/setup is wrong. I want to get these motors spinning soon
I just googled the motor controller. It was from sozbots.com that no longer exits. I bought the controller in 2004 heh, or at least it was manufactured then. Here is the info on it http://www.lynxmotion.com/Product.aspx?productID=90&CategoryID=10 and here is the datasheet on it. http://www.lynxmotion.com/images/data/hb-03.pdf Can't believe I bought it for 50 bucks back then. I am pretty confused on how to hook up a simple DC motor, I am sure I am doing something wrong thats probably simple. I appreciate everyones comments
That controller should do the job, but I'm not sure you can just use the analogwrite function with it.
From the page you linked,
To use the HB-03 motor controller, provide a repeating pulse with a 1.5mS on-time, and an
approximate 10 to 20mS off-time to the control input. At this time the motor will not be running.
Now when the pulse on-time is greater than 1.5mS the motor will rotate one direction, and when
the pulse is less than 1.5mS the motor will rotate the other direction. The farther you go from 1.5mS
the faster the motor will run. Keep the pulses from 1mS to 2mS in normal use.
So you probably have to do those timings manually in software.
I also can't tell from your picture if you've got the hardware set up right, but we can assume for now you do, since it's just a few wires.
I have this is my new code. I am manually doing the pulses by setting it to High for a millisecond and then low for 20 milliseconds. The thing doesn't turn...
int outPin = 12; // digital pin 12
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(outPin, HIGH); // sets the pin on
delay(2); // pauses for 2 milli
digitalWrite(outPin, LOW); // sets the pin off
delay(20); // pauses for 20 milli
}
To use the HB-03 motor controller, provide a repeating pulse with a 1.5mS on-time, and an
approximate 10 to 20mS off-time to the control input. At this time the motor will not be running.
Now when the pulse on-time is greater than 1.5mS the motor will rotate one direction, and when
the pulse is less than 1.5mS the motor will rotate the other direction. The farther you go from 1.5mS
the faster the motor will run. Keep the pulses from 1mS to 2mS in normal use.
That's a standard hobby servo signal. Ask google or whatever about servo libraries for the arduino.
I wouldn't start looking into libraries until you get that code working.
A library will hide a lot of what's going on and if that code doesn't work I don't see why a library should. At this point, how sure are you about the hardware setup? You have power going to the controller, pin 12 conected to the controller's input and the motor connected to the outputs, all properly?
I found the problem... I wasn't grounding the pwm single I guess to the motor control board. It doesn't neet the 5 volt single eaither I dont think this is my code...
int outPin = 12; // digital pin 12
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(outPin, HIGH); // sets the pin on
delay(2); // pauses for 2 milli
digitalWrite(outPin, LOW); // sets the pin off
delay(20); // pauses for 20 milli
}
When I do 1 millisecond it spins one way and 2 millisecond delay it spins the other because 1.5 is in the middle. I wish I can use the actual Analog Write on a PWM pin so I can control speed and direction that way. I am using these motors for an automated blinds project. I am going to have infrared limit sensors/switches to test the bounds if the blind is down or up. Thanks everyone who has helped, the motors are spinning!
I'm glad you got it going. That sounds like a nice project, it's something I've thought about doing but it would be far down on my list.
You can use analogwrite, just not with that motor controller board. Take a look at the Pololu one I linked. But at $40-50, you're probably stuck with with what you have.
Now might be time to look up that servo library that was suggested if you want to simplify your code.