Explain the use of a transistor in a motor driver

I have the following arduino code that reads potentiometer values and map them to values between 0 255 in order to control small 3.3V mini vibration motors.

const int potPin = A0;
const int motorPin = 3;
const int threshold = 2;

int potValue = 0;
int pwmValue = 0;
int prevPWM = 0;

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

void loop() {
  potValue = analogRead(potPin);
  pwmValue = map(potValue, 0, 1023, 0, 255);

  if (abs(pwmValue - prevPWM) > threshold) {
    analogWrite(motorPin, pwmValue);
    Serial.print("PWM ");
    Serial.println(pwmValue);
    prevPWM = pwmValue;
  }
}

I have the following schematic:

Any suggestion regarding code and electronics?

I try to understand the use of the transistor in the above application. a small current at the transistor gate will open a “way” to larger current to pass from VCC via the motor pins to transistor collector to the emmiter ?

what I should know about the transistor datasheet that is relevant for me?

looking at this 2N3904 datasheet - there is a lot of information in the table - what should I look at?

any other explanation of how the transistor works in that configuration?

Thanks

What kind of suggestion? They seem like good, clear, simple examples.

Correct. Except the pin is called "base" not "gate" in this type of transistor.

If it's a 5V motor why are you powering it with 5V.

Your link about the motor says

Micro Vibration Motor Rated Voltage: DC 3V;Rated Current: 85mA, Rated Speed: 12000 RPM,Voltage range: DC1.5-3.7V

But you are powering it with 5V. This may burn it out.

Also, while the current rating says 85mA, when motors start up from stationary, they will draw 5x to 10x that current, for a short time.

I am dropping the voltage to 4.3V with that diode - I think this motor can handle it. I will drop the voltage with another diode to 3.6V~ if required

I’m using 5V 2A PSU for powering it. I will drop the voltage with 2 diode if needed

The maximum rated voltage is 3.7V, so 4.3V could still burn it.

Your transistor will also drop some voltage, probably around 0.7V, so that may be ok.

The forward voltage of a diode is not a constant, it will vary with current. If you want to power the motor with 5V it's OK just don't expect it to last very long.

In any case you need to reduce the base resistor value. You want to make sure that the transistor is fully on so to speak.
There are different rules of thumb but I usually you the 5X rule. So make sure the collector current is 5X what is needed. Lets say the motor needs 100mA, so the collector current should be at 500mA. With a minimum Hfe of 50 for the 2N3904 the base current should be 500/50 = 10mA.
With 5V from the Arduino and a Vbe of 0.7V, the resistor should be (5-0.7)/10mA = 430 ohms, 470 is close enough

between Collector to Emitter there is a 0.7 Voltage drop? where it is written in the datasheet?

what is this calculation? Hfe of 50?

Sorry, I did not check the data sheet. It is only about 0.2~0.3V. in the datasheet it is called VCE

That's at saturation so your estimate could be correct under the actual conditions.

If you want to learn about transistors, this website is an excellent source of information.
https://www.allaboutcircuits.com/textbook/semiconductors/chpt-4/bipolar-junction-transistors-bjt/

You may also want to see the chapters on other semiconductor devices such as diodes and MOSFETs

This explains how to use the transistor as a switch
https://www.electronics-tutorials.ws/transistor/tran_4.html

It is a 3.3V motor.

The base resstor of the transistor is 1k. So, base current is about 5-0.7/1000 = 4.3 mA. The following saturation curve (Fig-1) shows that 4.3 mA base current causes VCE(sat) to be around 0.43V. So, @PaulRB's assumption of 0.7V makes some sense!


Figure-1:

In that case the 2N3904 is not suitable for the mission? look on the blue rectangular

My 5X rule does not imply that the transistor you are using can handle the 5X current, it is just a simple and easy calculation to make sure that the transistor is in complete saturation and acts like an on/off switch.
Since the 2N3904 has a max Ic of 200mA, it should be adequate for your motor if you power it with 3.3V.
You should read the tutorials that I gave links to.
Best way to learn is to build the circuits and measure the voltages and currents.

Thanks this make sense.

It's not a good idea to exceed the manufacturer's specification. It might "handle it", but it might not last long.

As mentioned, in-rush current can be a lot more than the running current.
A good example is a halogen lamp. It might pull 1-Amp when very hot, but 10-Amps when cold.

With 4.3mA base current there won't be much of a motor inrush current.
The transistor will get out of saturation just above 100mA.

! A not saturated small signal transistor is in danger of overheating.
A 2N2222 with 330 Ohm base resistor seems much safer for a small motor.
Leo..