Checking if a switch is open/closed, can I just use analog input to measure V?

Hi there,

I'm pretty much a noob to electronics, so I wanted to check on something quickly. I have a device with 2 reed switches on it, and the reed switch position indicates whether or not a gate on the inside is opened or closed. Basically, it has 4 wires coming out of it, 2 labeled open, 2 labeled closed. I've already checked, and if it's open I can measure the resistance along that path, same with the other.

Basically, I want to be able to check this state remotely with an arduino. My first instinct is to put the 5V power through a resistor, then send the open and closed paths from there in parallel with each other. I'd put the second open state wire on the board, then to ground and a second wire to an input, and just measure if I get any kind of signal, and do the same with the other (open) state.

Does this seem reasonable? Would the circuit require any other protection? Am I too vulnerable to noise to be able to properly read the signals? As a note I'm asking this to be sure it can be used for this purpose before I purchase the Arduino. There seem to be other topics, but they all look like they're dealing with things a bit trickier than just seeing if a small current can flow at all.

Thanks for any advice!

You should just be able to use digital pins for a reed switch.

Please sketch up your circuit and post it and we can review.

Hi, The two reed switches seem to close when the fgate is fully closed or fully open, is that right?

What is the situation when the gate is in between? What do you need to know and respond to?

Sorry for the delay in response.

The reason there is an open and closed switch is because there is a possibility it is somewhere else in between. The actual device is controlled by ~30 psi air, when it's going in one way it's open, the other way it's closed. If there is no air, then it's somewhere in between and not doing what I want it to. The air direction is controlled by a solenoid having current run through it (which in turn is controlled by a relay), but has already been solved and I know it's working.

The reason I don't just want to use the relay state to tell me if it's opened or closed is if there is a malfunction somewhere else. Say someone closes the air valve and I don't know, or something is wrong with it entirely. Having it tell me that it's not closed/open would instantly tell me to go look for the problem.

It actually being opened or closed has nothing else it sets off, at least at the moment. I just want to be able to confirm the state.

You have two reed switches, which have un-magnatized state of 'OPEN' (N.O.). So, when placed near a magnet, the reeds close, completing a circuit. same as a basic s.p.s.t switch.

Using the common configuration: +5V to a 10K resistor, other end of resistor to 1) an arduino digital pin set as input (with internal pull-up off), and 2) to one end of the reed switch, other end of the reed switch to ground.

When reed switch is not near a magnet, it is open, and the path from arduino pin to ground is open. thus thr resistor pulls the arduino pin's potential up to 5V. PIN IS IN HIGH STATE.

When reed switch comes close to magnet, it's reeds close, completing the circuit to ground, pulling the arduino'o pin to ground. PIN IS IN LOW STATE.

wire as above for gate open switch and for gate closed state on another pin.

write your code for the following truth table:

gate open gate closed gate condition
switch switch is
High High gate is open and in transistion (open to closed or closed to open, depending on
previous state
High Low gate is CLOSED
Low High Gate is OPEN
Low Low disastrous state, something is busted.

Ah I think I see why the digital pin works then. Does it just take any signal as High state? No signal is low? I assume there is a proper current (5v to 10K resistor), but is that the general idea?

And for the first person who commented yesterday, attached is what I had in mind. From my understanding now, I can basically just go a digital pin instead (making more logical sense anyway), assuming I use the correct resistor. Please let me know if I misunderstood, and more importantly thanks for all the help!

The IO pins have internal pullup resistors already, enabled with:
pinMode (pinX, INPUT_PULLUP);

Thus if your reed switch is wired with NO to the IO pin and COM to GND, the IO pin will read HIGH unless the switch closes and then it will read LOW:

if (digitalRead(pinX) == HIGH){
// switch is open code
else {
// switch is closed code


if (digitalRead(pinX) == LOW){
// switch is closed code
else {
// switch is open code