DC Motor with arduino

This is a simple code to run a dc motor. But motor is not responding. The voltage at the input terminals of the motor displaying 0.03V in volt mete. The motor is a 3V motor. What is the wrong here ?

void setup() { pinMode(11,OUTPUT); } void loop() { analogWrite(11,255); }

Analog output doesn't create a lower voltage, it creates a PWM signal. So with a volt meter you won't measure exactly what comes out of the Arduino, you'd need an oscilloscope for that.

What circuit are you using to drive your motor? (or which motor shield) If you attach the motor directly, your Arduino probably doesn't produce enough current to drive the motor.


I have directly connected the motor to the arduino. With a RPS I have run the motor with 2V, 0.40A.

The current of the PWM pin is 40mA only. So I have to use some driver circuit, Isn't ?

What may be the driver for this motor ?

So I have to use some driver circuit, Isn't ?


Assuming you didn't burn out the pin, that is...

Set up a simple sketch to digital write the pin you would using "directly" with a HIGH value. Then use a volt meter set on a scale to measure 5VDC, connect the black lead of the meter to ground and the red lead to the pin. It should read somewhere around 5V DC with a high level. Change the code to digital write a LOW value; the measured voltage should be around 0V DC.

If you get 4.9VDC for HIGH and 0.1VDC for LOW, that's OK. If you get anything else that isn't within a certain percentage, the pin is hosed. Buy a new ATMega.

Here's something I want to know, though. What made you think you could hook the motor directly up to the pin? I am curious from a standpoint that I am experienced with electronics, and have been playing around with them for many years (well, actually decades now - gettin' old). So I would like to know what a "newbie's" thought process is that led them to think they could hook such a thing up and it would work.

If I or others knew this, maybe we could come up with a better solution or documentation, or something - so that newbies wouldn't make this mistake - OVER AND OVER AND OVER.

Seriously - we seem to get this same kind of question here at least once a week, if not more often. What are we, the more experienced community doing wrong, that isn't plain and clear to newbies? Is there some kind of example or tutorial out there showing parts connected directly to ports/pins without and current limitations or driver circuitry? Is it because an LED hooked up this way (well, at least to pin 13 on certain Arduino designs - you can also sometimes get away with it on other pins - but its a no-no) works? Is a bad example being set by showing this simple electronic circuit? Should drivers always be shown?

I would love to see a time when newbies stop asking this question, and know why it is a bad idea, before they connect up anything - and quit killing their new Arduinos.

I doubt my dream will come true, though...



here's how I experience it and I'm pretty much fit your profile. Software guy without much clues about electricity.

The Arduino give the impression of simple and easy and clean. Call a function - 5 V appear on a pin - LED is on. It's very easy to create an easy to understand model: Inside the Arduino, there are a few light-switches with a software finger pressing them. Newbies love that kind of model, it makes learning a lot easier and faster. And specially for the software part, that model is actually quite good.

Now based on his model with the light-switch, the next very logical assumption is, a light switch that can turn on a light can also turn on a motor, why not. Only the next smoke plume emanating from their Arduino will indicate that the model needs to be refined with some more details.

Another problem is that while Volt is easy to measure and a common house-hold term, Ampere is a new concept and not that clearly understood by beginners in electronics. It just confuses them with all the new things to learn and doesn't appear important compared to other things - well until the previously mentioned smoke turns up.

How to improve matters? Perhaps Introduce a tutorial which needs simple transistor driver circuit very early on. Just like the first input hooked is a button with a pull-down resistor, make the first external thing hooked up something that uses a transistor - even if it's just a flashlight lamp (if those still exit).


Korman - my understanding of electronics from a "beginner" standpoint is actually kinda skewed. I played around with electronics as a kid, but I didn't start to understand until I went to a tech school here in Phoenix (known at the time as "High Tech Institute" - lol). Our first book was Grob's Basic Electronics; our first lessons were on Ohm's law and how voltage/resistance/current relate, and what each was. Our first circuits consisted of resistors, batteries, and Simpson analog multimeters (wish I had one today!). To learn soldering, our first project was to build a Radio Shack analog multi-meter kit, then we calibrated it against one of the Simpson meters.

I don't see this kind of progression online from people new to electronics - its more like "dive in feet first into this pool of sharks, alligators, and barracudas - good luck!". Certainly, this level of understanding (Grob starts with "what is an electron" - and works from there) is quite mind numbing, but it is very important in really understanding how it all works.

I am not sure if or whether such an "education" could be done with tutorials online (for one thing, there's no instructors or tests to really know if you know what you should know before moving on). Its a deep and thorough education; we didn't even touch digital electronics until after spending several months understanding analog (culminating in building and tuning an AM radio receiver) - because ultimately, digital circuitry is based on components that are analog in nature, so if you want to really know what is going on, you need this understanding.

Unfortunately, there is now this idea that electronics are like Lego, and should just fit together - but then the magic smoke comes out. Fortunately, this seems to only discourage a certain segment; the hackers, the foolhardy, and the just-plain-rich (to purchase a lot of components as they burn thru them by trial-n-error) persevere, and many go on to do amazing things...



I'm coming from from the software side - which seems to be more common these days - the clueless approach as you refer to it. In some way you're right, it is clueless, but times have changed. With highly integrated multifunction circuits, it makes these days not a lot of sense to start with winding your own coil to make a small dynamo using a magnet to light a flash-light bulb. Today the equivalent is the Blink Tutorial with the internal led on pin 13. Is the old or the new way better? Both and neither. If you have an Arduino for your first project, the flash-light bulb is rather pointless, the same if you just have wires and no computer. The same goes for soldering your own flip-flop out of transistors or learning about the 7473. Time changes and easy things become complicated while complicated things become easy.

The most useful lesson about all things electronic was from the project leader of the first microprocessor project I was involved in over 20 years ago. I was brought in as the software guy and all I knew about electronics and was flash-light bulbs and 9V batteries. He told me:

"Boy, there digital and analogue, digital is easy stuff you can understand, the analogue stuff is evil and only real men know how to handle that. You connect to your digital pins just other digital pins. Never connect two outputs together, it's just like peeing into a tube, if both ends are pee'd into, you'll end up with a mess. If you want to connect anything else to your digital pins, you call one of the electronic guys. If you don't your pin goes poof."

His other advice was:

"If you measure voltages on your signals, you either have below 0.2V or above 3.5V. Anything else is bad or complicated because of the evil analogue."

Those two things helped me through a few projects an kept me out of most trouble. Perhaps the tutorials need to teach the software-weenies more about what to be afraid of and where the areas with the dragons start. Most tutorials I've seen seem to assume people know what safe and reasonable around electronics, because they were written by electronic guys who got Ohm's law as lesson two (lesson one was which end of the soldering iron is hot).

As a side note, just as software guys and electronics don't mix, electronic guys should stay away from compilers. The worst software I've seen in my career, and there was quite a lot of bad stuff, where always written by electronic guys. Even marketing and business people's programs where better (but not much).


I think the problem is that most of the Arduino tutorials gloss over current and the laymen only really knows about volts. So if a pin can put out 5v then obviously it can run a 3v motor right?

I am an electronics newbie (my last real experience was 20 years ago with a 50-in-1 kit) but I have the benefit of having done physics in high school and so I know the difference between voltage and current (and this is back when you could still do cool science in schools like having the whole class join hands and then have the end links hooked into a lap power supply).

The Make: Electronics book is actually really useful for Arduino newbies because the experiments graphically illustrate why current is evil and wants to eat your Arduino.

P.S. I had to spend a week learning about stuff like "stall current draw" and "maximum continuous output" before I could pick out some motors and a controller for my project. Motor control isn't easy like hooking up some sensors and LED's.

It can be a cruel world when trying to learn practical electronics. You either learn slowly with applying your mind to new learning or you learn with your wallet replacing things that had their magic smoke removed.


PS: An additional lesson to be added to the ‘which end of the soldering iron is hot’ should be don’t solder while wearing shorts.