DC Motor Troubles

Hi all,
I was just messing around the other day and ran into something that I couldn't seem to figure out. I am trying to run a 3V DC motor with amp rating of 27mA. Here is the code:

int analogIn = 0;
int analogOut = 9;

void setup()
{
}

void loop()
{
int readVal = analogRead(analogIn);
int scaledVal = constrain(readVal,570,860);
scaledVal = map(scaledVal,570,860,0,255);

analogWrite(analogOut,scaledVal);
}

I have a photo resistor setup on pin A0 (connected with a voltage divider), and I am running my motor off of pin 9. When I put an LED in place of the motor, I get a full 5V. However, when I try to hook the motor up I go not get any voltage across the motor at all. I know the motor is good, I have tested it. Do you have any explanation.

P.S. I intentionally avoided a transistor setup.

Thanks for the help,
John

Do you have the motor connected between Pin 9 and Ground?

A 27 mA 3V motor will draw more current at 5V. Unfortunately it will go to 45 mA which is higher than the Arduino can stand.

27mA @ 3V. Are you sure? Not to sound too incredulous, but I think a bee puts out more power than that. I personally do not know of a 27mA 3V motor. Do you have a spec sheet for it or a link to some documentation?

Okay, let's say your right, that the motor's running current is 27mA, then johnwasser is right, it will overload the AVR at 5V. Plus, the start current for the motor would usually be 4-6 times the running current. IT quite likely is effectively shorting the output of the AVR.

BTW, how did you test the motor? Did you use a DMM to measure the current draw at 5V?

Here is something to try, If you feed the motor 5V through a 160 Ohm resistor, does it run?

johnnybgood:
P.S. I intentionally avoided a transistor setup.

WHY? I mean, seriously, WHY?

Obviously you did a bit of research; surely you saw the numerous postings all over this forum and the internet about why it is a bad thing to run virtually anything directly off the pins of any microcontroller? I mean, these postings are everywhere! They are like a daily (at minimum - weekly) question or comment!

Yet - you decided to ignore all of these warnings? What made you think that was a good idea?

Unfortunately, you have likely damaged your Arduino in some fashion; even if it appears to work on those pin(s) you hooked up to, it is likely that those pins are either outputting less than perfectly - if they are working at all - and will likely fail sooner than they should.

Now, granted, you haven't lost much - a $5.00 chip. But I tend to wonder if you gained anything out of doing this?

Do you at least understand why this is bad? Do you understand that with electronics (especially those that deal with larger loads) that there are rarely these kinds of shortcuts? Do you understand that in most cases, you have to put more than just a modicum of effort and understanding into your projects?

I'm not asking for you to understand and solve a large set of Kirchoff's equations - but you would do well to at least have some understanding of the math behind electronics. Heck, Ohm's Law and a multimeter will take you quite far, actually...

/if I shake my head any more, it'll probably break off like an overly bent piece of steel...

As harsh as it sounds, crOsh's response is right. I mean, what does a 2N7000 MOSFET cost these days? 20 cents? For turning on and off a small motor, you would not even need any other components, just the 2N7000. 0r a 6 cent 2N3904 and a base resistor. Invest a few pennies in some cheap transistors so that you have them. It's not like they are new, or fangled in any way these days. Buy 'em, use 'em, they are cheap, effective 'n easy.

Just out of curriosity, why does the 5V pin allow for a greater amperage to be pulled than the other digital or analog pins? Essentially, why would the motor work off of the 5V pin and not any of the others.

The other pins are logic pins, driven from the microcontroller.
The 5V pin comes straight off the regulator.

You know that tiny motor in your mobile phone that makes it vibrate?
It probably draws in excess of 70mA at a comparable voltage.