Relay and sensor, need some advice

Hi guys,

I got stuck with sensor and relay situation.
I am using two sensors. Using digital INPUT for everything.
What I am trying to do - engage digital pin 5 and 6 for 2 relays when sensor reading = HIGH; engage digital pin 5 and 7 when sensor reading = high.
Somehow I can get only one or the other sensor and relays doing what I want. But when I use both, its not working.

It looks like relay trying to engage but not doing it. I attached video. I checked voltage on usb - its 5v.

so relay 5 and 7 are working together now but 5 and 6 not working together, only 6 gets engaged.

here is code -

int sensor_pin =2;
int sensor2_pin=4;
int relay5 = 3;
int relay6 = 6;
int relay7 = 11;
volatile byte relayState = LOW;
void setup() {
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);

pinMode(sensor_pin, INPUT);
pinMode(sensor2_pin, INPUT);

}
void loop() {

if(digitalRead(sensor_pin) == HIGH){
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);

} else {

digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
}

if(digitalRead(sensor2_pin) == HIGH){

digitalWrite(relay5, LOW);
digitalWrite(relay7, LOW);
} else {

digitalWrite(relay5, HIGH);
digitalWrite(relay7, HIGH);
}

delay(1000);

}

relay_mpg.mpg (281 KB)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.