Transistor not turning off, how comes?

Hi, I am using a transistor (S8550) to help me turn a motor on and off. It turns on but does not turn off. Please can someone explain why?

Here is my setup:

here is my code:

// Pin definitions D1 mini
const int MOT_PIN = 4; //using pin D2 on d1 mini
const int LED_PIN = LED_BUILTIN;

void setup() {
  // Initialize fan and LED pins as outputs
  pinMode(MOT_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  // Turn on the motor and LED
  digitalWrite(MOT_PIN, HIGH);
  digitalWrite(LED_PIN, LOW);

  // Wait
  delay(9000);

  // Turn off the notor and LED
  digitalWrite(MOT_PIN, LOW);
  digitalWrite(LED_PIN, HIGH); // d1 mini off = high

  // wait
  delay(18000);
}

That is because he D1 I/Os are 3.3V not 5V.
You may have damaged the D1.
If the D1 is still OK, I recommend using a NPN transistor to control th motor

thanks I think S8550 is NPN?

No, it's a PNP
See This:

Your circuit is missing a base current limiting resistor.

1 Like

is the current limiting resistor necessary because of the possibility of the motor pulling too much current than the transistor can handle?

In my case:
Motor: 200ma
Transistor limit: 500ma
MCU pin max: 40ma

No, it's necessary because of how a transistor works, it's a current amplifier. Also you should have a flyback diode on the motor...

That is an absolute maximum spec, you should never draw more than about half of that. When you run directly into a transistor base, you are probably drawing too much current. Also you are quoting an Uno/Mega current spec but using an ESP, which has an even lower max current spec.

In lay terms, you are "shorting out the pin".

So the resistor is to limit the current at the MCU pin to around 20ma?

Ohm's law:
Voltage = 5v
Current = 20ma
Resistor Value = 250 (Ohms)

5V? Aren't you using an ESP? Also, ESP pins are limited to about 12 mA, not 20. I told you about that difference in post #8. People will also be telling you to include the base voltage drop...

Regards you original question as it is stated, it is possible that the flyback pulse from the motor is continuously resetting the board, which keeps the motor on. To find out, put one serial print at the beginning of your sketch. If it's resetting, it will print repeatedly...

Hi,

Output Voltage - BaseEmitter voltage = 3.3 - 0.7 = 2.6V

20mA base current is MAX for ESP32, in fact 12mA is recommended.

2.6 / 0.012 = 216R or 220R closest standard value.

Depending on what NPN you use, you may even be able to use lower base current and so higher base series resistor.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

I will switch to Arduino Uno (5v pins) after Jim-P pointed out the 3.3v esp/5v arduino pin difference.

  • Esp (esp 5v pin) & 5v motor are powered with 5v battery
  • The esp pinout is 3.3v 12ma
  • Transistor base pin is 5v?

Is 1.2v voltage drop required to match base pin voltage to esp pin voltage or not?

Also how come 3-pin transistor pin order varies even though the transistor package look the same. Some transistor have base pin in the middle, some left pin.
12
13

You have the transistor between +5 and the motor, which is a high side switch. You need to have it as a low side switch, between 0V and the motor. E to 0V, C to motor, B via resistor to Arduino output. Flyback diode across the motor is essential.

1 Like

Hi,
This basic circuit may help.

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

Do you have any NPN transistors or do you need us to tell you what to buy?

I have a 200pc selection pack. The box is labelled with the transistor types:
BC337
BC327
2N2222
2N2907
2N3904
2N3906
S8050
S8550
A1015
C1815

I did a quick google search to find current limit & whether they are NPN or PNP and wrote it as thus (feel free to correct):
BC337 - NPN - 800ma
BC327 - PNP - 630ma
2N2222 - NPN - 800ma
2N2907 - PNP - 200ma
2N3904 - NPN - 200ma
2N3906 - PNP - 200ma
S8050 - NPN - 700ma
S8550 - PNP - 500ma
A1015 - PNP - 140ma
C1815 - NPN - 150ma

I am checking them now for ECB pinout as I think perhaps they may vary

Use the BC337.
For the wemos D1 use a base resistor of 620 ohms
For an UNO use 1K
Don't forget the diode across the motor

Redone circuit using:
S8050 NPN transistor
330ohm resistor (had laying around seems to be within limits)
N4001 diode (had laying around)

Circuit works nicely. Thanks for helping. Now to see if the D1 mini is still functioning haha....

4x1.6V= ??? (> 5V)

it's just how fritz does battery