Go Down

Topic: relay and sensor, need some advice (Read 2815 times) previous topic - next topic

PASHGEN

Sep 25, 2019, 06:20 am Last Edit: Sep 25, 2019, 06:32 am by PASHGEN
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);

}




Go Up