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??
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:
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.
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.
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.