Check status of a relay without a shield?

Hi,

I’m looking at using a relay to power a plug socket, but I’m wondering if there’s a way for me to pullup the current status of the pin so it can be a simple toggle.

I.e. if it’s already HIGH, set LOW… and if LOW, set HIGH.

I can’t find anything in the documentation about reading the current status of an OUTPUT pin. Is there a neat way to do it?

Cheers

Tim

You could use an intermediate variable.
Then in the loop() you assign the variable value to the pin.
In this way, you can read the variable status whenever you want.

You can digitalRead() an OUTPUT pin too.

Just try this

void setup() {
  pinMode(D7, OUTPUT);
}

void loop() {
  digitalWrite(D7, !digitalRead(D7));
  delay(500);
}
2 Likes

Awesome! Thanks @ScruffR!!