هنر
زیبایی و سلامت
صنایع دستی
فرهنگ و تاریخ
سرگرمی
محیط زیست
غذا و نوشیدنی
آینده سبز
مهندسی معکوس
علوم
ورزش
فناوری
پوشیدنی‌ها
Driving a Motor — SIK Circuit 12
Ed

ایجاد شده توسط

Ed

17. March 2026

Driving a Motor — SIK Circuit 12

Spin a DC motor at variable speeds using a transistor as a switch. Learn about transistors, flyback diodes, PWM motor control, and serial input for speed control.

دستورالعمل‌ها

1

Parts & Introduction

DC motors draw too much current for an Arduino pin to drive directly. A transistor acts as an electronic switch — a small signal from the Arduino controls a larger current flowing through the motor. The flyback diode protects against voltage spikes when the motor turns off.

Parts Needed

  • 1x Arduino Uno + USB cable
  • 1x Breadboard
  • 1x DC Motor
  • 1x NPN Transistor (P2N2222A)
  • 1x Diode (1N4148)
  • 1x 330Ω Resistor
  • 6x Jumper Wires
2

Hardware Hookup

Wiring Instructions

Transistor pinout (flat side facing you, pins down): Collector, Base, Emitter (left to right).

  1. Place the transistor in the breadboard.
  2. Connect Base (middle pin) through a 330Ω resistor to Arduino Digital Pin 9.
  3. Connect Emitter (right pin) to GND.
  4. Connect Collector (left pin) to the motor's black wire.
  5. Connect the motor's red wire to 5V.
  6. Flyback Diode: Connect the banded end (cathode) to 5V, the other end (anode) to the motor's black wire.
3

Arduino Code

Open the Arduino IDE and upload the following sketch to your Arduino board.

dc_motor.inoarduino
/*
SparkFun Inventor's Kit
Example sketch 12 — SPINNING A MOTOR

Use a transistor to spin a motor at different speeds.

Hardware connections:
  Transistor BASE through 330 ohm resistor to digital pin 9
  Transistor EMITTER to GND
  Transistor COLLECTOR to motor black wire
  Motor red wire to 5V
  Flyback diode: band (cathode) to 5V, anode to motor black wire

This code is completely free for any use.
*/

const int motorPin = 9;

void setup()
{
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  serialSpeed();

  //motorOnThenOff();
  //motorOnThenOffWithSpeed();
  //motorAcceleration();
}

void serialSpeed()
{
  int speed;

  Serial.println("Type a speed (0-255) into the box above,");
  Serial.println("then click [send] or press [return]");
  Serial.println();

  while(true)
  {
    while (Serial.available() > 0)
    {
      speed = Serial.parseInt();
      speed = constrain(speed, 0, 255);

      Serial.print("Setting speed to ");
      Serial.println(speed);

      analogWrite(motorPin, speed);
    }
  }
}

void motorOnThenOff()
{
  int onTime = 3000;
  int offTime = 3000;

  digitalWrite(motorPin, HIGH);
  delay(onTime);
  digitalWrite(motorPin, LOW);
  delay(offTime);
}

void motorOnThenOffWithSpeed()
{
  int Speed1 = 200;
  int Time1 = 3000;
  int Speed2 = 50;
  int Time2 = 3000;

  analogWrite(motorPin, Speed1);
  delay(Time1);
  analogWrite(motorPin, Speed2);
  delay(Time2);
}

void motorAcceleration()
{
  int speed;
  int delayTime = 20;

  for(speed = 0; speed <= 255; speed++)
  {
    analogWrite(motorPin, speed);
    delay(delayTime);
  }
  for(speed = 255; speed >= 0; speed--)
  {
    analogWrite(motorPin, speed);
    delay(delayTime);
  }
}
4

Test & Experiment

What You Should See

The default serialSpeed() function lets you type speed values (0-255) into the Serial Monitor to control motor speed in real time.

Troubleshooting

  • Motor not spinning: If you sourced your own transistor, double-check the pinout — many NPN transistors have reversed pin orders compared to the P2N2222A.
  • Motor won't start at low values: Below ~50, the motor doesn't have enough torque to overcome friction. This is normal.
  • Connection issues: Try unplugging and re-plugging the USB cable.

Experiments to Try

  • Uncomment motorAcceleration() to see smooth speed ramping.
  • Add a potentiometer to control speed with a knob instead of serial input.
  • Add a button for on/off control.

مواد

  • SparkFun Inventor's Kit - V3.2 - 1 kitNOK 999.20
    مشاهده
  • Arduino Uno R3 - 1 pieceجایگزین
    مشاهده
  • Breadboard - 1 pieceجایگزین
    مشاهده
  • DC Motor - 1 pieceجایگزین
    مشاهده
  • NPN Transistor (P2N2222A) - 1 pieceجایگزین
    مشاهده
  • Diode (1N4148) - 1 pieceجایگزین
    مشاهده
  • 330 Ohm Resistor - 1 pieceNOK 24.00
    مشاهده
  • Jumper Wires - 6 piecessNOK 39.20
    مشاهده

ابزارهای لازم

  • Computer with Arduino IDE

CC0 مالکیت عمومی

این نقشه تحت مجوز CC0 منتشر شده است. شما آزاد هستید آن را کپی، ویرایش، توزیع و برای هر هدفی بدون نیاز به اجازه استفاده کنید.

با خرید محصولات از طریق نقشه از سازنده حمایت کنید و او کمیسیون سازنده تعیین شده توسط فروشندگان، دریافت می‌کند یا یک نسخه جدید از این نقشه ایجاد کنید و آن را به عنوان اتصال در نقشه خود قرار دهید تا درآمد به اشتراک گذاشته شود.

بحث و گفتگو

(0)

ورود برای شرکت در بحث

در حال بارگذاری نظرات...