Transistor as switch unexpectedly blinks LED

Thread Starter

idkq

Joined Jan 29, 2022
9
I have the circuit below. GPIO15 goes to a ESP32 and lights up an LED. If 12v is completely connected, LED is on. When 12v is completely disconnected LED is off. This is the correct behavior I expect.

When only 12v- (GND) is connected (no 12v+ connection) LED is off. BUT, when only 12v+ is connected (no 12v ground) LED is flashing on and off.

Why is it flashing?

Am I missing something on how transistors work when positive only source is connected?

12V+12V-LED
CONNECTEDCONNECTEDON
DISCONNECTEDDISCONNECTEDOFF
DISCONNECTEDCONNECTEDOFF
CONNECTEDDISCONNECTEDFlashing (Why?)


1643505488980.png
 

BobTPH

Joined Jun 5, 2013
11,515
What are you trying to do? I can make no sense of your circuit.

is the GPIO an input or output? What is its purpose?

What kind of LED? Vf an If?

10K is way too large a current limiting resistor.

Bob
 

Thread Starter

idkq

Joined Jan 29, 2022
9
What are you trying to do? I can make no sense of your circuit.

is the GPIO an input or output? What is its purpose?

What kind of LED? Vf an If?

10K is way too large a current limiting resistor.

Bob
I’m trying to capture when a voltage source is provided. 12v is a pump that activates every few minutes so I want to count how many times it actually activated. The LED is just for testing purposes. GPIO 15 is set as input and the microcontroller reads and write to the LED GPIO. LED is not shown in this picture.

This is for a comercial product so I suspect that either the positive side or negative side can remain connected even when the pump is off. In this case I want to read off.
 

Thread Starter

idkq

Joined Jan 29, 2022
9
Yes. You are missing showing us where GPIO15 goes, the ESP32 and the LED.
Apologies I oversimplified the circuit and omitted the LED. LED is connected to another GPIO set as output and I read GPIO15 and write it on or off for testing purposes. In the real world this will be sent wireless via MPTT. GPIO15 goes to ESP32 microcontroller.
 

sghioto

Joined Dec 31, 2017
8,634
The base resistor is probably getting enough residual voltage through the pump circuit or the base maybe free floating when the pump is off. Connect a 100K resistor from the 12 volt input to ground , the right side of R4
What is the voltage on the GPIO 15 pin when the pump is on?
 

BobTPH

Joined Jun 5, 2013
11,515
OMG! I did not even notice there was no LED in the circuit! My brain put it in between the 10K resistor and ground.

So, without any indication of what the program on the ESP is doing, you want us to tell you why it is blinking the LED? Sorry, but my crystal ball is down tonight.

Bob
 

Thread Starter

idkq

Joined Jan 29, 2022
9
OMG! I did not even notice there was no LED in the circuit! My brain put it in between the 10K resistor and ground.

So, without any indication of what the program on the ESP is doing, you want us to tell you why it is blinking the LED? Sorry, but my crystal ball is down tonight.

Bob
Here is the source code...

SOURCE CODE:
const int buttonPin = 15;   
const int led = 13;
int buttonState = 0;

void setup() {
  Serial.begin(115200);
  while(!Serial) continue;
 
  pinMode(buttonPin, INPUT);
  pinMode(led, OUTPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState)
    digitalWrite(led, HIGH);
  else
    digitalWrite(led, LOW);

  Serial.println(buttonState);
}
 

MrChips

Joined Oct 2, 2009
34,812
What you have is too complex.
Remove the ESP32.
Remove the connection to GPIO15.

Now focus on the behaviour of the circuit you posted using a DVM.
 

ErnieM

Joined Apr 24, 2011
8,415
Adding a 100k resistor SOLVED the blinking issue! Thanks @sghioto
Meh. ‘Too many notes, dear Mozart, too many notes’ as Emperor Joe said to Mozart.

All you need do is constrain the 3V signal to an acceptable range for the ESP32, being 0 to 3.3V. Also, when the 12V is active you want to present a signal large enough to represent a HIGH to the input.

I'm not sure what the range for a high is, but >2.0V should suffice. I would recommend going to 3V for a high. To achieve this all you need is s simple voltage divider. I'd toss in a diode (1N4148 but not critical) too for safety in case the 12V is larger than expected.



DIV.jpg

Note I had to move *my* ESP32 board aside to type this
 
Top