Control DC Motor on the Arduino directly from Analog

analogarduinodc motortransistors

Is is possible to control a toy DC motor (5V) on an Arduino directly from the Analog (or Digital with PWM) pin without damaging the board? I know that DC motors are usually controlled via a transistor but I am thinking of controlling it this way. My Arduino code is:

    void setup() {
         pinMode(6, OUTPUT);
         Serial.begin(9600);
    }
    void loop() {
         int val = Serial.parseInt();
         if( val >= 0 && val <= 1024) {
             analogWrite(6,val);
             delay(5000);
         }
    } 

My schematic:

GND———————MOTOR————–|<|——-D6 (PWM)

Best Answer

There are a number of problems with your approach - while simple, you will be facing a number of challenges.

  1. The maximum current output from your Arduino will probably be a maximum of around 40mA (http://arduino.cc/en/Main/ArduinoBoardUno). This is insufficient to drive a hobby motor. Most small project motors will draw 100 to 500 mA of current. I think you might be at risk of damaging your Arduino.

  2. Even if the motor could be run at a very low current (less than 40mA), motors are noisy - they use brushes and contacts that create electrical noise that can cause interference with the microcontroller. There are techniques for removing this noise, like using filter capacitors connected to ground and sometimes a diode across the motor (http://www.pololu.com/docs/0J15/9).

  3. Lastly, you would be limited to the voltage supplied by the microcontroller (in this case 5V DC). Many motors run at different voltages - such as 6V or 12V.

There are many good circuits describing how to run a motor using easy to find components if you do a quick search on Google!