Do I need a resistor behind the LED in this situation?

Thread Starter

FranciscoB

Joined Feb 8, 2014
85
The PIR sensor's output goes high when motion is detected. Output signal is at 3.3V and goes through a 1500 ohm resistor.

I use this output signal to trigger an interrupt in my microcontroller, on the rising edge of the signal.

I would like to have a visual indication of when the output is HIGH. Do I need an extra resistor for the LED, or can I just place the LED in parallel with the MCU?

Thank you.
 

Attachments

dl324

Joined Mar 30, 2015
15,435
I would like to have a visual indication of when the output is HIGH. Do I need an extra resistor for the LED, or can I just place the LED in parallel with the MCU?
It's worse than that. Since the output from the module has a 1.5k series resistor, you'll need to use a buffer to drive the LED so you don't load the output.

Unless you can operate the LED at a very low current (with a series resistor)...
 

djsfantasi

Joined Apr 11, 2010
8,652
Depends…

It depends on the LED you use and the loading of the output line by the microprocessor.

You need to know the forward voltage (Vf) and current requirement (A) of the LED. Then, calculate if the 1.5kΩ resistor results in enough (and not too much) current for the LED.

AND as dl324 said, the LED may load the output line to the point the MCU cannot detect the output of the PIR… YMMV
 

Ian0

Joined Aug 7, 2020
6,667
If you use a blue or white LED, then the LED forward voltage will be higher than the minimum voltage for the pin to be recognised as high by the microprocessor, which is generally 2.4V.
If you use a red LED (forward voltage 1.8V) it might read the pin as high, and it might not.
 

WBahn

Joined Mar 31, 2012
27,855
If you use a blue or white LED, then the LED forward voltage will be higher than the minimum voltage for the pin to be recognised as high by the microprocessor, which is generally 2.4V.
If you use a red LED (forward voltage 1.8V) it might read the pin as high, and it might not.
If the LED had a forward voltage of 2.5 V (barely over the typical 2.4 V level for detecting a HI input), then that 1.5 kΩ resistor is going to limit the current to 1.7 mA. That really limits the LED selection. A quick check of DigiKey revealed only nine active parts (the highest voltage being 2.75 V), and some of them aren't in the running because the forward voltage spec was measured at 20 mA and not the spec'ed 0.5 mA test current (at which the forward voltage is ~1.7 V). And this is all assuming that the MCU input current is still negligible at this low a current (this is likely a good assumption).

The better solution, I think, is to use a transistor to buffer the current. If nothing else, that minimizes the perturbation to the interaction between the sensor and the MCU.

Tie the collector to 5 V and put the LED and a resistor in series in the emitter path. Size the resistor to drop about 2 V at the desired LED current.
 

Thread Starter

FranciscoB

Joined Feb 8, 2014
85
Tie the collector to 5 V and put the LED and a resistor in series in the emitter path. Size the resistor to drop about 2 V at the desired LED current.
If I understood correctly, the output of the PIR would connect both to the base of the transistor and the GPIO of the mcu, correct?
 

Thread Starter

FranciscoB

Joined Feb 8, 2014
85
What is the input voltage level spec for your micro?
The microcontroller is an ESP32-Cam, which works at 3.3V with 3.3V logic GPIO.

I have just realized the drawing of my initial post is incorrect, it should show 3.3V not 5V.
 

WBahn

Joined Mar 31, 2012
27,855
Would it make sense to use an n-mosfet and p-mosfet as such? (I have plenty of all these components)
No need to get that elaborate. As long as the threshold voltage of your NFET isn't much more than 2.5 V you can drive it directly from your sensor output and put an LED/resistor combo in the drain path.

If your supply voltage is only 3.3 V, you will want to use a red or green or other relative low voltage LED. You may not have enough overhead to reliably turn on a blue LED.

Is the sensor output active for both HI and LO outputs?
 

WBahn

Joined Mar 31, 2012
27,855
Do you have a spare output from your micro? If so, use it to drive the LED.
Not a bad idea, though it does require a program change to the MCU code. Also, it makes the indication one further step removed since the LED no longer indicates just that the sensor is outputting a HI, but also that the MCU recognized it. Depending on what the true purpose of the LED is, that might or might not be a good thing.
 

Ian0

Joined Aug 7, 2020
6,667
Not a bad idea, though it does require a program change to the MCU code. Also, it makes the indication one further step removed since the LED no longer indicates just that the sensor is outputting a HI, but also that the MCU recognized it. Depending on what the true purpose of the LED is, that might or might not be a good thing.
Another idea would be a buffer such as 74LVC1G17 (or 74LVC1G04 if it doesn't matter if it is inverting). That would give a logic output that could drive an LED.
 
Top