Skip to content

Conversation

drf5n
Copy link

@drf5n drf5n commented May 1, 2023

Flesh out the logic of https://github.com/br3ttb/Arduino-PID-Library/blob/master/examples/PID_RelayOutput/PID_RelayOutput.ino to clearly accommodate both active-LOW and active-HIGH relays per #136

diff --git a/examples/PID_RelayOutput/PID_RelayOutput.ino b/examples/PID_RelayOutput/PID_RelayOutput.ino
index 17fbe1a..7c19203 100644
--- a/examples/PID_RelayOutput/PID_RelayOutput.ino
+++ b/examples/PID_RelayOutput/PID_RelayOutput.ino
@@ -18,6 +18,8 @@
 
 #define PIN_INPUT 0
 #define RELAY_PIN 6
+#define RELAY_ON LOW
+#define RELAY_OFF HIGH
 
 //Define Variables we'll be connecting to
 double Setpoint, Input, Output;
@@ -55,8 +57,14 @@ void loop()
   { //time to shift the Relay Window
     windowStartTime += WindowSize;
   }
-  if (Output < millis() - windowStartTime) digitalWrite(RELAY_PIN, HIGH);
-  else digitalWrite(RELAY_PIN, LOW);
+  if (Output > millis() - windowStartTime)
+  {
+    digitalWrite(RELAY_PIN, RELAY_ON);
+  }
+  else
+  {
+    digitalWrite(RELAY_PIN, RELAY_OFF);
+  }
 
 }

David R Forrest and others added 2 commits May 1, 2023 11:34
Set `pinMode(RELAY_PIN,OUTPUT)` since it is default configured as an INPUT.
@drf5n drf5n changed the title Add RELAY_ON /RELAY_OFF per https://github.com/br3ttb/Arduino-PID-Lib… Set pinMode(RELAY_PIN,OUTPUT) & add RELAY_ON /RELAY_OFF per https://github.com/br3ttb/Arduino-PID-Lib… Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant