# Relay keeps clicking continously - help

**URL:** <https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394>\
**Category:** Sensors\
**Created:** [February 23, 2024, 1:07am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394 "2024-02-23T01:07:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 1:07am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/1 "2024-02-23T01:07:17Z")

</div>

Hello. I am making a water fountain for my cat. I have an Arduino Nano, powered via miniUSB from a 5v phone charger. I have a 5v relay and a motion PIR sensor, powered from arduino's 5v. The relay clicks when moving, seems fine. When I connect the pump, the pump works but the relay keeps clicking. The voltage slightly drops to 4.7 - 4.8v. Pump is supposed to be 3-6v 100-200mah. The pump is connected to another charger. The pump works, but the relay clicks like once every 0.1 seconds. This is the code.

```arduino
const int MOTION_SENSOR_PIN = 8; // Arduino pin connected to the OUTPUT pin of motion sensor
const int RELAY_PIN = 6; // Arduino pin connected to the IN pin of relay
int motionStateCurrent = LOW; // current state of motion sensor's pin
int motionStatePrevious = LOW; // previous state of motion sensor's pin

void setup() {
  Serial.begin(9600); // initialize serial
  pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode
  pinMode(RELAY_PIN, OUTPUT); // set arduino pin to output mode
}

void loop() {
  motionStatePrevious = motionStateCurrent; // store old state
  motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // read new state

  if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGH
    Serial.println("Motion detected!");
    digitalWrite(RELAY_PIN, HIGH); // turn on
  }
  else
  if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // pin state change: HIGH -> LOW
    Serial.println("Motion stopped!");
    digitalWrite(RELAY_PIN, LOW); // turn off
  }
}

```

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [February 23, 2024, 1:31am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/2 "2024-02-23T01:31:33Z")

</div>

> [@lupuom](#):
>
> powered from arduino's 5v

Use the phone charger as the power supply for all the devices. Arduino is a microcontroller, not a power supply.

---

<div class="post-metadata">

**Author:** ![dougp](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dougp/32/238908_2.png) [@dougp](https://forum.arduino.cc/u/dougp)\
**Post date:** [February 23, 2024, 1:32am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/3 "2024-02-23T01:32:55Z")

</div>

Also, tho' it's not shown I'll guess you're driving the relay with an Arduino output?

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 1:36am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/4 "2024-02-23T01:36:30Z")

</div>

The above is all the code. What do you mean?

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 1:37am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/5 "2024-02-23T01:37:29Z")

</div>

If I power the relay from the same psu, it does not work at all. 5v 2.4A psu.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [February 23, 2024, 1:51am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/6 "2024-02-23T01:51:00Z")

</div>

Then you have "it" incorrectly connected... according to your drawing.

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 2:43am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/7 "2024-02-23T02:43:17Z")

</div>

![arduino-motion-sensor-relay-wiring-diagram](https://europe1.discourse-cdn.com/arduino/original/4X/2/f/d/2fdcf4eb860d56c629343881b92c415279020eb0.webp)  
It is exactly like this, but a small pump not a bulb, and Nano not Uno

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [February 23, 2024, 2:51am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/8 "2024-02-23T02:51:11Z")

</div>

> [@lupuom](#):
>
> It is exactly like this

Where is the 5vdc phone charger?

> [@lupuom](#):
>
> 5v phone charger

I know, I know... everything is connected right and it all works, but it doesn't work... and I am wrong... so that means, if you hook it up like this, and it works, you will be saying I am right... but since you have everything right and it works but it doesn't work... this must be wrong. Dilemma.  
Corrected image shows the missing 5vdc phone charger power going to the coil side of the relay and sharing ground... or not.

 ![thing](https://europe1.discourse-cdn.com/arduino/original/4X/4/7/e/47ed687d8e87cd7198f7bbf009ad47928ab46248.jpeg)

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 9:57am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/9 "2024-02-23T09:57:07Z")

</div>

I just did as you said, relay does not work at all now

 ![PXL_20240223_095238331.MP](https://europe1.discourse-cdn.com/arduino/original/4X/f/1/4/f144c7d401f20ddea3ab6cfc13a28cd033c196b2.jpeg)  
Relay ground to arduino ground, red wire from VCC to charger.

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [February 23, 2024, 10:12am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/10 "2024-02-23T10:12:54Z")

</div>

@lupuom  
The diagram you show in post #7 is fine and it should work.  
Does it work OK if you have the USB connected to a computer?  
Is there a sensitivity adjustment on the PIR device?

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 10:40am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/11 "2024-02-23T10:40:34Z")

</div>

With a computer USB, it is the same. The thing is, the relay clicks and works perfectly when NOT connected to the pump. It respects the set time on the PIR sensor, everything. When I connect the pump... Clickclickclickclick. Pump works. The clicking is extremely annoying though.

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [February 23, 2024, 11:02am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/12 "2024-02-23T11:02:26Z")

</div>

> [@lupuom](#):
>
> The thing is, the relay clicks and works perfectly when NOT connected to the pump.

Your assumption that connecting the pump should not have an effect on the relay is **correct** but it is happening.  
One bad thing is that you are running a 3-6V pump on 12V, that is not good.  
Another bad thing is that you don't have a flyback diode on the pump.

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 11:15am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/13 "2024-02-23T11:15:37Z")

</div>

The pump runs on a phone charger via usb cable cut up, it is 5v.

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [February 23, 2024, 11:23am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/14 "2024-02-23T11:23:55Z")

</div>

Is there anything else different from what you show in your diagram in post #7 ?

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [February 23, 2024, 11:25am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/15 "2024-02-23T11:25:19Z")

</div>

Hi @lupuom ,

is it intended that your drawing and the sketch do not comply?

Sketch:

```arduino
const int MOTION_SENSOR_PIN = 8; // Arduino pin connected to the OUTPUT pin of motion sensor
const int RELAY_PIN = 6; // Arduino pin connected to the IN pin of relay

```

Drawing:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/e/5/0/e507dd478c92f0ab7df9c2b64a60e6c06fd6257f.jpeg)

If the drawing is correct it should read

```arduino
const int MOTION_SENSOR_PIN = 7; // Arduino pin connected to the OUTPUT pin of motion sensor
const int RELAY_PIN = A5; // Arduino pin connected to the IN pin of relay

```

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [February 23, 2024, 11:25am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/16 "2024-02-23T11:25:27Z")

</div>

Try putting a 1N4001 diode like shown in this diagram

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/d/5/0/d508d9ac078fd6c63fdd775a644c23304e4c15d5.png)

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 11:26am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/17 "2024-02-23T11:26:14Z")

</div>

Yes, it is an internet scheme, I put mine on 8 and 6, Digital.

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 11:27am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/18 "2024-02-23T11:27:04Z")

</div>

Thank you, will try it out.

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [February 23, 2024, 11:32am UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/19 "2024-02-23T11:32:50Z")

</div>

Please don't post diagrams that don't show exactly how you have things connected and what powers sources you are using. It just makes us go on wild goose chases and we get nowhere in trying to help you.

Please show us exactly how you have things connected and how things are powered.

---

<div class="post-metadata">

**Author:** ![lupuom](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lupuom](https://forum.arduino.cc/u/lupuom)\
**Post date:** [February 23, 2024, 12:51pm UTC](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394/20 "2024-02-23T12:51:44Z")

</div>

![arduino](https://europe1.discourse-cdn.com/arduino/original/4X/a/0/0/a00a47f5e7cd60c0ad62604dc055fdba910f2533.jpeg)  
Done ! I have trouble finding that diode without quite some time of shipping

[Next page](https://forum.arduino.cc/t/relay-keeps-clicking-continously-help/1227394.md?page=2)
