Let's Make Robots!

DIY not gate


i tried building a not gate (1 input only), not one i saw on the internet but i tried to make one myself. The problem is i didn't succeed. Now, i know there are loads of examples of how to make one on the net, but i opened this post because i'd like to know why mine doesn't work, so i can improve, hopefully :), my electronics skills.

Here it is:


..the LED doesn't light up. how come? Oh btw i forgot to mention that the base of the PNP is connected to an MCU, and i wanted the LED to light up when the pin goes low.

Thank you for the answers, in case i forget to thank you later :=D ! 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
I took R2 away and now it works! Thank you for the advice TeleFox! Now i only need to understand which setup works better.

Any explanation on why removing R2 would allow it to work? From looking at the setup, I can't see why that would prevent it from working. All resistors seemed to be of reasonalble value.


When the PNP is active, current is pulled through R2 causing the voltage to drop across it. The voltage seen at the PNP's collector is therefore 5V-(R2*Ip+VceSAT), where Ip is the PNP emitter current, and this voltage is applied to the MOSFET gate to turn it one. If you remove R2 then the voltage at the collector is now simply 5V-(VceSAT), which is always going to be higher than before, so more likely to turn on the MOSFET.

I'd also suggest moving the LED to the other side of the MOSFET - the LED itself won't care, but the MOSFET will now see a greater Vgs (gate to source voltage), which will ensure it turns on fully. This results in lower losses through the MOSFET, and also allows the circuit to operate at a lower supply voltage (only really important if using batteries).

:O so much knowledge in just one person! Could you tell me where you have learned all this? It would be very useful and i would avoid bothering guys like you all the time ! :) 

I kind of understood the first part of you answer regarding the resistor. I still need to understand the second one regarding the position of the LED, but i guess that's normal as i don't even know what vgs is. Actually i always see it in the absolute ratings section on every mosfet's datasheet.

Thanks again for your time. 

Well I picked up all sorts of useful things during my mechatronic engineering degree, but a lot of the time it's simply been a case of asking myself "what does this do?" or "how can I do this?", and then searching for the answer. Places like LMR, Wikipedia, and all the numerous electronics reference websites are great, not to mention that books are still useful once in a while =)
Probably the main thing is just trying to do something different with every project, which forces you to advance your skills if you want to complete it. Learning is a lot easier when you have a goal in mind.

Now, regarding MOSFET threshold voltages... N-channel MOSFETs like the one you have need positive voltage fed to the gate terminal to turn them on - this voltage is measured with respect to the source, and so it's usually labelled Vgs (voltage from gate to source). If Vgs is at least as high as the threshold voltage, then the MOSFET will turn on fully (this is the same as 'saturation', it's as on as it can be). If Vgs is below the off threshold (which might not be listed) then the MOSFET will be fully off. Anywhere in between the on and off threshold values causes the MOSFET to turn on partially, which is no good, as the MOSFET won't pass as much current as it would when fully on, but it tends to waste a lot of power like a poorly chosen resistor. For this reason MOSFETs are almost always operated at both ends of the scale, either fully on or fully off.

Your IRL540N has a nice low Vgs on-threshold of (at worst) 2V, so it's quite easy to turn on compared to many MOSFETs. The BC556 should drop less than 0.65V across the emitter-collector terminals, so when it turns on it delivers 5V - 0.65V = 4.35V to the gate of the MOSFET. If the MOSFET's source was connected to ground/0V, then the Vgs would be 4.35V, which is more than enough to turn on fully. However as soon as the MOSFET turns on the LED will drop a few volts across it, which means that the voltage at the MOSFET's source terminal must rise up to meet the LED voltage. Now that the source is no longer at 0V, the Vgs decreases by the amount of voltage dropped across the LED. In the case of your circuit, the LED would have to drop at least 2.35V before there was any chance of it affecting the MOSFET, but what if it does drop more than 2.35V? Or what if the supply voltage decreases? In either case the Vgs value may fall below the threshold, and the MOSFET will start acting up.

Fortunately in this case there's an easy solution, which is to move the LED above the MOSFET instead, which ties the source to ground permanently. Now the LED can drop up to almost 5V with no problems (if it wanted to), and secondly the source voltage can drop way down to something like 2.65V and the circuit will still work as expected.

Wow. Very very valuable information. Thank you very much. Now i know much more about MOSFETs than i knew before! 

Oh and btw i am also studying mechatronics, but i have just started it in september...i hope i'll learn things like these one day!

again..thank you! 

R1: 1K

R2: 1K

R3: 330

R4: 10K (not labelled, it is the one that connects collector to ground)

the MOSFET is logic-level and it's a IRL540N while the pnp is a bc556. 

oh btw. you said it's not a perfect solution. Why is that? Any idea to improve it?

For a super simple NOT gate, you can use one NPN transistor.


When the input from the micro is low, the transistor is off and the output is pulled high through the 10k resistor. When the input from the micro is high, the transistor is on and the output is grounded throug the transistor. 

That's what i also found surfing the net yesterday, but i didn't like the fact that current is wasted when pin is high. Even if very little. But besides that (current wasted would be very low), does this setup have any advantages if compared to the previous one?