A transistor is a semiconductor device that can be used as a switch, amplifier, or for other electronic functions. Transistor has three terminals for connection to an external circuit.
In this tutorial, we will learn how to use a NPN transistor to operate a DC motor. It will provide the motor with the necessary power.
Connect the wires between the NPN transistor, the motor and the Raspberry pi 5 board, as shown in the image below.
Connections from the NPN transistor:
• NPN emitter pin → Raspberry Pi 5 GND pin
• NPN base pin (middle pin) → 4.7 KΩ resistor → Raspberry Pi 5 pin 18
• NPN collector pin → Motor first wire
Connections from the motor:
• Motor first wire → NPN collector pin
• Motor second wire → Raspberry Pi 5 VCC pin (5V)
Now on your Raspberry Pi, click on the menu, then choose programming, then open the Thonny ide program.
Now copy that code into it, The function of this code is to turn the DC motor on and off for 5 second.
Now run the code, you will find that the Raspberry Pi 5 board turns on and off the DC motor for 5 second.