Electronics · CLEAR

Motor Switch Circuit

An Arduino switching a DC motor through a transistor, with a flyback diode catching the voltage kick when the motor turns off. Built in Tinkercad.

Play the cartridgeView repo

The problem

A DC motor needs far more current than an Arduino pin can give. The Uno R3 tops out at 40 mA per pin, and pushing a motor straight from it risks the board.

I wanted a small 5 V signal from the Arduino to switch a motor running on its own 9 V battery, and to do it safely. It was also my first time using Tinkercad.

The approach

Pin 9 drives a 2N2222 NPN transistor through a 1 kΩ base resistor. That keeps the base current near 4.3 mA ((5 V − 0.7 V) / 1 kΩ), well inside the pin limit while still switching the transistor fully on.

The motor sits between the battery and the collector, so the transistor works as a low-side switch. The Arduino ground and the battery ground are tied together, otherwise the base current has no return path.

A 1N4007 diode sits across the motor, reverse-biased. When the transistor switches off, the motor coil kicks back with a voltage spike, and the diode gives it a safe path instead of the transistor.

The sketch turns the motor on and off every second, which proves the Arduino is switching the higher-current circuit.

Schematic

Schematic: Arduino Uno pin 9 through a 1 kΩ resistor to an NPN transistor base; the motor between the 9 V battery and the collector, with a diode across the motor.
Schematic exported from Tinkercad.

Code

// DC Motor Switching Circuit
// Turns a DC motor on and off every second using an NPN transistor (2N2222)
// as a low-side switch. Pin 9 drives the transistor base through a 1 kΩ resistor.

const int MOTOR_PIN = 9;   // Arduino pin connected to the transistor base

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

void loop() {
  digitalWrite(MOTOR_PIN, HIGH);  // Transistor on  → motor runs
  delay(1000);                    // Wait 1 second
  digitalWrite(MOTOR_PIN, LOW);   // Transistor off → motor stops
  delay(1000);                    // Wait 1 second
}

motor_switching.ino, also in the repo.

Photos

Tinkercad breadboard view: Arduino Uno, NPN transistor, resistor, diode, DC motor and 9 V battery wired together.
The circuit in Tinkercad.
Tinkercad simulation with the circuit on the left and the Arduino code on the right.
Circuit and code side by side in the simulator.

Next steps

Rebuild the circuit on a real breadboard and check that it behaves the same as the simulation.