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.
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).