logo elektroda
logo elektroda
X
logo elektroda

Detection of 12V relay status via GPIO - I am looking for a method without using the D1 mechanism

faber 1452 13
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19014759
    faber
    Level 24  
    Posts: 701
    Help: 49
    Rate: 36
    Board Language: polish
    With this arrangement (only the relay will be on 12V and not 5V):
    Detection of 12V relay status via GPIO - I am looking for a method without using the D1 mechanism .
    I am looking for the best way to detect if the relay is switched on. I don't want to do this through the D1 relay switching mechanism because the relay can also be switched on by another circuit (not ESP). How on another GPIO can I detect if the relay is switched on ?
  • ADVERTISEMENT
  • #2 19014772
    Anonymous
    Level 1  
  • #3 19014779
    jozgo
    Level 42  
    Posts: 7248
    Help: 1010
    Rate: 1303
    Board Language: polish
    faber wrote:
    I am looking for the best way to detect if the relay is switched on.
    .
    Its contacts are from signalling this state.
    I don't understand the question.
    In contactors there are auxiliary contacts for this, and here every contact not used for switching the circuit in question.
  • ADVERTISEMENT
  • #4 19014785
    bumble
    Level 40  
    Posts: 7189
    Help: 608
    Rate: 1183
    Board Language: polish
    It has to be from the contacts to be sure it has switched on.
  • ADVERTISEMENT
  • #5 19014810
    faber
    Level 24  
    Posts: 701
    Help: 49
    Rate: 36
    Board Language: polish
    Hm... well, there is 230V on the contacts. And isn't there some way to e.g. detect the 12V flow of the relay coil ?
  • ADVERTISEMENT
  • #6 19014816
    Anonymous
    Level 1  
  • #7 19014824
    faber
    Level 24  
    Posts: 701
    Help: 49
    Rate: 36
    Board Language: polish
    jozgo wrote:
    faber wrote:
    I am looking for the best way to detect if the relay is switched on.
    .
    Its contacts are from signalling this state.
    I don't understand the question.
    In contactors there are auxiliary contacts for this, and here every contact is not used for switching a circuit.

    the point is that I plan to plug in another circuit where the relay has no other auxiliary contacts.
  • #8 19014825
    jozgo
    Level 42  
    Posts: 7248
    Help: 1010
    Rate: 1303
    Board Language: polish
    faber wrote:
    Hm.... well there is 230V on the contacts
    .
    After all, not on all of them.
    A relay is an electromechanical apparatus.
    It is also a mechanism. The only certain information about its switching is the state of the contacts. It means that the jumper has been tightened to the core.

    Added after 4 [minutes]: .

    faber wrote:
    Hm.... well there is 230V on the contacts
    .
    Well that's right. And if it is switched on there will be zero on the switched contact. Do you have the information?
  • #9 19014857
    faber
    Level 24  
    Posts: 701
    Help: 49
    Rate: 36
    Board Language: polish
    khoam wrote:
    faber wrote:
    As there is no way to e.g. detect the 12V flow of the relay coil ?
    .
    This will 100% not mean that the contacts have switched on or off.
    .
    And would it be possible to do so after all ? :) i.e. this monitoring of the state of the relay is not sensitive, just by the way of changes I wanted to know, but it is not a function on which something will depend, just monitoring, I would not like to simply interfere with the 230V circuit
  • Helpful post
    #10 19014862
    jozgo
    Level 42  
    Posts: 7248
    Help: 1010
    Rate: 1303
    Board Language: polish
    faber wrote:
    As it would be possible after all ?
    .
    Collector voltage. If it is close to zero, i.e. the full voltage of 12 V is on the coil of the relay.
    With a circuit with e.g. a zener diode and a resistor you can lower it to e.g. 5 V.
    It will be a negative signal.
  • #11 19014867
    Anonymous
    Level 1  
  • #12 19014920
    jozgo
    Level 42  
    Posts: 7248
    Help: 1010
    Rate: 1303
    Board Language: polish
    For separation, you can insert an optocoupler.
  • #13 19015042
    krzysiek_krm
    Level 40  
    Posts: 4612
    Help: 716
    Rate: 598
    Board Language: polish
    faber wrote:
    no at the contacts is 230V
    .
    It is possible to detect this voltage (230V), for example with a brazenly copied mains zero detection circuit.
  • #14 19019675
    krzbor
    Level 29  
    Posts: 1731
    Help: 40
    Rate: 1044
    Board Language: polish
    If no separation is needed (i.e. we have a common ground) then it is best to connect the cathode of the diode to the collector, a 10k resistor to the anode and the other end of the resistor to supply the ESP (3.3V). To the anode we connect the free I/O. The signal will be in negation.

Topic summary

✨ The discussion revolves around detecting the status of a 12V relay using GPIO without relying on the D1 relay switching mechanism, as the relay may be activated by other circuits. Participants suggest various methods for monitoring the relay's state, emphasizing the importance of using the relay's contacts for accurate detection. Suggestions include using a zener diode and resistor to lower the voltage to 3.3V for the ESP, and employing an optocoupler for isolation. The conversation also touches on the challenges of working with high voltage (230V) circuits and the need for safe monitoring solutions.
Generated by the language model.

FAQ

TL;DR: Want ESP8266/ESP32 to know if a 12 V relay switched? Sense the driver’s collector with a 10 kΩ pull‑up to 3.3 V; "The signal will be in negation." [Elektroda, krzbor, post #19019675]

Why it matters: You need a reliable GPIO read even when another circuit drives the same relay; this FAQ is for ESP8266/ESP32 makers wanting safe, accurate relay state monitoring.

Quick Facts

How can I reliably detect if my 12 V relay actually switched?

Sense the relay’s contacts, not just the coil or drive signal. Any unused contact can serve as a status output. As one expert put it, "The only certain information about its switching is the state of the contacts." This directly reflects mechanical closure. [Elektroda, jozgo, post #19014825]

Can I just monitor the 12 V coil to know the relay status?

No. Coil voltage or current does not guarantee contact movement. Edge case: the coil can energize while the contacts fail to change state. As noted, "This will 100% not mean that the contacts have switched on or off." Rely on contacts or a properly derived sense node. [Elektroda, khoam, post #19014816]

Whats the easiest way to read relay status on ESP8266/ESP32 without touching 230 V?

Tap the relay drivers collector node and pull it up to 3.3 V through ~10 ka. Feed that node to a free GPIO. This works when the ESP and relay driver share ground and provides a clean logic signal. Note the signal is inverted relative to coil power. [Elektroda, krzbor, post #19019675]

How do I wire the collector-sense method to an ESP GPIO?

  1. Ensure common ground between the relay driver and ESP supply.
  2. Add a 10 ka resistor from the flyback diodes anode node (collector side) to 3.3 V.
  3. Connect that same anode node to a free ESP GPIO; expect inverted logic. [Elektroda, krzbor, post #19019675]

Is the collector-sense logic inverted?

Yes. When the coil is energized, the collector node goes low, so the GPIO reads low. When the coil is off, the pull‑up drives the node high. "The signal will be in negation." Adjust your firmware logic accordingly. [Elektroda, krzbor, post #19019675]

Do I need galvanic isolation for relay status sensing?

Use an optocoupler if you need isolation between the relay circuit and the ESP. It protects the MCU from transients and different ground potentials. As advised, "For separation, you can insert an optocoupler." This is preferred in noisy or high‑voltage environments. [Elektroda, jozgo, post #19014920]

How can I detect 230 V on the relay contacts safely?

Use a mains zero‑cross detector or similar high‑impedance sensing circuit. This indicates whether 230 V is present on the switched contact without loading the line. It avoids relying on coil status and directly measures the AC side condition. [Elektroda, krzysiek_krm, post #19015042]

Which ESP8266/ESP32 pins can I use as inputs for status sensing?

Use any GPIO that supports input mode on your ESP8266 or ESP32. Choose pins that fit your boards boot requirements and your firmware design. Refer to a pinout guide for selection details. [Elektroda, khoam, post #19014772]

Can I drop a higher node voltage to a logic-level input with a zener + resistor?

Yes. A simple zener diode with a series resistor can clamp the sense node to a lower voltage. For example, down to about 5 V at the node, yielding an inverted signal referenced to the driver. This helps protect the input stage. [Elektroda, jozgo, post #19014862]

What voltage should an ESP GPIO see as HIGH?

Target 3.3 V logic levels for ESP8266/ESP32 inputs. As noted, "Specifically to 3V3, as this is the ESP." Avoid 5 V direct connections without proper level shifting or clamping. This protects the microcontroller inputs. [Elektroda, khoam, post #19014867]

Can I reuse an unused relay contact purely for feedback?

Yes. Any contact not used to switch the load can serve as a feedback signal path. Wire it to a suitable low‑voltage sensing circuit or isolation stage, then into a GPIO. This mirrors industrial auxiliary contact practice. [Elektroda, jozgo, post #19014779]

Why not read the D1 drive signal if another circuit also switches the relay?

Because the control signal you drive wont reflect external activations. As the OP states, "the relay can also be switched on by another circuit (not ESP)." You need contact sensing or a shared node that changes for all drivers. [Elektroda, faber, post #19014759]

Will a 10 ka pull-up work for collector sensing, or should I pick another value?

10 ka to the ESPs 3.3 V rail works well for this method. It limits current, keeps the node stable, and produces the expected inverted logic. This value is commonly suggested for the collector‑sense technique described. [Elektroda, krzbor, post #19019675]
Generated by the language model.
ADVERTISEMENT