# Relay Turned on When Arduino Connected to Power Source

**URL:** <https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924>\
**Category:** Programming\
**Created:** [March 2, 2020, 5:25pm UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924 "2020-03-02T17:25:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pashew\_khalid](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@pashew\_khalid](https://forum.arduino.cc/u/pashew_khalid)\
**Post date:** [March 2, 2020, 5:25pm UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/1 "2020-03-02T17:25:47Z")

</div>

Greetings,

Dears I Hope you are in Good Health,

I'm Using Arduino UNO, This is My Project:

Motion Detector(PIR)  
Relay  
IR Remote

this is how it work

if Motion Detected Turn on the Relay, when IR Remote Received the Signal it Will Turn off the Relay

**THIS IS MY PROBLEM**

when i Upload the code it will work Normally, but when i unplug the the power and plugged in again, the Relay will Turn on ☹

can any one Help me Please to make relay off when plugged to power source.

Thanks in Advance.....

```cpp
#include <IRremote.h>
int MP_Sensor=3;    //Define PIR
int MP_Notification=4;  //Define Relay
int MP_IR = 6;  //Define IR Remote

IRrecv irrecv(MP_IR);
decode_results results;
#define BUTTON_0 0x9716BE3F

void setup() {
Serial.begin(9600);
pinMode(MP_Sensor, INPUT);
pinMode(MP_Notification, OUTPUT);
pinMode(MP_IR, INPUT);
digitalWrite(MP_Notification, HIGH);  //Make Relay off at Start

irrecv.enableIRIn();
}

void loop() {
if(digitalRead(3) == HIGH)
{
 digitalWrite(4, LOW);
}
  if (irrecv.decode(&results))
  {
    if (results.value == BUTTON_0)
    {
      digitalWrite(4, HIGH);
    }
    irrecv.resume();
  }
}

```

---

<div class="post-metadata">

**Author:** ![ToddL1962](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/toddl1962/32/225060_2.png) [@ToddL1962](https://forum.arduino.cc/u/ToddL1962)\
**Post date:** [March 2, 2020, 6:07pm UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/2 "2020-03-02T18:07:01Z")

</div>

Since your relay is active LOW use a pullup resistor. The pin defaults to an input (high impedance) at powerup.

---

<div class="post-metadata">

**Author:** ![pashew\_khalid](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@pashew\_khalid](https://forum.arduino.cc/u/pashew_khalid)\
**Post date:** [March 2, 2020, 6:13pm UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/3 "2020-03-02T18:13:28Z")

</div>

Dear ToddL1962 Many thanks for your Reply,

I'm Little bit new at Arduino 🙂  
Can you explain it to me because I Don't Understand.

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [March 2, 2020, 6:28pm UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/4 "2020-03-02T18:28:02Z")

</div>

This line controls the relay state at startup:

```cpp
digitalWrite(MP_Notification, HIGH);  //Make Relay off at Start

```

try

```cpp
digitalWrite(MP_Notification, LOW);  //Make Relay off at Start

```

---

<div class="post-metadata">

**Author:** ![pashew\_khalid](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@pashew\_khalid](https://forum.arduino.cc/u/pashew_khalid)\
**Post date:** [March 2, 2020, 6:37pm UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/5 "2020-03-02T18:37:38Z")

</div>

Dear aarg,  
I Tried this solution but Didn't Work ☹

---

<div class="post-metadata">

**Author:** ![evanmars](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/evanmars/32/217678_2.png) [@evanmars](https://forum.arduino.cc/u/evanmars)\
**Post date:** [March 3, 2020, 12:39am UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/6 "2020-03-03T00:39:33Z")

</div>

> aarg:  
> This line controls the relay state at startup:
> 
> ```arduino
> digitalWrite(MP_Notification, HIGH);   //Make Relay off at Start
> 
> ```
> 
> try
> 
> ```arduino
> digitalWrite(MP_Notification, LOW);   //Make Relay off at Start
> 
> ```

Probably not as most relay modules are active low.

What does the sensor sense at startup? ~~What kind of sensor is it?~~ Is the input floating by any chance?  
Why do you name the I/O pins, but then not use the names in loop()?

---

<div class="post-metadata">

**Author:** ![pashew\_khalid](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@pashew\_khalid](https://forum.arduino.cc/u/pashew_khalid)\
**Post date:** [March 3, 2020, 7:19am UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/7 "2020-03-03T07:19:53Z")

</div>

my motion detector (PIR) is work without any problem.

and there is no different if I use the definition or the Arduino pin

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:21am UTC](https://forum.arduino.cc/t/relay-turned-on-when-arduino-connected-to-power-source/639924/8 "2021-05-06T00:21:20Z")

</div>

Closed on May 6, 2021, 12:21am UTC


