Diode Logic AND Gate Issue

I am trying to make a system using a PIR sensor and Light sensor. The Light sensor outputs HIGH (1) when it is dark otherwise LOW (0). The PIR sensor outputs HIGH (1) when it senses any motion. I want to AND their digital outputs to turn on an LED when there is dark and motion is detected, so both of the sensors should output HIGH (1) to turn on the LED. It is a simple AND logic. I have diodes and resistors so I wanted to make a Diode Logic AND gate. The problem is when there is dark so Light sensor outputs HIGH (1) but there is no motion so PIR sensor outputs LOW (0) but the LED turns on. If I connects the inputs to the diode using the power supply positive and ground terminals directly (without sensors) the AND logic works perfectly. I have checked the voltage at PIR input when there is no motion ( and no dark), it is usually near 0V but when there is dark and no motion the voltage of the PIR sensor is near 1.36V which could be the cause of the issue but I am not sure. The PIR and Light sensors are powered using the same power supply as the circuit that is Arduino Uno 5V and GND. Please see the attached schematics.

whilst it's limited by the diode and R1, can your PIR and LIGHT sensors' output pin sink current when they are LOW ?

I have no idea if they can sink current since they are sensor modules and they may have amplifier or comparators. What are the workarounds if they can't sink?

I think for an AND gate they should be reversed, right?

Maybe. You can measure all involved voltages and find the guilty one.

HIGH and LOW can be different for each sensor. A diode can not increase or decrease these levels by more than 0.6V. Your circuit is okay in general but not with the voltages and currents supplied and consumed by the various components.

A sensor can be damaged by a too high voltage (5V) on its output.

Hello yokonav

Take a view here to gain the knowledge.

I think you are right. I see the sensors HIGH is near 3.2V so I guess internally they are converted. I switched the power input voltage from 5V to 3.3V. But it does not solve the problem.

Test them!

Connect led+series resistor from 5V to the output pin. If it lights when the output is LOW, it can sink current. Connect led+series resistor from the output to ground. If it lights when the output is HIGH, it can source current.

You will need both sensors to be able to sink current in order for your diode and-gate to work. You don't need them to be able to source current.

hum - that's the typical diode based AND gate (the pull-up is usually higher)

OK, thanks for letting me know the easy testing method. Both of them can sink the current. The LED turns on when input is LOW with 1.8 V and 1.7 V across LED for the Light and PIR sensors respectively, though LED seems a bit dimmer for the PIR.

Ok maybe you can explain what is the difference between LOW (1) and LOW (0)

When I connect the sensors to Arduino Uno the Light sensor outputs 1 (Logic High) in the dark otherwise 0 (Logic Low) and the PIR sensor outputs 1 when there is any motion otherwise 0. I know Low/High are just relative terms but the sensors are active HIGH in this context.

EDIT: I have fixed the typo in the original post.

The Arduino inputs are very high impedance which means that if the sensor outputs can only source or sink a tiny current, the Arduino pin can still read them correctly.

But your diode and-gate's inputs are low impedance, which means the sensor outputs need to source or sink quite a large current, or the gate will not work. Perhaps that is the problem here.

Perhaps you should consider using a logic chip like 74hc00. A transistor and-gate is another possibility.

I thought your comment was on the circuit - my bad

I think the problem is with the forward voltage drop and source resistance that increases the low voltage level. Not sure if Schottky diodes would help or should I pull down the inputs. I agree that logic chip like 74hc00 would be a lot easier. Anyway I learned many things by trying this out.

My comment was on the circuit. I have reread what OP wrote and I am even more confused about what is the desired output of this circuit. So ignore my comment.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.