I found a few good answers and guides about how to control a relay module from the pi, however, I want to find a way to check its state/status from the pi, is there a way to determine if the relay is currently on or off so I can update the app interface accordingly ?
I don't think I fully understand your question. Relays can either be on or off - depending on if the output to the relay module is high or low. So if you're controlling the relay from code, just keep a variable that tracks the state of the relay. for example, in python:
relayOn = False def turnRelayOn(): relayOn = True #turn on the relay def turnRelayOff(): relayOn = False #turn off the relay def printRelayState(): if relayOn: print("The relay is currently ON") else: print("The relay is currently OFF")
You could use a ready-made current sensor like this ready made module(or something similar) to measure the current between the output of the relay and your load. That current sensor uses a I2C interface, so it should be easy to connect to with the pi.
This is a great question because the actual relay state may differ from its nominal state. Feedback is critical, since actuators are physical objects that die over time. It is well worth the effort to add a way to sense the actual actuator state. For example, if the relay engages a pump, add a vibration sensor or sound sensor to determine if "everything is working as expected." Such a sensor will detect pump failure as well as relay failure. For robust system design, add a sensor for each actuator. Open loop systems (i.e., blind actuators) do work but are maddening when they fail (e.g., "We lost the entire crop because we thought the relay was on"). Simple actuators (e.g. light switch) can be exceptions because the operator can usually deduce their non-operation and repair as necessary.