I have a small DC motor but it won't work

I have a DC motor and I want it to turn on a very simple need, but I tried a lot of stuff but it won't work, I hooked the motor up to a small battery and it worked fine, so something is off with my code, can someone help me?
Code:

const int motorPin1  = 9;

void setup() {
  pinMode(motorPin1, OUTPUT);

}

void loop() {

}

Likely not only that.
Read and pay attention to this link: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

1 Like

Are you trying to power the motor with an Arduino pin? That will not work. You need a transistor or motor driver to power the motor with an external power supply.

You need a digitalWrite() to change the state of the pin. The default state of an output pin is LOW.

1 Like

Will a relay work?

Yes, but the relay must be driven by a transistor because a pin can't, directly, drive a relay either. The external power will be required for the relay coil, too. A relay takes a certain amount of current to hold it closed. It will draw that current all the time that is is closed.

A transistor driver draws much less current and the MOSFET draws nearly 0 current.

A relay cannot accept PWM for motor speed control. A transistor or motor driver can.

So, yes, a relay will work. It is less efficient and practical, though.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.