Motor not running with mosfet

Hi,

Intro
I would like to control my (Lego) motor via my Arduino. The end result might involve pressing buttons, leds, fancy code etc. But first, I try to get the basics working. With the motor, I ran into an issue. It does not run when it is connected through the mosfet.

I feel kind of stupid, because it is really simple what I try to do and I am not able to solve it.... I tried to search around, but was unable to find anything. Other than posts that explain how to create a circuit with a motor and mosfet, which I think I followed correctly. (Think, because my setup doesn't work). I am skilled in coding, but less experienced in electronics.

The rest of my post will show the hardware I use, my schematic, explain what I read and tried.

Hardware used
I have an Arduino starterskit and referred to Project 09 Motorized Spinweel.
The board is an Arduino Uno.
The motor is an old Lego motor from 1980's, 4.5 V.
The Arduino starter kit contains two different types of transistors/mosfets. I tried both.
I used a diode to avoid back voltage from the motor.
I did not use a resistor, because I need the 5 V that comes from the arduino board, not less. ( Is this correct, this post confirmed my opinion: Where do I need resistors? - Motors, Mechanics, Power and CNC - Arduino Forum )
The chapter from the book advises to use a battery to power the motor. I did not do this, because I dislike to have a second power source and I assumed the 5V output of the board is enough for the motor.

Code
For the test setup, I kept the code simple and just want to send a "full on signal":

int motorPin = 3;
 
void setup() 
{ 
  pinMode(motorPin, OUTPUT);
  analogWrite(motorPin, 255);
} 
 
 
void loop() 
{ 
    analogWrite(motorPin, 255);
}

Schematics and actual photo
Sorry, I probably did not draw the diode and mosfet correctly. Also, I might not have connected the pins in the right order in the schematics. Because I am not sure what every icon means exactly.
circuit.png

Actual photo is in mill-circuit-photo.png . I added two leds (with transistor) to debug.


Debug
I tried to connect the motor directly to a 9V battery (I assumed it was 9V before I googled it, because of other Lego stuff that runs at 9 or 12V) and that works fine.
In the current setup, when I change the orange wire from the motor directly to ground, making it connected to 5V and ground directly, the moto spins fast.
Conclusion: motor works ok. Motor works ok with 5V from Arduino via USB.

I added a blue led (and transistor) to the digitalpin 3, which is on. Conclusion: I have the right pin in the code and code for having the pin "on" is correct.

I added a green led via transistor to 5V and to the output from the mosfet where motor is also connected. Actually it is connected in the same way as the motor.
When the led is connected, but the motor is not: the led is on, bright.
I changed my code a bit; added a delay, switch off, delay, back on. The led switches off and on.
Conclusion: the mosfet is working, I connected mosfet pins in the correct way.

When I connect both the led and the motor, the led is on, but not very bright. The motor does not spin.
When I help the motor a bit to start spinning. Or when the motor spins, because it is connected directly to ground, I quicky change the wire to the mosfet. Then (both cases) the motor will spin, but slowly.
Conclusion: I do not understand. It seems that there is not enough power for the motor to startup nor to spin at expected speed.

I tried both the types of mosfets in the Arduino starters kit and of both I tested different mosfets.
The smaller, totally black one, as in the photo, can get the motor spinning as described above.
The other one (larger, black with metal top) does not get the motor spinning in any way.

I did try to find an explanation on the forums. I read something about minimal current for mosfet and something about "bad mosfets". But I did not understand what was written. Only that the mosfet could be the problem. However, as it is in the starterskit, described in different tutorials, it should be working, right? So do I need another mosfet or do I have a stupid mistake somewhere?

Concluding remarks
I am new to electronics. I tried to build a basic setup with my Arduino starter kit and a Lego motor.
Although I couldn't find any solution after reading different tutorials and forum posts, I decided not to give up but make this post.
The post explained my setup and the things I tried, what I observed and my conclusions.
I would really like if somebody could point me to the mistake I made or explain how the mosfet is expected to work and why the motor doesn't get enough power in my setup (if that's the case).

circuit.png

Your circuit doesn't show a MOSFET, it shows a transistor connected completely the wrong way round. So what are you actually using? What TYPE of transistor or MOSFET? They always have codes printed on them and that's the information needed. There are lots of starter kits with lots of different components in them.

And whether it's a transistor or MOSFET there should be a resistor between Pin3 and the transistor/MOSFET.

Also the Arduino 5V cannot safely provide enough power to run a motor, particularly when it's running from a weedy little 9V battery. The motor should be separately powered maybe with 4 x AA batteries.

Steve

The transistor/mosfet has this text on it: BC547 B 331 .
The one I used before (and never spins the motor) is IRF520 Y71K AN 4A.

The Arduino is powered via USB, not via a 9V battery.
You say the Arduino 5V cannot safely provide enough power. Why is that? Is that due to wattage?
When I connect the motor directly to the 5V it works fine.

It seems the transistor (or mosfet) does not let enough power through.

Hope this helps. :slight_smile:

NPNMot-2.pngMosMot-1.png

NPNMot-2.png

MosMot-1.png

BC547 has a maximum collector current rating of 100mA. Probably not enough for a motor.

IRF520 is not a logic level MOSFET. It will not turn on fully with 5V on the gate.

To choose a transistor to drive the motor you need to know the stall current. If you don't have a data sheet that lists the stall current you can estimate the stall current. To estimate the stall current, measure the motor winding resistance. Take several measurements rotating the motor a bit between readings. Use the lowest reading in the calculation. The estimated stall current is the motor supply voltage divided by the measured resistance. The driver that you choose must be able to handle the stall current as the stall current is pulled, briefly, every time the motor starts.