I have been having problems trying to run multi sensor code for my project, this requires four KY-024 Linear magnetic Hall sensors as position sensors that trigger NC independent relays to make a circuit. I can get the code to run on one independent circuit, one hall switch one relay with no problems. But when I try the code for 4 hall sensors + relays I get no response from the circuit at this point I am at a loss where to go from here the code compiled with no problems.
int hallswitch = 1;
int val = 0;
int RELAY1 = 6;
void setup() {
pinMode(hallswitch, INPUT);
pinMode(RELAY1, OUTPUT);
}
void loop() {
val = digitalRead(hallswitch);
if (val == HIGH) {
digitalWrite(RELAY1, HIGH);
}
else {
digitalWrite(RELAY1, LOW);
}
}
and
int hallswitch1 = 1; //Pin for Hall switch
int hallswitch2 = 2; //Pin for Hall switch
int hallswitch3 = 4; //Pin for Hall switch
int hallswitch4 = 5; //Pin for Hall switch
int val = 0; //Integer for reading Hall statu
int RELAY1 = 6; // The socket number on the Arduino that the relay1 will go to.
int RELAY2 = 7; // The socket number on the Arduino that the relay1 will go to.
int RELAY3 = 8; // The socket number on the Arduino that the relay1 will go to.
int RELAY4 = 9; // The socket number on the Arduino that the relay1 will go to.
void setup()
{
pinMode(hallswitch1, INPUT);
pinMode (RELAY1, OUTPUT);
pinMode(hallswitch2, INPUT);
pinMode (RELAY2, OUTPUT);
pinMode(hallswitch3, INPUT);
pinMode (RELAY3, OUTPUT);
pinMode(hallswitch4, INPUT);
pinMode (RELAY4, OUTPUT);
}
void loop() {
val = digitalRead(hallswitch1); //Read Hall pin status
val = digitalRead(hallswitch2); //Read Hall pin status
val = digitalRead(hallswitch3); //Read Hall pin status
val = digitalRead(hallswitch4); //Read Hall pin status
if (val == HIGH) { //If there is a magnet infront of Hall switch...
digitalWrite(RELAY1, HIGH); // Turn RELAY1 on:
digitalWrite(RELAY2, HIGH);
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, HIGH);
}
else {
digitalWrite(RELAY1, LOW); // Turn RELAY1 off:
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, LOW);
}
}