# Problem with relay

**URL:** <https://forum.arduino.cc/t/problem-with-relay/1231039>\
**Category:** General Electronics\
**Created:** [March 3, 2024, 10:33am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039 "2024-03-03T10:33:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 10:33am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/1 "2024-03-03T10:33:05Z")

</div>

Hi, I recently started my adventure with arduino and for one of my first projects I decided to make a plany watering system. However, I encountered a problem while creating it. The issue is that when I have the whole system connected and I fire off the code that changes the states of the pin in a loop along with a delay, the relay sort of bypasses the delay because it shuts off momentarily when turned on. When the relay has no load, it works flawlessly and turns on/off every two seconds. There is also no problem with operation when the only part of the code is to set the pin to a low state to turn the relay on, then it also works without a problem. As for the relay, it is the SRD-5VDC-SL-C (it a module from here: [Buy Relay 5V 10A/250VAC Botland - Robotic Shop](https://botland.store/relays/8463-relay-5v-10a-250vac-5904422300517.html)). I have included the schematic diagram in the attachment (an arduino is powered from a computer by the usb). What could be the reason for this behavior?

 ![IMG_3667](https://europe1.discourse-cdn.com/arduino/original/4X/7/7/7/777d045c42afa0e1f39a19dd118064764b503e74.jpeg)

```arduino
#define pompa 5

void setup() {
  pinMode(pompa, OUTPUT);
  digitalWrite(pompa, HIGH);
}

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

```

---

<div class="post-metadata">

**Author:** ![gabygold](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gabygold/32/1048226_2.png) [@gabygold](https://forum.arduino.cc/u/gabygold)\
**Post date:** [March 3, 2024, 11:18am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/2 "2024-03-03T11:18:27Z")

</div>

Hi @kraszor ,

> [@kraszor](#):
>
> the relay sort of bypasses the delay because it shuts off momentarily when turned on. When the relay has no load, it works flawlessly and turns on/off every two seconds. There is also no problem with operation when the only part of the code is to set the pin to a low state to turn the relay on, then it also works without a problem.

Let's see if you can get closer to the solution by parts.

1. The startup issue: The pins, for microcontroller security issues, after rebooting start in a LOW tristate configuration, as I recall, that means that when you execute the

` pinMode(pompa, OUTPUT);`

you are already sending a LOW. To avoid this invert the two setup() lines order, first the digitalWrite, next the pinMode, so when you activate the pin in OUTPUT mode it will be presenting a HIGH condition.

The second part might be related to the characteristics of the relay used, is seems not to be optocupled, so using a motor might filter some noise in the circuit. For starters you've got a 6V power source for your pump, that relay model stands a voltage input of 120% of nominal specification, it means is tolerates 5v\*120% = 6v. Disconnect the relay power source from the Arduino and connect it to the battery pack appropiately (that includes the ground must be common...).

Good Luck!  
Gaby.//

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 11:30am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/3 "2024-03-03T11:30:59Z")

</div>

Thank you for your answer. But I am not sure if I understand. Isn’t a relay with a coil an element that separates the circuits? I don’t understand how can pump affect the arduino. Is it something related to EMI?

---

<div class="post-metadata">

**Author:** ![gabygold](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gabygold/32/1048226_2.png) [@gabygold](https://forum.arduino.cc/u/gabygold)\
**Post date:** [March 3, 2024, 11:41am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/4 "2024-03-03T11:41:17Z")

</div>

Hi @kraszor,

> [@kraszor](#):
>
> Isn’t a relay with a coil an element that separates the circuits? I don’t understand how can pump affect the arduino. Is it something related to EMI?

No, the relay is an element to separete mainly the **load** , so to give you the chance to move a bigger load with a smaller signal.

In the case of this pump what are you getting? The command circuit with low power (from the Arduino port), and a coil (as rightly noted by you) to activate the relay... on the other hand a bigger power (from your power bank) and a coil (your pump motor)... yes, it's better to separate them, you might be having EMI issues.

Good Luck!  
Gaby.//

---

<div class="post-metadata">

**Author:** ![gabygold](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gabygold/32/1048226_2.png) [@gabygold](https://forum.arduino.cc/u/gabygold)\
**Post date:** [March 3, 2024, 11:45am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/5 "2024-03-03T11:45:23Z")

</div>

And sorry, my mistake, in my previous answer I shoul have stated...

> [@gabygold](#):
>
> so when you activate the pin in OUTPUT mode it will be presenting a **HIGH** condition.

Gaby.//

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [March 3, 2024, 11:52am UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/7 "2024-03-03T11:52:47Z")

</div>

@kraszor  
Your diagram shows the relay connected to pin 4 but you sketch uses pin 5.  
Which one is correct?

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 12:12pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/8 "2024-03-03T12:12:49Z")

</div>

It should be connected to pin 5

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [March 3, 2024, 12:33pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/9 "2024-03-03T12:33:28Z")

</div>

> [@kraszor](#):
>
> it shuts off momentarily when turned on.

How do you know this? Does the LED blink off then come back on?  
How long is momentarily, 10ms, 50ms, 100ms?

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 1:08pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/10 "2024-03-03T13:08:00Z")

</div>

There is an led on the relay module, and instead of turning on and staying lit for 2 seconds (time of the delay) it turns off nearly in the same moment

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 1:32pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/11 "2024-03-03T13:32:00Z")

</div>

I will probably power the relay from batteries, but could you explain to me what is a difference between separating load and separating a circuit with a load (I mean this one with batteries and a pump)?

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [March 3, 2024, 1:36pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/12 "2024-03-03T13:36:20Z")

</div>

> [@kraszor](#):
>
> it turns off nearly in the same moment

Does it continually do that or does the sketch stop working

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [March 3, 2024, 1:40pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/13 "2024-03-03T13:40:06Z")

</div>

> [@gabygold](#):
>
> For starters you've got a 6V power source for your pump, that relay model stands a voltage input of 120% of nominal specification, it means is tolerates 5v\*120% = 6v.

Gaby,  
I think you are confusing 2 different things. The relay coil is rated for 5V and may well tolerate 6V, but that has nothing to do with the supply to the motor, which is not connected in any way to the relay coil. The contacts can undoubtedly work with a much higher voltage.

> [@kraszor](#):
>
> Isn’t a relay with a coil an element that separates the circuits?

Yes, it does.

> [@gabygold](#):
>
> No, the relay is an element to separete mainly the **load** , so to give you the chance to move a bigger load with a smaller signal

What does this mean? Why 'no'? The relay separates the circuits, including allowing a small signal to control a large load, and providing isolation between the two.

> [@gabygold](#):
>
> You might be having EMI issues.

I agree. However, I think we established that the load and the Arduino are separated by the relay, which leaves poor layout or wiring as a possible cause of problems. @kraszor , please can you post some photos clearly showing the layout of your project?

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 1:40pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/14 "2024-03-03T13:40:44Z")

</div>

It continually does that

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [March 3, 2024, 1:49pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/15 "2024-03-03T13:49:46Z")

</div>

Try putting a diode across the relay contacts like this  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/4/7/a/47abe3253ca736ea0d970bd8747c3e35ae30a98a.jpeg)

---

<div class="post-metadata">

**Author:** ![gabygold](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gabygold/32/1048226_2.png) [@gabygold](https://forum.arduino.cc/u/gabygold)\
**Post date:** [March 3, 2024, 2:58pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/16 "2024-03-03T14:58:20Z")

</div>

Hi @PerryBebbington ,  
Thank you for your input and surely the answer to @kraszor deserved a more elaborated redaction, let's see...

> [@PerryBebbington](#):
>
> I think you are confusing 2 different things. The relay coil is rated for 5V and may well tolerate 6V, but that has nothing to do with the supply to the motor, which is not connected in any way to the relay coil.[...]

The main ideas I'm attempting to give are easy ways to rule out problems in that very simple schematic @kraszor sent.  
So instead of going the expensive path I tried to re-elaborate what he has...

A new isolated power source for the relay? No need, the datasheet states specifically (I'm not guessing it) the coil tolerance of 6V, so removing any possibility of the relay coil interfering is as easy as removing the cable from the Arduino and connecting it to his 6V (4 batteries) power bank. Insurance for free.

Optocupler for the signal?? No need unless everything else free fails.

> [@PerryBebbington](#):
>
> What does this mean? Why 'no'? The relay separates the circuits, including allowing a small signal to control a large load, and providing isolation between the two.

Because you 're right the device isolates electrically the circuits, the one driving the coil from the higher values of the one providing for the main load, but here you have a coil inducing electromangnetic power to drive the contacts, contacts that close and become a conductor of a circuit driving higher current for a pump motor... The way to go is always isolate, and in this case not only to drive a higher load with a weaker signal provider, but to keep any spureous signals out.

If it's EMI he now has 2 roads (let's take out the gnd cable issue now... but no, we shouldn't) from his Arduino to the relay, cutting them down to 1 doesn't seem a bad start... next thing I would ensure is he's using an Optocupler version of those relays, as this one doesn't explicit name this attribute, checkin the provider's site.

So putting this clearly enough: in my humble opinion, having the relay indepentently powered, with a signaling isolation solution, not an electric signal conected to the MCU... yes, it's a complete separation of circuits.

Then, if everything fails...

Good Luck once again.  
Gaby.//

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [March 3, 2024, 4:05pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/17 "2024-03-03T16:05:01Z")

</div>

Hi, @kraszor  
Welcome to the forum.

Can you please post some pictures of your project?  
So we can see your component layout.

Do you have a DMM? Digital MultiMeter?

What is the load?  
Can you please post a link to data/specs of the load?

Thanks.. Tom.. 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 4:25pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/18 "2024-03-03T16:25:25Z")

</div>

@TomGeorge @PerryBebbington  
Uploading: IMG\_3671.jpeg…

 ![IMG_3672](https://europe1.discourse-cdn.com/arduino/original/4X/2/a/0/2a09b99fc7cecb8c7d4300aefa9f10fa012cc448.jpeg)  
 ![IMG_3673](https://europe1.discourse-cdn.com/arduino/original/4X/8/2/d/82dbf73ffddb826d0a038b4b47b624d7c1ea4206.jpeg)  
 ![IMG_3674](https://europe1.discourse-cdn.com/arduino/original/4X/a/2/c/a2c2dc62f97128f430dc73631ce22421884ca30f.jpeg)  
 ![IMG_3675](https://europe1.discourse-cdn.com/arduino/original/4X/2/c/4/2c413dbcb16cbe14d06630ba7c05e098c682364c.jpeg)

The load is this pump or very simmilar: [https://5.imimg.com/data5/IQ/GJ/PF/SELLER-1833510/dc-mini-submersible-water-pump.pdf](https://5.imimg.com/data5/IQ/GJ/PF/SELLER-1833510/dc-mini-submersible-water-pump.pdf)

---

<div class="post-metadata">

**Author:** ![kraszor](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kraszor](https://forum.arduino.cc/u/kraszor)\
**Post date:** [March 3, 2024, 4:26pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/19 "2024-03-03T16:26:29Z")

</div>

Yes, I have a DMM

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [March 3, 2024, 4:37pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/20 "2024-03-03T16:37:39Z")

</div>

Thanks for the photos.  
At the moment I don't see anything that causes me concern, so I am going to watch this topic and see what others suggest, but at the moment I don't have any ideas for you to try. If I think of anything I'll be back.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [March 3, 2024, 4:55pm UTC](https://forum.arduino.cc/t/problem-with-relay/1231039/21 "2024-03-03T16:55:32Z")

</div>

Did you try the diode yet?

[Next page](https://forum.arduino.cc/t/problem-with-relay/1231039.md?page=2)
