Using two transistors as an AND gate for a motion sensor and a photoresistor? - Page 1
Forum section: electronics / beginners

author: YurkshireLad
author_rank: Frequent Contributor
timestamp: March 16, 2022, 10:33:58 pm
content: 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

author: Benta
author_rank: Super Contributor
timestamp: March 16, 2022, 11:10:46 pm
content: 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.

author: golden_labels
author_rank: Super Contributor
timestamp: March 16, 2022, 11:46:36 pm
content: Transistor AND gate— this is what you want to achieve and conceptually it is right. However it has one issue. TheRoutresistor 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 adiode 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.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 17, 2022, 06:13:21 am
content: 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:

author: YurkshireLad
author_rank: Frequent Contributor
timestamp: March 17, 2022, 04:59:53 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: March 17, 2022, 05:51:15 pm
content: 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.

author: YurkshireLad
author_rank: Frequent Contributor
timestamp: March 17, 2022, 06:03:56 pm
content: Quote from: Zero999 on March 17, 2022, 05:51:15 pmI will try that for sure - I think I have an AND gate IC, but not a NAND.

author: Benta
author_rank: Super Contributor
timestamp: March 17, 2022, 09:05:21 pm
content: Quote from: Zero999 on March 17, 2022, 05:51:15 pmI doubt that a 74HCT00 will work well with an LDR. But that's just me...

author: Zero999
author_rank: Super Contributor
timestamp: March 17, 2022, 10:12:04 pm
content: Quote from: Benta on March 17, 2022, 09:05:21 pmIt'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 .

author: Benta
author_rank: Super Contributor
timestamp: March 17, 2022, 10:46:39 pm
content: 'HC132 would certainly be a better idea.