In this tutorial, a DC motor is interfaced with Raspberry Pi and then controlled its speed and direction with the help of two buttons connected with the circuit.

We cannot draw more than 15mA from any GPIO pins and DC motor draws more than 15mA, so the PWM generated by Raspberry Pi cannot be fed to the DC motor directly. So if we connect the motor directly to PI for speed control, the board might get damaged permanently.

So we are going to use an NPN transistor (2N2222) as a switching device. This transistor here drives the high power DC motor by taking PWM signal from PI. Here one should pay attention that wrongly connecting the transistor might load the board heavily.

 

The motor is an induction and so while switching the motor, we experience inductive spiking. This spiking will heat up the transistor heavily, so we will be using Diode (1N4007) to provide protection to transistor against Inductive Spiking.

 

Once everything is connected as per fritizing circuit diagram, we can turn ON the PI to write the program in PYHTON. You can download the program from the download section, or can find the detailed explaination here.