Go Down

Topic: Strange relay behaviour  (Read 2347 times) previous topic - next topic

jack wp

Not sure how to wire them. Tried to wire pullup resistor as for input pin - put 10K resistor between attiny pin and Vcc. But it doesn't work. Maybe because wiring is somewhat different for an output pin?
It sounds like you wired them correctly. You are actually concerned about the input pins having a pullup resistor, but, sounds like, in your case, that was the same.

Paul__B

On this optocoupler module pulling low switches relay on and vice versa.
That is correct.

So if you use the incorrect initialisation sequence, you are briefly pulling the outputs LOW in setup() before setting them HIGH.

So have you now tried the corrected code I gave you? :smiley-roll:

jack wp

Have you changed your script as Paul__B suggested in post #9 ?
That may well be the key.

gv445

Yes, I changed my script according to Paul__B as suggested in post #9, but the result is the same. Also tried removing the pinmode commands altogether. No help. All the relays still flash momentarily. Maybe I shall try lower than 10K pullup ?

jack wp

You say "after power on", how about after hitting the reset button on the arduino?
Does power on mean powering up the relay board as well as the arduino?

gv445

Quote
Does power on mean powering up the relay board as well as the arduino
Yes. I power them both from the same source. But I use Attiny44, not Arduino. Not sure how do I reset Attiny? Is grounding Reset pin sufficient?

jack wp

#21
Sep 21, 2015, 07:02 pm Last Edit: Sep 21, 2015, 07:04 pm by jack wp
" I use Attiny44, not Arduino. Not sure how do I reset Attiny? Is grounding Reset pin sufficient?"

Yes, grounding the reset pin is sufficient.

On a side note, it is normal to have a 10k pullup resistor on the reset pin to prevent false resets.

gv445

Well, the relays flash in the same way when I ground Reset pin.

jack wp

#23
Sep 21, 2015, 07:22 pm Last Edit: Sep 21, 2015, 07:29 pm by jack wp
Well, more info, but still a mystery!

You say the relays flash, does that mean the output of the relay (the contacts side)?

If you pull one wire from between the processor and the relay board, does that prevent that particular relay from activating?

It's looking more and more like the signal is origination from the processor.
You may want to try a different script, such as the old standby "blink a led". Just to make sure none of the pins set by the script are causing the problem. It may be just a hardware thing.

gv445

Got totaly confused   :smiley-confuse:  :smiley-confuse:  :  This one works without any flash:

Code: [Select]
void setup() {
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  
}

// the loop function runs over and over again forever
void loop() {
  delay(1000);  
  digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(7, HIGH);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}


But this one still flashes once (all the 7 relays at once).

Code: [Select]
int Relay1 =  6;        
int Relay2 =  7;        
int Relay3 =  8;        

int Relay4 =  4;        
int Relay5 =  9;        
int Relay6 =  10;      
int Relay7 =  5;        

void setup()
{  
  pinMode(Relay1, OUTPUT);  
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay4, OUTPUT);  
  pinMode(Relay5, OUTPUT);
  pinMode(Relay6, OUTPUT);
  pinMode(Relay7, OUTPUT);
  
  digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, HIGH);
  digitalWrite(Relay3, HIGH);
  digitalWrite(Relay4, HIGH);  
  digitalWrite(Relay5, HIGH);  
  digitalWrite(Relay6, HIGH);  
  digitalWrite(Relay7, HIGH);
}

void loop()
{  
        digitalWrite(Relay1, LOW);    // relay is "on" when pin is LOW      
        delay(1000);
        digitalWrite(Relay1, HIGH);          
        
        digitalWrite(Relay2, LOW);    
        delay(1000);
        digitalWrite(Relay2, HIGH);    

        digitalWrite(Relay3, LOW);
        delay(1000);
        digitalWrite(Relay3, HIGH);
        
        digitalWrite(Relay4, LOW);
        delay(1000);
        digitalWrite(Relay4, HIGH);
        
        digitalWrite(Relay5, LOW);
        delay(1000);
        digitalWrite(Relay5, HIGH);
        
        digitalWrite(Relay6, LOW);
        delay(1000);
        digitalWrite(Relay6, HIGH);
        
        digitalWrite(Relay7, LOW);
        delay(1000);
        digitalWrite(Relay7, HIGH);
    delay(3000);
}

jack wp

It is challenging for sure.

try removing or remarking out :
Code: [Select]

 pinMode(Relay1, OUTPUT); 
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay4, OUTPUT); 
  pinMode(Relay5, OUTPUT);
  pinMode(Relay6, OUTPUT);
  pinMode(Relay7, OUTPUT);
 

Paul__B

Yes, I changed my script according to Paul__B as suggested in post #9, but the result is the same.
I think I have figured it - as a result of another discussion I was having!

So, try this code:

Code: [Select]
int Relay1 =  6;        
int Relay2 =  7;        
int Relay3 =  8;        
int Relay4 =  4;        
int Relay5 =  9;        
int Relay6 =  10;      
int Relay7 =  5;        

void setup()
{  
  digitalWrite(Relay1, HIGH);
  pinMode(Relay1, OUTPUT); 
  digitalWrite(Relay2, HIGH);
  pinMode(Relay2, OUTPUT);
  digitalWrite(Relay3, HIGH);
  pinMode(Relay3, OUTPUT);
  digitalWrite(Relay4, HIGH);  
  pinMode(Relay4, OUTPUT); 
  digitalWrite(Relay5, HIGH);  
  pinMode(Relay5, OUTPUT);
  digitalWrite(Relay6, HIGH);  
  pinMode(Relay6, OUTPUT);
  digitalWrite(Relay7, HIGH);
  pinMode(Relay7, OUTPUT);
}

void loop()
{  
        digitalWrite(Relay1, LOW);    // relay is "on" when pin is LOW      
        delay(1000);
        digitalWrite(Relay1, HIGH);          
        
        digitalWrite(Relay2, LOW);    
        delay(1000);
        digitalWrite(Relay2, HIGH);    

        digitalWrite(Relay3, LOW);
        delay(1000);
        digitalWrite(Relay3, HIGH);
        
        digitalWrite(Relay4, LOW);
        delay(1000);
        digitalWrite(Relay4, HIGH);
        
        digitalWrite(Relay5, LOW);
        delay(1000);
        digitalWrite(Relay5, HIGH);
        
        digitalWrite(Relay6, LOW);
        delay(1000);
        digitalWrite(Relay6, HIGH);
        
        digitalWrite(Relay7, LOW);
        delay(1000);
        digitalWrite(Relay7, HIGH);
    delay(3000);
}


It's looking more and more like the signal is origination from the processor.
Yes, of course it is originating from the processor!  That was only ever the case. :smiley-lol:

jack wp

#27
Sep 21, 2015, 09:01 pm Last Edit: Sep 21, 2015, 09:05 pm by jack wp
"Yes, of course it is originating from the processor!  That was only ever the case. :smiley-lol: "
You may be an engineer, and know that a relay on a relay board may be triggered by other than the external processor upon power up of the two systems. Sorry if I am not an engineer, but I still try, of course.

The new code that you learned, may just work. Good find.

Go Up