Go Down

Topic: Relay issues (Read 146 times) previous topic - next topic

Danlov99

Sep 09, 2019, 10:02 pm Last Edit: Sep 09, 2019, 10:03 pm by Danlov99
hi, I apologise in advance if I get any terminology wrong and make it hard to understand beware I am a beginner. I have connected a single chanel 5V relay board module to the arduino with d8 going to signal, + going to 5V and - going to ground, the code I am using is extremely simple as follows:
Code: [Select]

#define Relay 8

void setup() {
pinMode(Relay, OUTPUT);
}

void loop() {
digitalWrite(Relay, HIGH) ;
delay(2000);
        digitalWrite(Relay, LOW) ;
}


It was all working fine earlier today but suddenly after connecting it all back up the LED on the relay board blinks(once per second) and it doesn't switch at all, I've tried using external power(both four AA battery's and a USB cable. I only bought the relay a few days ago and here is the link if it helps:

https://rover.ebay.com/rover/0/0/0?mpre=https%3A%2F%2Fwww.ebay.co.uk%2Fulk%2Fitm%2F252051910091

vaj4088

The line

Code: [Select]

digitalWrite(Relay, HIGH) ;


will be executed almost immediately after

Code: [Select]

        digitalWrite(Relay, LOW) ;


so the relay won't get much of a chance to switch.  The relay is slow when compared to what your unspecified Arduino can do.

Try this and report back:

Code: [Select]

#define Relay 8

void setup() {
pinMode(Relay, OUTPUT);
}

void loop() {
digitalWrite(Relay, HIGH) ;
delay(2000);
        digitalWrite(Relay, LOW) ;
        delay(2000);                  //  This line added as a crude way to slow things down.
}


By the way, you are to be congratulated for using code tags!

Good Luck!

hammy

#2
Sep 09, 2019, 10:25 pm Last Edit: Sep 09, 2019, 10:27 pm by hammy
And ....Could really do with a drawn wiring diagram , as above there is an error in the code , but ...what you say suggests the relay itself is also being powered from the Arduino - that is not a great idea as the load may be pulling the 5v supply low

vaj4088

I agree that the relay should not be powered from the Arduino.

What "...error in the code" ?  It compiled fine for me.


Danlov99

Sorry it's an Arduino Uno and yes I did power the relay from the arduino after this issue occurred to check if it was the power source or not. originally it was being powered by battery's and then a USB port on my pc. do you think that not giving the relay time to switch back could cause this issue then? can't recall how many times it switched earlier so it might have only been the once which would make sense in that case

vaj4088

Not allowing time for the relay to switch is certainly a problem.  It should be simple enough to try the modified code.

Danlov99

that fixed it thanks a bunch :)

lisa85goss

Thanks everyone for you information

vaj4088

Who is lisa85goss and why is this person giving thanks on this topic?

Go Up