jartioli
Posts: 1
Joined: Sat Mar 21, 2020 2:35 am

Get state of a relay

Sat Mar 21, 2020 2:51 am

I am on my first Raspberry PI project and am using a PI 4B with an 8 relay board.

I've created a web page in HTML/javascript/php that has 8 push buttons on it. I am leveraging an IndexedDB solution to store the state of the relay on or off associated with the button clicked via coding and current value in the database. So when the button is clicked, I check the database value of the relay state (on or off) associated with that button in the database, then the code sends the relay to flip to the opposite and store the new state of the relay in the database.

While this works to an extent - is there a way to capture via code the current state a particular relay is in on or off?

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Get state of a relay

Sat Mar 21, 2020 5:01 am

When a GPIO pin is set to output, reading its value (as if it was an input) will give you the current state.
Unreadable squiggle

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Get state of a relay

Sat Mar 21, 2020 3:41 pm

Knowing the state of the signal switching a relay
Can only be verified knowing if the relay contacts
Have parted , so this must be in the loop. If the
System was controlling a industrial application
It must be designed fail to safe not just relieing
On Code, In some cases relay contacts can be
Sticking or burnt , Isolation must be in open loop
And not in closed loop

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Return to “Beginners”