[Solved] dc motor transistor switch oddness

Hi!

I am trying to use a transistor to turn power on/off for a dc motor (not PWM for now). From my googling I have made the attached circuit. However...

I can not get it to work unless I remove the 220Ohm resistor.

The motor speed is significantly slower than connecting it directly to the external 3 volt power supply (2 AA batteries). Too slow to be useable.

If I use another 3v battery pack to control the transistor instead of using the nano, the speed is a bit slower compared to connecting the motor directly to 3v. But much faster than when using the nano to control the transistor.

Is this expected or have I made a mistake?

Thanks!


sketch doc

DC motor transistor switching.jpg
this is the arduino sketch I am using to test:

//number of elements in arrays need to match for() cycles in void setup
int pinsIn[4] = {6, 7, 8, 9};
int pinsAnalog[8] = {0, 1, 2, 3, 4, 5, 6, 7};

int pin = 0;
int val = 0;
int pinsOut[4] = {2, 3, 4, 5};

void setup()
{
  //set up a total of pins for digital input (has to match number of elements in array)
  for(int i = 0; i < 4; i++)
  pinMode(pinsIn[i], INPUT);
  
  for (int i = 0; i < 4; i++) {
    pinMode(pinsOut[i], OUTPUT);
    digitalWrite(pinsOut[i], LOW);
  }
//DEFAULT works with thermistors,
//INTERNAL with transitor thermostats
// ELLER var det tvartom???
  analogReference(DEFAULT);

  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  pinMode(A4, INPUT_PULLUP);
  pinMode(A5, INPUT_PULLUP);
  pinMode(A6, INPUT);
  pinMode(A7, INPUT);
  
  Serial.begin(115200); // perhaps use a faster baud rate
}

void loop()
{
  Serial.print("knobs"); // use "knobs" as a keyword so you can receive
  // the knob values as a list with a [r knobs] in Pd
  for(int i = 0; i < 8; i++){
    unsigned int knob = analogRead (pinsAnalog[i]);
    Serial.print(" "); // first print a white space to separate the "knob" keyword from the values
    // and the values from each other
    Serial.print(knob); // then  print the actual knob value
  }
  Serial.println(); // finally print a newline character to denote end of data for keyword "knobs"

  // the same technique applies to the switches too
  // receive the switch values as a list with [r switches]
  Serial.print("switches");
  for(int i = 0; i < 4; i++) {
    int switchVal = digitalRead(pinsIn[i]);
    Serial.print(" ");
    Serial.print(switchVal);
  }
  Serial.println();
  
  //handle digital outputs
  if (Serial.available()) {
    static int temp;
    byte in = Serial.read();
    if (isDigit(in)) {
      temp = temp * 10 + in - '0';
    }
    else if (in == 'p') {
      pin = temp;
      temp = 0;
    }
    else if (in == 'v')  {
      val = temp;
      temp = 0;
      digitalWrite(pinsOut[pin], val);
    }
}
}

DC motor transistor switching.jpg

What transistor? What Arduino? Why not test with a simple program that just writes to pin 2?

Steve

Sorry but the drawing is useless. Generate a schematic and post that, I have a feeling by the time you have the schematic you will know what is wrong. I am still trying to figure out what a NPC is, maybe a NPN transistor. The speed change makes sense, you are losing about 25% to 50% of your voltage through the transistor EBC. A MOSFET would give you a marked improvement in performance.

Perhaps you've got the transistor pinout wrong? Different transistors have different pinouts, you
need to check the datasheet so that you definitely have base/emitter/collector correctly wired.

The 220 ohm resistor must be there or you will risk burning the transistor or Arduino.

If you have the transistor miswired it may or may not be damaged (reversing base and emitter
is a very easy way to blow most BJTs).

You circuit is designed for a NPN switching transistor (like a 2N2222A). It will not work with any PNP,
it will not work with a low current signal transistor, since motors take loads of current. Even the 2N2222A
will only handle a toy motor.

Can you confirm exactly which motor is involved?

I changed to a n-channel MOSFET and followed this guide, including using the simple test code.

Now it works fine with my code also.

The MOSFET I salvaged from an old PC-power supply. It's quite big and I can not make out what it says on it, but it works.

Thanks all!

gilshultz:
Sorry but the drawing is useless. Generate a schematic and post that,

Can you please give a suggestion for a simple and free method for me to be able to generate a good schematic? I am on mac osx.

MarkT:
The 220 ohm resistor must be there or you will risk burning the transistor or Arduino.
...
Can you confirm exactly which motor is involved?

Now when using a n-MOSFET it still does not work with the 220 ohm resistor. Is it needed when using a MOSFET?
The motor is a toy motor salvaged from a toy rc car. I run it on 3v. I will only use it to achieve vibrations on an object.

Try KiCad, it is free and runs on most platforms. Here is the link: macOS Downloads | KiCad EDA

Hand-drawn schematics are quick and easy if you can take a pic...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.