0

I am using Tinkercad simulator, but an unusual thing happened. When I connect one wire of dc motor to pin 9 with digitalWrite(9,HIGH) and other wire to ground, the motor runs with rpm of 5555.

void setup()
{
  pinMode(9, OUTPUT);
} 

void loop()
{
  digitalWrite(9, 1);
}

But instead if I connect the other wire to pin 13(say) and set digitalWrite(13,LOW) the motor runs at an rpm of 3846.

void setup()
{
  pinMode(9, OUTPUT);
  pinMode(13, OUTPUT);
} 

void loop()
{
  digitalWrite(9, 1);
  digitalWrite(13,0);
}

Can anyone explain this?

  • 2
    Tinkercad probably doesn't have an option to show smoke coming from your Arduino, which is what would happen if you tried to ground a motor through a pin set to LOW. DON'T DO THAT. As others have mentioned, It can't handle the current, and a motor is a "dirty" load that can push negative voltages into the pin through a process called "back EMF". (It is caused by the inductive coils in a motor. When you remove power from an inductor, the collapsing magnetic field causes a surge of current flowing backwards.) – Duncan C Sep 30 at 14:57
  • Thank you, next time I'll use a motor driver – Akash Karnatak Sep 30 at 16:20
  • 1
    You can control a regular DC motor with a power MOSFET and a "flyback diode". A motor driver is overkill unless you have a servo or a stepper motor. – Duncan C Sep 30 at 17:39
5

Yes, it is different.

First: Never run a motor directly from IO pins - you will damage your Arduino. Not only can a real Arduino not supply enough current, but motors generate a lot of back-EMF that will kill an Arduino.

Secondly a pin doesn't connect direct to GND or VCC - it is connected through a MOSFET that performs the switching. That MOSFET has an ON resistance, which causes a voltage drop across it determined by the current being sourced or sunk through the pin.

You can read more about GPIO pins here.

  • Thank you, next time I'll use a motor driver – Akash Karnatak Sep 30 at 16:19
1

In the real world, either pin sinks current to Gnd via an onchip N-channel MOSFET. They will safely sink 20, 25mA. If your motor allows more than 40mA to flow, you risk damaging the pin and likely the whole chip.

Similarly, either pin can source the same current to a load, likely via P-channel MOSFET, with the same current limitations.

Using both together, you have one transistor sourcing current, one transistor sinking current, so you have twice the Rds (MOSFET on-resistance) limiting current to the load, hence the simulator might have the motor going slower due to less current being available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.