Arduino: How to control a DC motor (Lego Technic) with a mosfet

In this video I demonstrate an easy way to control a DC motor with an Arduino and a mosfet.
The sketch used in this video can, as always, be copied from here under the video.

sketch:

int motorPin = 11;
int potiPin = 0;
int poti = 0;

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

void loop(){
poti = analogRead(potiPin)/4; // reads the input pin; from 0 to 1023
analogWrite(motorPin, poti); // analogWrite; value from 0 to 255
}

 

connections:

k-DSC01423 k-DSC01426 k-DSC01430 k-DSC01432 k-DSC01433

The motor is a Lego Technic motor, the mosfet used in this video is a IRLU 2905. Beside that you only need a schottky diode for example the SB 140, a potentiometer and some resistors.