MOSFET ON when it should be off-OFF when it should be on?

I put these two circuits together to make a night light (but I only use 2 phototransistors). I’m using both IRLB8271PbF and 30N06 n-channel MOSFETs to try.

The 12V LED (lamp) has its own power source; the op amp works off USB 5v.

As in the video
(night light.mp4 - Google Drive),

when there is ambient light, the standard red LED turns OFF, but the MOSFET turns the 12V LED ON, and vice-versa. Both MOSFETs act the same, so I know they’re good, but they’re working backwards (right?).

Been searching a lot for answers, but I don’t understand it. Is this circuit behaving as it should or have I done something wrong? If it’s working as it should, how can I reverse the MOSFET behavior to ‘close’ the switch when the op amp outputs HIGH?

I am sharing the op amp output with the red LED and MOSFET, which, I assume, is bad practice, but the behavior doesn’t change with the red LED removed.

night light.png

circuit.JPG

Mosfet Lamp.jpg

On first reading I can't see what you have done wrong. I would put a 10K pull down resistor on the gate of the FET though, although lack of this should not result in what you see.

It would be good if you could post all the schematic of what you actually have instead of just pieces of it and notes saying some bits are missing. Also a few more pixels in your tiny photograph might actually show something.

Missing from the original circuits are two phototransistors and the transistor from the MOSFET circuit, replaced with the phototransistors/op amp circuit (741).

The photo is much better thanks.

But isn't

Missing from the original circuits are two phototransistors and the transistor from the MOSFET circuit, replaced with the phototransistors/op amp circuit (741).

just

instead of just pieces of it and notes saying some bits are missing.

Also you seem to have a pull down resistor in the gate that does not appear on any diagram? Also there seems to be a signal diode going somewhere.

These things might sound petty, but a clear schematic is an essential tool to convey information about a circuit.

I'll get a schematic together. I added resisters all over based on every different MOSFET circuit i could find. Still, the MOSFET's working backwards, right? The diode sits across the 12v LED panel.

What would make a MOSFET act like this?

The output of the opamp goes LOW when dark, so 12volt falls across the LED/resistor, and turns the LED on.

You added a mosfet, which expects the opposite (HIGH wen dark).

Just swap the photo transistors and the pull up resistor (R1 in the opamp diagram).
So photo transistor between supply and -input, and resistor between -input and ground.

The 10k:10k divider sets switchpoint.
Changing ratio makes it come on with more or less ambient light.
Leo..

thank you.

So why does the red LED turn on when the MOSFET turns off?

Wow, where did you find that 741 dinosaur.
A 12volt supply is ok for that opamp, but 5volt...
A non logic level IRF530 mosfet also doesn't like the maybe ~3volt volt gate drive coming from that opamp.
That circuit really needs to be powered with 12volt.

When the +input of an opamp is higher than the -input, then the output is high.
When it's dark, the photo transistors do not conduct, so R1 pulls the -input to the supply.
The -input is thus higher than the +input, resulting in a low on the opamp's output (not what you want).
As said, swap R1 and the photo transistors, so the -input is low when it's dark.
Leo..

First off, how would anybody with my lack of experience know that a 741 is any better or worse than any other?
2nd, thank you for clarifying everything.
3rd, where are resistors necessary here? I know what they do, in general, although putting them where, and with what values is beyond my math skills.

Thanks for the full diagram, as you see that made it clear,

First off, how would anybody with my lack of experience know that a 741 is any better or worse than any other?

By reading the data sheet of the component you are going to use. That will tell you the minimum and maximum power supply needed.

Your bits of diagram did not show the 741 connected to 5V, in fact the one with the 741 showed a 12V supply, which is why I didn’t pick that up.

That diode in the gate pull down is not needed. The resistors values look OK although they are not too critical in that circuit.

Putting 12v everywhere and switching as you directed fixed it all.

I was thrown with the led going to positive, not negative. It's the simple things...

Thanks again

I was thrown with the led going to positive, not negative.

When the LED is connected to the positive and an output, the output is said to be sinking current.

When the LED is connected to the negitave and an output, the output is said to be sourcing current.

To turn the LED on the output needs to be low when sinking current and high when sourcing current.

In the Arduino world you almost always see current sourcing, but in the rest of the world it is sinking that is most common. This is because a lot of the time the current rating of an output for sinking, is more than for sourcing.