MosFet tutorial

The Mosfet is an output module that is used to work with high voltages and currents that the Arduino can’t supply. Unlike the Relay, it doesn’t support very high voltages; in fact it works until 24V DC. It’s very useful to control small motors, since it can be used like a regular PWM output to adjust the power supplied.

On the module there’s a connector with four ports: M- M+ +V and GND.
Into the M- and M+ ports we have to plug the device, while +V and GND are the place for the external power supply.

In this tutorial we connect a small DC motor running at 9V to the Mosfet, then we control its speed using a potentiometer.

This is what we are using for our tutorial:

Apart from the regular components like USB cables, shield and modules, we have two elements that we have to connect to the Mosfet.

The first thing is an external power supply: we are using a regular transformer that runs at the voltage required by our motor, 9V. If you don’t have one, before buying it, take a look in some old drawer; probably there’s some old mobile charger that runs at the voltage required, just look on the transformer for the output voltage.

This is the DC motor that we are going to use, it’s very simple and cheap: the more power you supply (inside its limit!), the faster it spins.

To see how fast it spins we put a small piece of plywood on its tip.

The TinkerKit! modules required are Mosfet and Potentiometer, but any analog sensor will do the job. The potentiometer is just easier to control.

This is how our transformer terminates. Since we need to put two cables into the Mosfet, we can avoid to cut it by plugging a couple of cables into the holes.
This is just a particular case though, usually they have a specific connector at the end; in that case just cut the cable and peel a small portion from the two wires that run inside of it.

We decided to use a female header to keep the cables steady:

Once we’re ready with the motor and the transformer, we can plug them into the Mosfet

Let’s start with the motor. The two wires must be placed into the M+ and M- connectors. Don’t worry about the order; reversing them will just cause the motor to spin in the other direction.

The next step is plugging the transformer in the remaining connectors. Here the order matters: the ground must be connected to the GND and the power to the +V connector.

If you have a tester, it’s a piece of cake: just touch the two wires with the tips of the tester, if the result is positive, this means that the red tip touches the power and the black the ground. If the result is negative they’re inverted.

If you don’t have a tester: the Mosfet module is designed in a way that it shouldn’t break if you connect the wires in the wrong order. We don’t take responsibility if you break it in this way but it’s safe to try: if the motor doesn’t work just invert the wires into the Mosfet connector.

The final cable layout:

Then connect the potentiometer to an input port.

The TinkerKit! library for the Arduino software includes a TKMosFet object. In our tutorial we use the .write() method to give a specific amount of power to the motor. Like all the TK methods, the value goes from 0 to 1023. We use the potentiometer to see the variations:

#include <TinkerKit.h>

TKMosFet mos(O0);  
TKPotentiometer pot(I0);

void setup() {

void loop() 
  int val =;

Upload the code onto the board and finally plug the transformer in the socket.
If the motor doesn’t spin when the potentiometer is rotated, check the various contacts. If you didn’t test the transformer’s wires it’s likely that they’re inverted.

If everything was done correctly, you should see the motor spinning and by rotating the potentiometer we change the speed of rotation.

  1. February 4, 2013

    awdhesh kumar

    It’s an effective demo for understanding to a beginner. Suggest insert a bit higher technical demo for engineering students’ understanding.

  2. November 28, 2013


    I wanna control a DC motor just like you but I don’t have tinker shield and potentiometer. I want to use the mosfet directly with Arduino but I don’t manage to do it.

    I have a H-bridge to control my motor. The power supply is 20V, so i put 20V in V+ and GND, then I put my motor in M+ and M- but i don’t know where to put the 2 outputs of my H-bridge in the mosfet kit. I want to control my motor when my arduino send a ’1′ TTL and stop it when ’0′.

    Can you help me ? And sorry for my english…

    • Avatar of Angelo
      December 13, 2013


      Hello Vincent,
      Sorry but I don’t understand what you want to do.
      Here some information: you can control the motor directly with the H-bridge, you don’t need the mosfet module.
      If you want to use the mosfet module then you don’t need the H-bridge because you can directly connect the Arduino to your module and the module to the motor.


Leave a comment