Author Topic: Using two transistors as an AND gate for a motion sensor and a photoresistor?  (Read 966 times)

0 Members and 1 Guest are viewing this topic.

Offline YurkshireLadTopic starter

  • Frequent Contributor
  • **
  • Posts: 365
  • Country: ca
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
« Last Edit: March 16, 2022, 10:37:53 pm by YurkshireLad »
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5880
  • Country: de
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.

 

Online golden_labels

  • Super Contributor
  • ***
  • Posts: 1212
  • Country: pl
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.
« Last Edit: March 16, 2022, 11:48:42 pm by golden_labels »
People imagine AI as T1000. What we got so far is glorified T9.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5914
  • Country: es
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:
« Last Edit: March 17, 2022, 06:15:03 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline YurkshireLadTopic starter

  • Frequent Contributor
  • **
  • Posts: 365
  • Country: ca
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.  :)
 
The following users thanked this post: Tom45

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19536
  • Country: gb
  • 0999
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.
 

Offline YurkshireLadTopic starter

  • Frequent Contributor
  • **
  • Posts: 365
  • Country: ca
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.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5880
  • Country: de
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...
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19536
  • Country: gb
  • 0999
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 .
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5880
  • Country: de
'HC132 would certainly be a better idea.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf