Hi
I am using the attached relays which I think are logic low.
[https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/5773/TS0010D%20DATASHEET.pdf]
I think this is causing my relays to switch opposite to how the code is written.
The below code bring the relays on when LOW and OFF when HIGH.
Is there a fix for this within the code so when I use "digitalWrite(11, HIGH) the relay is activated.
int relay_1 = 9;
int relay_2 = 10;
int relay_3 = 11;
int relay_4 = 12;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(relay_1, OUTPUT);
pinMode(relay_2, OUTPUT);
pinMode(relay_3, OUTPUT);
pinMode(relay_4, OUTPUT);
}
void loop() {
digitalWrite(relay_1, HIGH);
digitalWrite(relay_2, HIGH);
digitalWrite(relay_3, HIGH);
digitalWrite(relay_4, HIGH);
Serial.println("All relays ON");
delay(3000);
digitalWrite(relay_1, LOW);
digitalWrite(relay_2, LOW);
digitalWrite(relay_3, LOW);
digitalWrite(relay_4, LOW);
Serial.println("All relays OFF ");
delay(3000);
}
Nothing is the opposite way round. Writing LOW turns the relay on. Get over it
You cannot write HIGH to the relay and have the relay turn on. You could, if you wanted to, #define ON as LOW and OFF as HIGH then write ON or OFF to the relay but it would still actually be writing LOW to turn the relay on
I am surprised that if you are triggered by a relay being on when its input is LOW then I am surprised that you find this acceptable
while (digitalRead(azLimitSwitchPin) == HIGH)
Meanwhile, back at the relay, as it is a Double Throw switch, you could use the common and normally closed contacts to switch whatever it is controlling and then writing HIGH would turn off the relay and close the contacts
This whole thing has confused the hell out of me over the last few days. Had me changing code and getting in a mess. I didn't realise why the relays were working opposite. think I have got my head around the limit switch side being LOW when closed and HIGH when open.
Using the "define" makes it easier to follow as the program gets longer.
It all seems to work well now. Just need to write the code to move the "Elevation" ram.
Thanks for your help.