This is more a conceptual question than one about details, so for now ignore component values etc. I thought it would be interesting to build a small device that detects motion and at night, lights a bright LED. It would be located inside, but point out through a window to between two houses. Hence the use of the RCWL-0516 sensor and not a PIR sensor.
The circuit would also be connected to a microcontroller's pin to report motion to Home Assistant.
The drawn box identifies an RCWL-0516 sensor, which outputs a signal when it detects motion. I only need the LED to be lit when there's motion AND when the photoresistor's resistance is low when dark. Is this a valid use of two transistors to form an AND gate? Are there specific reasons why this is a bad idea or better alternatives?
TP identifies Test Points that you can add in CircuitJS to observe the voltage at that point.
Thanks
Conceptually yes. There's a lot missing in that circuit (resistors etc.)
But a NOR concept is in practice much easier to implement. It could come down to two diodes and a couple of resistors.
Transistor AND gate — this is what you want to achieve and conceptually it is right. However it has one issue. The
Rout resistor must be chosen well, as some voltage will appear on it even if the upper transistor is turned off. Albo both inputs, while low, must be close to 0V or the transistors may still turn on. That can’t be blindly assumed, as both low and high states are ranges of values, not ideal 0V and 3.3V.
There is also a
diode AND gate. It may be simpler to implement. In this case, though, you should pay attention to the ranges of high inputs.
In either case the output may require amplification with either a transistor in common-emmiter configuration or a buffer, inverter or a Schmitt trigger.
Depending on the values your LDR sees in light and dark, you may not need to treat it as a logic signal source at all, but use it as a pull-up/down resistor for the signal from RCWL-0516.
If you're already using a mcu, why don't just use it for that?
Use the ADC for the LDR, an input for the sensor, and depending on the LDR value, enable an output to drive the led for a specified amount of time. (You want it to be lit for some time, right? Not just a blink)
Otherways you'll enter the messy analog territory, requiring value tweaking for every little change.
Doing a precise comparator using transistor is much harder than just using an op-amp.
Just an example taking care of most stuff:
Thanks all. I know I could use a microcontroller but it'll be more fun to use components. A good way to learn some more basics. I develop code for a living so not developing is a nice change.
Why not simply use a logic IC? The 74HCT00 has four NAND gates, which can be used to make an AND and will work from 5V, with 3V logic inputs. AND gate ICs are also available, but I don't stock them, as they're not as versatile.
Why not simply use a logic IC? The 74HCT00 has four NAND gates, which can be used to make an AND and will work from 5V, with 3V logic inputs. AND gate ICs are also available, but I don't stock them, as they're not as versatile.
I will try that for sure - I think I have an AND gate IC, but not a NAND.
Why not simply use a logic IC? The 74HCT00 has four NAND gates
I doubt that a 74HCT00 will work well with an LDR. But that's just me...
Why not simply use a logic IC? The 74HCT00 has four NAND gates
I doubt that a 74HCT00 will work well with an LDR. But that's just me...
It's still better than the circuit attached to the original post. It can be improved by adding a few resistors to make the inputs Schmitt trigger, or use the 74AHCT132 .
'HC132 would certainly be a better idea.