2 Reed switches schematic

Is the following schematic correct? My previous circuit had the reed switches on the grounding side but I was not able to get a reliable signal.reed setup

No your two input pins are floating (not HIGH or LOW) when the switches are open.

Your schematic is not corretct.
But I didn’t quite understand what you need to do.
When operating the reed switch do you want the arduino inputs to be connected to + 5V or to the ground?

RV mineirin

You don’t need the unknown resistor, connect one side of the reed switches to 5V, connect the other side of each to an input pin, connect a 10k pulldown resistor from each input pin to GND.
Best (and easiest) way: Connect one side of the reed switches to GND, connect the other side of each to an input pin, in setup() set the input pins to pinMode(pin, INPUT_PULLUP), the pin will be LOW when the switch is ON and HIGH when OFF.

void setup()
{
   pinmode(2,INPUT_PULLUP);
   pinmode(3,INPUT_PULLUP);

When the magnetic is over the switch, I want it to read 5V. What would the circuit look like?

So you want to do it the nooby backwards way :slightly_smiling_face: use the first example with pulldown resistors to keep the pins from “floating” between 0 and 5 volts.

You add a resistor between the pin and GND so you read LOW when the switch is open. And you connect the other side of the switch to 5V to read HIGH when the switch is closed by the magnet.

In Case 1, the ports must be defined with “pinMode INPUT”.
With open reed switches, read 0, with closed reed switches read 1.
Uses 3 resistors and 2 external diodes.

In Case 2, the ports must be defined with “pinMode INPUT”.
With open reed switches, read 0, with closed reed switches read 1.
Uses 4 external resistors.

In the Best case the ports must be defined with “pinMode INPUT_PULLUP”.
With open reed switches, read 1, with closed reed switches read 0.
No external components are needed.


RV mineirin

1 Like

Pullup and pulldown resistors are fundamental to proper operation of digital inputs.
CMOS logic is a good place to find that out.
Without a defined state on inputs, CMOS logic chips can start using a lot more power and generally don’t work very well.
Defining the state of an input is as fundamental as adding decoupling capacitors to devices.
If you really need to change the sense (HIGH/LOW) of an input, use an inverter like a simple transistor or a 4049 CMOS chip as a front end which gives you all the options you need as well as cleaning up noisy signals.

Case 2 would work, remove or short the 10K resistors, so one end of the switch would be connected to 5V.