Go Down

Topic: 8 relay module inverted (Read 4593 times) previous topic - next topic

makyrave

hello i'm new with arduino and i programed a to activate a relay module but here is the problem all program is inverted when i using the relay module and i don't know how to resolve this problem here 's the program, and i'm using a bluetooth module to activate the pin's.

for example: to activate the port 13 i must hit the number "1" and to desactvate i hit the "a" but it happens the opposite only if i am using the relay module, why ??

void setup()
{
   pinMode(13,OUTPUT);
   pinMode(12,OUTPUT);
   pinMode(11,OUTPUT);
   pinMode(10,OUTPUT);
   pinMode(9,OUTPUT);
   pinMode(8,OUTPUT);
   
   Serial.begin(9600);
}

void loop()
{
   char c = Serial.read();
   if (c == '1') digitalWrite(13,HIGH);
   if (c == '2') digitalWrite(12,HIGH);
   if (c == '3') digitalWrite(11,HIGH);
   if (c == '4') digitalWrite(10,HIGH);
   if (c == '5') digitalWrite(9,HIGH);
   if (c == '6') digitalWrite(8,HIGH);
 
 
   if (c == 'a') digitalWrite(13,LOW);
   if (c == 'b') digitalWrite(12,LOW);
   if (c == 'c') digitalWrite(11,LOW);
   if (c == 'd') digitalWrite(10,LOW);
   if (c == 'e') digitalWrite(9,LOW);
   if (c == 'f') digitalWrite(8,LOW);
   
 
  delay(1000);

AWOL

#1
Feb 01, 2015, 06:04 pm Last Edit: Feb 01, 2015, 06:07 pm by AWOL
Quote
and i programed a to activate a relay module
Which relay module?

Please remember to use code tags when posting code, like this
Code: [Select]
   char c = Serial.read();
   if (c >= '1' && c <= '6')
     digitalWrite(13 - (c -'1'), HIGH);
 
   if (c >= 'a' && c <= 'f')
     digitalWrite(13 - (c -'a'), LOW);

JimboZA

I've never used a relay module but from what I read, I think they usually have opto-isolators which by their nature invert. So you will probably have to change those digitalWrites so the HIGHs are LOWs and vice versa.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

MarkT

You should guard the Serial.read() call by first checking if a character is available:
Code: [Select]

  if (Serial.available () > 0)
  {
    char c = Serial.read () ;
    ....
    ....
  }


then lose the "delay (1000);"
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

zoomkat

Typical schematic for arduino relay modules.

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

KenF

HIGH is HIGH, LOW is LOW  Why do you have difficulty accepting that LOW is ACTIVE and HIGH is INACTIVE?

If that's the way your relay board works (and most of them do) , take off the blinkers and accept it. The only problem is with your erroneous preconception that "HIGH=ACTIVE".

Paul__B

#6
Feb 02, 2015, 01:30 am Last Edit: Feb 02, 2015, 02:03 am by Paul__B
HIGH is HIGH, LOW is LOW  Why do you have difficulty accepting that LOW is ACTIVE and HIGH is INACTIVE?

If that's the way your relay board works (and most of them do) , take off the blinkers and accept it. The only problem is with your erroneous preconception that "HIGH=ACTIVE".
That sounds a trifle harsh - the OP, single post so far, simply did not realise that it depends on how the relay board is wired and it is reasonably understandable that someone might expect modules to work in a "logical" manner. :D  We encounter this with great frequency in regard to the desirability of using switches pulling to ground and corresponding pull-ups.

zoomkat's diagram (which I have duly bookmarked on this PC, not the one I mostly use for discussions here) illustrates nicely what is really happening.

I've never used a relay module but from what I read, I think they usually have opto-isolators which by their nature invert.
Sifting through my 52 litre bins of eBay acquisitions, I find I have well over half a dozen such relay modules of the dual relay variety from SainSmart, but have yet to actually try one out.

I think it is somewhat misleading to say "opto-isolators which by their nature invert".  They no more "invert" than does a transistor which can be used in emitter-follower or common-base modes which do not invert.  Because the output of the opto-isolator is essentially a two terminal device - as is the input - there is considerable flexibility in how they are used (four permutations).  In particular, the opto-isolator is not limited as is an emitter-follower, in its ability to pull up to very close to the supply voltage.

KenF

That sounds a trifle harsh
Yes.  Reading it back it does come across that way. 

I've been suffering some considerable pain today and I'm afraid it's come across (quite unjustifiably) in my post here.  I hope makyrave will not take this personally. 

I can only say I'm sorry :(

JimboZA

I think it is somewhat misleading to say "opto-isolators which by their nature invert".  They no more "invert" than does a transistor which can be used in emitter-follower or common-base modes which do not invert. 
Fair comment.

Message to the OP though, is that his relay board seems to be wired to be upside-down from what was expected, and that can be sorted out in code by flipping the digitalWrites
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Go Up