0

I’m making microcontroller project in which I determine whether door is open or closed based on switch data.

If door is open, then switch 1 is triggered. (Output should be 5V)

If door is closed, then switch 2 is triggered. (Output should be 0V)

Is there a way to make this logic with electrical components only?

Best case would be to have 3rd scenario in which the output is 3V that would be triggered when neither switch is triggered.

toolic
  • 5,637
  • 5
  • 20
  • 33
krystof18
  • 167
  • 5
  • 1
    Yes. Make switch 1 connect the output to 5V. Make switch 2 connect the output to 0V. Make sure they don't both activate at the same time because it will blow a fuse or something (you didn't say what should happen if both switches are triggered). Add a voltage divider that keeps the output at 3V if neither is triggered. – user253751 Jul 13 '22 at 12:25
  • @user253751 It shouldn’t occur that both switches are triggered, but in case someone presses them both by hand, how can I prevent fuse from blowing? – krystof18 Jul 13 '22 at 12:27
  • by putting resistors in series with each switch and also changing the other resistors that make it 3V by default, you can make a voltage divider where the switches change the resistance, so when 1 is pressed it's *nearly* 5V, when 2 is pressed it's *nearly* 0V, when 1 and 2 are pressed, it's somewhere in the middle, and when neither is pressed it's somewhere else in the middle. – user253751 Jul 13 '22 at 12:29
  • this isn't really a logic circuit, anyway - you *have* switches that tell you whether the door is open or closed - switch 1 tells you if it's open, and switch 2 tells you if it's closed. – user253751 Jul 13 '22 at 12:36

1 Answers1

3

You can use the following circuit. You don't specify a load on your state output voltage so this expects a high-impedance load, like an MCU (Arduino) input pin.

R1 limits the current through the two switches if both switches are closed accidentally.

R2 and R3 deliver 3.012 V (approx. 3 V) when both switches are open. Note that the voltage's accuracy must consider the resistor tolerances, along with the 5 V supply rail tolerance which is beyond what your current question describes.

When SW1 is closed, R3 keeps its contacts current at 1 mA. When SW2 is closed, R2 keeps its contacts current at 1.5 mA.

If the output load needs more current, you can increase just the R2 and R3 values while keeping the ratio the same. The maximum load current available must be traded off against the continuous current drawn through R2 and R3.

schematic

simulate this circuit – Schematic created using CircuitLab

TonyM
  • 21,742
  • 4
  • 39
  • 62