running motor with no motor shield

Hi All,

I have regular toy motors that I want to use directly with the arduino pins. I was going to plug one end of the motor to pin 4 and the other to pin 5 then set one high and the other low to go forward, and do the reverse to go backward.. My question is what resistor should I use on these pins so that the load wouldn't cause the arduino to restart, or worse, get fried..

I understand that the arduino pins can handle up to 40 mA. My problem is that I don't know how to calculate which resistors to use.. =)

Thanks! :)

ps please explain how you got to the answer so I can do it myself in the future :)

To calculate the resistor use ohm's law. Resistance = voltage / current For 40mA and 5V this works out at about 100 ohms.

However there are two points, back voltage from the motor will damage the arduino if you don't fit diodes. You will find that 40mA is not enough to drive a motor.

You don't need a shield but you do need some driving circuit.

I see.. Thanks, looks like I'll just buy the shield then.

I understand that the arduino pins can handle up to 40 mA

NO ! Arduino team is wrong when they write 40mA !, they do not respect Atmell specifications. Atmell guaranteed only 20mA in continuous use Read the datasheet : 40mA are ABSOLUTE MAXIMUM RATING !

*NOTICE: Stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

You could also see important notice concerning source or sink mode :

3. Although each I/O port can sink more than the test conditions (20 mA at VCC = 5V, 10 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: ATmega48PA/88PA/168PA/328P: 1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100 mA. 2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100 mA. 3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100 mA. If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition. 4. Although each I/O port can source more than the test conditions (20 mA at VCC = 5V, 10 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed: ATmega48PA/88PA/168PA/328P: 1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150 mA. 2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150 mA. If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.

You cann't do what you explained - you WILL fry Arduino. If you want to drive motor both directions you need at least motor driver IC like L293 or better use shield, if you need only one direction you can use one MOSFET transistor.

If you want to drive motor both directions you need at least motor driver IC

No, you could do it with a DPDT relay.

Atmell guaranteed only 20mA in continuous use

No you are miss reading the specification. The 20mA refers to the the other parameters, those range of parameters they give regarding output voltage and so on only apply when the pin load is 20mA. They are not saying it will not work higher, the guaranteed only applies to the parameters.

Yes 40mA is the point at which damage starts to be done.

No you are miss reading the specification

No. I am french and I read a little english but I think that atmell datasheet is clear : Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

I think it's clear : if you do not want to risk you should not always use the micro to the absolute maximum rating. Notice : 1) they are also limitation per PORT and not only per output. 2) Outputs can source more mA that they can sink-> have a look to the I/O schematic and you will understand that this is normal.

It is so simple to interface with a transistor, especially with an motor, than risk killing the micro.

I think that atmell datasheet is clear

Yes it is clear, but you are not understanding it.

Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

Yes very true, that is why I said:-

40mA is the point at which damage starts to be done.

Outputs can source more mA that they can sink-> have a look to the I/O schematic and you will understand that this is normal.

Not according to the data sheet. Yes that is normally the case but not on this processor. Section 10.2 says:-

Figure 10-2 shows a functional description of one I/O-port pin,

That is it is not, a schematic. That resistor in the FET is the 30K pull up resistor . Anyway you cannot make this assertion because the limit on current sourcing will be higher than the 40mA absolute limit, so it has no meaning. Do you know how much current a pin can source? I did some measurements and clocked in excess of 250mA, well into the damage region.

What impact on reliability? During 40 years in R & D I've never seen colleagues take such risks. End of discussion.

No, not end of discussion. As you yourself quoted

Although each I/O port can source more than the test conditions (20 mA at VCC = 5V, 10 mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:

20mA is clearly NOT the maximum recommended, as long as the listed conditions are met.

During 40 years in R & D I've never seen colleagues take such risks.

What risk? The experiment with the output pin sourcing that much current? I knew what I was doing and I expected that pin to blow. Have you never worked with a safety department, they do that sort of thing all the time. Actually the pin still worked but I suspect it is damaged. I did it for this page www.thebox.myzen.co.uk/Tutorial/LEDs.html

Have you never worked with a safety department, they do that sort of thing all the time.

I have “just” worked in submarine links with coaxial cable and fiber optic.
Lifetime warranty : two failures in 25 years for all repeaters (beetween 50 to 100 units per link)
Also I have a “little” idea of what reliability is.

Now do as you hear it, I just wanted to correct a confusion between what should be the operating data and marketing information.

Have a nice day

I guess question was how to drive motor - not who can better interpret datasheets ;)

With my poor English and using Google translation I will try. In my humble opinion it is safer not to drive the motor dirrectement by the arduino, it is better to use dedicated circuits such as H-bridges (eg L293 / 1€ on Ebay). These circuits include protection diodes which act against the effects of Lentz's law (see Wikipedia for more information).

If the motor is designed to 5V, there is no resistance to calculate. If the motor is designed for less than 5V, 3V for example, you need to know the value of motor current for U = 3V. Then just apply Ohm's law : U = R * I U = volts R = Ohms I = amps U = Usupply - Umotor = 5V - 3V = 2V with example's values.

Attention, motor does not consume the same current whith no load or loaded. When the load increases the motor's speed decreases and the current increases.

I guess question was how to drive motor

or circuits see my page:- http://www.thebox.myzen.co.uk/Workshop/Motors_1.html