Detect relay state

I have a circuit that controls a relay. Its always closed but periodically, the relay will open and then close again. I can’t change anything on that existing circuit, so all I can use it that relay. Nothing else is plugged into the load side of the relay

If I use this method, and instead of the switch use the relay, will I be able to detect the relay opening and closing again?


It’s a little unclear, are you controlling the relay with the Arduino?

If not, is there an unused set of contacts on the relay ? if yes, that could ‘replace’ a switch…
If the contacts are already in use, we need more information about what’s being switched, and what’s controlling the relay.

It’s possible to ‘test’ the coil voltage to determine if the relay is energised or not… tell us more. Maybe a block/circuit diagram…?


No the arduino is not controlling the relay. The relay is part of a turnstile system. All I want is detect when someone goes through the turnstile. When the turnstile is turned on, the relay closes. When someone walks through the turnstile the relay opens and then closes again.

There are 2 wires at the moment that go to the old system that monitors the turnstile but the wires will be disconnected so I can connect the arduino to the relay.

The graphic above is what I was thinking of doing

Not sure about the coil voltage. would that be important even though the arduino would never get in contact with the coil voltage?

The current system simply sends a 24V signal which drops to about 21V I guess because of the length of wire. The current system monitors about 30 turnsiles. I was thinking to place 1 arduino per block of turnstiles which is between 5 or 6 right next to each other. That way I wouldn’t need to worry about the voltage drop

You’ve done well, so it looks like the contacts are clear - they were used previously by the ‘old’ controller, being replaced by the Arduino.

You’re good to go - using the contacts in place of a switch, because no external voltage will be applied to the Arduino.
Use INPUT_PULLUP, switch to 0V, and make sure to debounce the contacts to avoid mis-triggering / counting.

Give it your best shot - maybe use a simple switch on the workbench to test your ideas, then you can move across to the turnstile when it works!

If possible, try not to use delay() for your timing…meet used to millis()

Good luck !


Can I use INPUT_PULLUP on all digital pins?

To review…
The turnstile energizes and re-energize the coil of the relay.
The extant system monitors the contact side of the relay.

The intent is to replace the existing monitor with an arduino.

A simple AC opto-isolator can make that work

Thanks for the suggestion. I have not a lot of experience with arduinos or electonics. I nerver even heard of opto-isolators. So if the relay will work I would prefer going down that route.

For all ATmegaxx8 and I imagine all ATmegaUxx processors, yes, including most “analog” pins which are in fact, digital pins with additional analog reading functionality.

This leads me to believe underfloor conduit will be involved.  If so, what other wiring is in the conduit?  How long is the longest run?

No conduit at all. At the moment there is one central system that connects to all turnstiles. I am trying to replace the system with 7 arduinos. They will be located directly at the turnstiles and each will monitor between 3 and 6 turnstiles. I am going to use uno’s with ethernet shield. The arduino will then send a http request to a server ( in the same building ) every time the turnstile has been activated by simply submitting the turnstile ID. That ID will then be stored in a database along with date and time so that that we can display total numbers and also flowrates.
hope that makes sense.

Do you let children play with the turnstiles? What is the purpose of the turnstiles?

The Turnstiles are in a football ( or soccer depending on where you life ) stadium. There are 7 groups of turnstiles ( 30 turnstiles in total ). Its not a massive stadium, about 15000 seats in total. The arduinos are replacing an old broken system.

Plan is to store all turnstile movements in a mysql database and then we will have a number of different screens that show different stats.

Then the project looks like a good one for Arduino use. Be sure to debounce the relay contact closures.

Can you give more information on “connects to all turnstiles” ?

If there is a central place that connects to all turnstiles. That might be the best place to start.

Yes at the moment there is a central place where they meet. But the stadium is big and you get voltage drops. So I am going to place an arduino on each group of turnstiles ( anywhere between 3 and 6 turnstiles.
The relay is already there, there is power and ethernet ports. So I thought best to have each group of turnstiles watched by a different arduino. If something goes wrong with the arduino, at least the other groups are still working. Also I would think that 30 turnstiles for 1 arduino would be too much. Each time a turnstile is turned, a signal needs to be sent and stored in a db. But I would think 3-6 are manageable.

I created a test setup and got the code ready for checking to see if the relay is open or closed. Just need to add the http request bit now.

In setups like that, it may be easier to use what is effectively a ‘current loop’ rather than a simple switched voltage.

You can get much longer runs for a simple switch closure. Not much speed, but virtually no extra components.

the OP said there are Eithernet ports at the turnstile.
that would indicate to me the installation is less than 30 years old and since there was some form of monitor, I would venture to guess that the original installation had offered a count of attendees.

also, if you have eithernet, it does not make sense to run wires from individual turnstiles back to a central monitor, but just send the data in serial.

it would be interesting to see photos of a turnstile, but the the eithernet is there, using that does seem like the easiest way.

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