I have 24V switch, ON=24V, Off=0V. i want to connect this to my particle, using digital input D1 in the electron which can handle up to 3.3V if i am right, so what is the best way to conncet this 24V to my electron to detect when its High and when its low,
I used relay, but i am looking for alternative solution “smaller and easy to implement”.
Optocouplers, voltage dividers, op-amps, transistors… Plenty of options to choose from. A quick Google can tell you more than we could in the same timeframe.
All of the above are valid, and depending on the application you’re intending to use them for, they could all work. Price/size/complexity could then make the difference, which we can’t determine for you.
Is the 24V “switch” and actual switch that you flip or is it a relay? If it is a relay then there should be a smaller voltage flipping it. I had to do something similar only it ended up being a 240V relay, you tap into the two lower voltage wires and then can determine when they are connected or not (on or off).
If the load is inductive, I’d vote for Opto Isolation for protection.
Something like This is a starting point for searching. They are very easy to implement.
Since it’s inductive load, I wouldn’t use a voltage divider from resistors to monitor the 24V side unless the Relay has an induction suppression capacitor and you have confirmed there are no voltage spikes during switching (hard to accomplish).
If your goal is to replace the flip switch with something the Electron can control, then you want to look at Opto Isolated Relay. Look Here for ideas.