Relay problem

Howzit everyone.

I have a very strange relay problem. I wrote a code to change between two relays. before I purchased the 2-channel 5v relay board I used 2 LED's to indicate HIGH and LOW. That works perfectly fine, but once I connect the relay board they switch vigorously for about half a second, and then work inversely to the outputs, the outputs are generally low but the relays then stay at the normally open positions and switch over to normally closed once they get a high. To make this more confusing, I connected the relays together with the LED's just to be sure, now the LED's still light up correctly and the relays still switch incorrectly
What bugs me though. The relay board has two small LED's on it, and I believe they are there to indicate the state of each relay. If I only connect the 5v and GND to the relay board those are off. But once I add the two input wires the relays switch to NO and the turn red, but once but once I play with the sensors to make them switch these indicator LED's don't go off they simply dim... although the relays fully switch.

Has anyone ever had such a problem? can you perhaps give me some advice please??

Got a schematic, link to the relay board you are using, code you are using (poste with < /> code tags)?

Hi

Sound like me. I ordered some relays to switch off a external device, but I missed the correct relay. As you, I tested my code with led before the relay arrive.
So, I suspect you have an "Active LOW level trigger", see here:

https://arduino-info.wikispaces.com/ArduinoPower

I solved this with this code inside setup section:

    digitalWrite(Relaypin, HIGH); // will prevent an active low relay to energize
    pinMode(Relaypin, OUTPUT);

And inside the main loop code use:

digitalWrite(Relaypin, LOW);

to active/energize the relay.

As told to you, a schematic or even a pic of your relay will help too.

Some relay boards are jumper hight/low selected, mine is only low trigger.

Trigger is not the right word. A trigger is a momentary pulse. The word you are looking for is "signal".

Thanks guys!! Let me try it by changing the HIGH's and the LOW's of the code first, its kind of backwards programming but if it solves the problem then great! If not, I'll post the code, purpose and wiring diagram.

Most relay boards are "active LOW".
As mentioned, set the pin HIGH (relay off) in setup.
Avoid pin13.
Leo..

Wawa:
Most relay boards are "active LOW".
As mentioned, set the pin HIGH (relay off) in setup.

Also - set the pin HIGH before setting it as pinMode(relayPin, OUTPUT).

It seems on many of these relay boards, presumably due to saturation of the driver transistor, the supposedly brief time between setting it as a (LOW) output, and setting it HIGH, is sufficient to turn the relay briefly on, and especially if you are defining a number of pin modes before setting up the output levels.

I can't believe that could happen, a few tens of microseconds is invisible to a mechanical relay.

But we have had extensive discussions here about that very effect. Something about the design of the relay modules and saturating transistors.

It seems on many of these relay boards, presumably due to saturation of the driver transistor, the supposedly brief time between setting it as a (LOW) output, and setting it HIGH, is sufficient to turn the relay briefly on, and especially if you are defining a number of pin modes before setting up the output levels.

Can you post a hand drawn timing diagram that shows the timing you describe ? I am not sure I follow what you are saying. If it is active LOW, and you send a LOW, are you saying that it should not turn on unless the duration of the LOW exceeds some minimum turn on time ?

Thanks guys! Changing the code worked perfectly well!! thanks for your time and advice!! (I did however post a reply saying it worked and thank you very much and all, seems it didnt deliver.