# Input monitoring logic is not working

**URL:** <https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932>\
**Category:** Programming\
**Created:** [April 8, 2026, 7:07am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932 "2026-04-08T07:07:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 7:07am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/1 "2026-04-08T07:07:51Z")

</div>

Hello,

I have written the following sketch and I am facing few issues

1. while power on device irrespective of input pins state relay1 is switching ON and OFF for twice actual behaviour should be if both input1 and 2 are high(not connected to GND pin) then the relay 1 should be on and after 1 second relay1 should off along with relay1 led should ON. this whole behaviour is not consistent while power OFF and ON the device

2. this is more troublesome logic in my sketch i.e. input monitoring logic. once relay1 is ON then the monitor timer starts i.e 30 secs and within this time if this pin is not low then relay2 should trigger ON and wait for a second and then OFF and finally will go to block state for 45 mins once lapse this 45 mins time frame then the whole device should reset automatically.  
Sometimes after reset the actual functionality is not working at all, like blink led dont respond, relay1 triggers but relay1 led wont lit up etc…

Please help me to resolve this. I tried to fix through AI tools but no luck.  
I am using arduino UNO to test this code but my final goal to use ATTiny2313 MCU.

```  
// implemented auto timer reset logic after 45 mins

```arduino
#include <avr/wdt.h>

#define OPENED 1 // Pin not connected (HIGH, due to pull-up resistor)
#define CLOSED 0 // Pin connected to GND (LOW)

const int BLINK_LED = 4;
const int Input1 = 5;
const int Input2 = 6;
const int monitor_input = 7;
const int mode = 8;

const int RELAY1 = 9;
const int RELAY2 = 10;
const int Relay1_Led = 11;

const int monitor_input_LED = 13;
const int ind1_LED = 14;
const int ind2_LED = 15;

bool relay1Activated = false;
bool monitor_input_Active = false;
bool stopHandled = false;
unsigned long monitor_input_StartTime = 0;

unsigned long previousMillis = 0; // Tracks the last time the LED blinked
const unsigned long blinkInterval = 600; // Blink interval in milliseconds
bool blinkState = false;
const unsigned long waitTime = 2700000; // Wait time 45 minutes
unsigned long relayStartMillis = 0;

const unsigned long ledWaitTime = 1800000; // Wait time 30 minutes
unsigned long startTime = 0;
bool timerStarted = false;
bool timeoutReached = false;

bool isMagMode = false;
bool sce1 = false;
bool sce2 = false;

void setup() {
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(monitor_input_LED, OUTPUT);
pinMode(ind2_LED, OUTPUT);
pinMode(ind1_LED, OUTPUT);
pinMode(Relay1_Led, OUTPUT);
pinMode(BLINK_LED, OUTPUT);

pinMode(Input1, INPUT_PULLUP);
pinMode(Input2, INPUT_PULLUP);
pinMode(monitor_input, INPUT_PULLUP);

digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, HIGH);
digitalWrite(monitor_input_LED, LOW);
digitalWrite(ind2_LED, LOW);
digitalWrite(ind1_LED, LOW);
digitalWrite(Relay1_Led, LOW);

pinMode(mode, INPUT_PULLUP);
isMagMode = (digitalRead(mode) == HIGH);
}

void loop() {

// Blink LED (Pin 15) continuously
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= blinkInterval) {
previousMillis = currentMillis; // Update the last blink time
blinkState = !blinkState; // Toggle the blink state
digitalWrite(BLINK_LED, blinkState ? HIGH : LOW); // Set LED state
} // Wait for 500 milliseconds

// LED section

int IN2 = digitalRead(Input2);
int IN1 = digitalRead(Input1);

if(isMagMode){
if (IN2 == CLOSED && IN1 == CLOSED) {
digitalWrite(ind1_LED, LOW); // Yellow OFF
digitalWrite(ind2_LED, HIGH); // Green ON
}
else if (IN1 == CLOSED) {
digitalWrite(ind1_LED, HIGH); // Yellow ON
digitalWrite(ind2_LED, LOW); // Green OFF
}
else {
digitalWrite(ind1_LED, LOW); // Yellow OFF
digitalWrite(ind2_LED, LOW); // Green OFF
}
}
else
{
if ((digitalRead(Input1) == HIGH && digitalRead(Input2) == LOW)) {

// Start timer only once
if (!timerStarted) {
  startTime = millis();
  timerStarted = true;
  timeoutReached = false;
}

// Check timeout
if (!timeoutReached && millis() - startTime >= ledWaitTime) {
  timeoutReached = true;
}

// LED control (NO conflict now)
if (!timeoutReached) {
  digitalWrite(ind2_LED, HIGH); // Green ON
  digitalWrite(ind1_LED, LOW); // Yellow OFF
} else {
  digitalWrite(ind2_LED, LOW); // Green OFF
  digitalWrite(ind1_LED, HIGH); // Yellow ON
}

}
else {
// Reset everything
timerStarted = false;
timeoutReached = false;

digitalWrite(ind2_LED, LOW);
digitalWrite(ind1_LED, LOW);

}
}

//for scenario 1
if(isMagMode){
sce1 = (digitalRead(Input1) == HIGH && digitalRead(Input2) == HIGH);
}
else{
sce1 = (digitalRead(Input1) == LOW);
}

if (sce1 && !relay1Activated) {
if (relayStartMillis == 0) {
digitalWrite(monitor_input_LED, LOW);
relayStartMillis = millis();
}

if (millis() - relayStartMillis >= 3000) {
  delay(2000);
  digitalWrite(RELAY1, LOW);
  digitalWrite(Relay1_Led, HIGH);
  delay(1500); // Wait for 4 seconds
  digitalWrite(RELAY1, HIGH);
  relay1Activated = true;
  relayStartMillis = 0; // Reset the timer to allow re-triggering the delay
}

}

// for monitoring
if (relay1Activated && digitalRead(monitor_input) == HIGH) {
if (!monitor_input_Active) {
monitor_input_StartTime = millis();
monitor_input_Active = true;
}

unsigned long monitor_input_currentMillis = millis();
if (monitor_input_currentMillis - monitor_input_StartTime >= 30000) {
  if (digitalRead(monitor_input) == HIGH) {
    digitalWrite(RELAY2, LOW);
    digitalWrite(monitor_input_LED, HIGH);
    digitalWrite(Relay1_Led, LOW);
    delay(1000);
    digitalWrite(RELAY2, HIGH);
    delay(waitTime); // Wait for 45 mins
    relay1Activated = false;
    // After the delay, reset the timer and allow the sce1 logic to trigger
    relayStartMillis = 0;
  } else {
    monitor_input_Active = false;
  }
}

} else {
monitor_input_Active = false;
}

//for scenrio2
if(isMagMode){
sce2 = (digitalRead(Input1) == LOW && digitalRead(Input2) == LOW);
}
else{
sce2 = (digitalRead(Input1) == HIGH && digitalRead(Input2) == LOW);
}

// Trigger STOP for BOTH scenarios (auto + external)
if (sce2 && !stopHandled) {
stopHandled = true;

digitalWrite(monitor_input_LED, LOW);
delay(2000);

digitalWrite(RELAY2, LOW);
digitalWrite(Relay1_Led, LOW);
delay(1000);
digitalWrite(RELAY2, HIGH);

// Reset internal states
relay1Activated = false;
monitor_input_Active = false;
relayStartMillis = 0;
}

if (!sce2) {
stopHandled = false;
}
delay(500);
}

```

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 7:12am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/2 "2026-04-08T07:12:45Z")

</div>

Develop your hardware/software using Arduino UNO R3 and then nicely migrate to ATtiny2313. You will be enjoying to troubleshoot/debug the system.

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 7:17am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/3 "2026-04-08T07:17:30Z")

</div>

I tried with Arduino UNO directly still same behavior but reset functionality should work on ATTiny2313

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 7:19am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/4 "2026-04-08T07:19:59Z")

</div>

> [@chandu-mca06](#):
>
> I tried with Arduino UNO directly still same behavior

Try step-by-step and not the whole sketch at a time. Describe the workflow (what is happening after what) of your sketch to get help from where to start first.

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 7:21am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/5 "2026-04-08T07:21:27Z")

</div>

As I mentioned, only problem with monitoring block. I tried different logics but no luck.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 8, 2026, 7:22am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/6 "2026-04-08T07:22:15Z")

</div>

> [@chandu-mca06](#):
>
> if both input1 and 2 are high(not connected to GND pin)

What is keeping them HIGH when not connected to GND ?

Please edit your post, select all of the code then click on the \< CODE \> icon and save the post. This will make the code easier to read by adding code tags to it

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 7:27am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/7 "2026-04-08T07:27:26Z")

</div>

> [@chandu-mca06](#):
>
> monitoring block.

Post the code using code tags \< code \> that belong to "Monitoring Block".

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 7:36am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/8 "2026-04-08T07:36:26Z")

</div>

Done. Please check now.

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 7:36am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/9 "2026-04-08T07:36:55Z")

</div>

Edited my post.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 8, 2026, 7:39am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/10 "2026-04-08T07:39:03Z")

</div>

Thank you for adding the code tags

What about my question ?

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 7:40am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/11 "2026-04-08T07:40:57Z")

</div>

If I connect monitor pin 7 to GND then it is LOW if we disconnect it is HIGH right? I mean floating pin as we are using internal pullup

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 8, 2026, 7:49am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/12 "2026-04-08T07:49:09Z")

</div>

Because of the use of INPUT\_PULLUP the pins are not actually floating, rather they are HIGH or LOW, and now that you have added the code tags it is easier to examine the code to see the use of INPUT\_PULLUP

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 8:14am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/13 "2026-04-08T08:14:33Z")

</div>

> [@chandu-mca06](#):
>
> As I mentioned, only problem with monitoring block.

Is the following your monitoring block? If yes, explain in plain text what do you want achieve here? You can easily test this block using UNO R3.

I have re-formatted your code block by aligning the opening/closing braces ({}).

```arduino
// for monitoring
if (relay1Activated && digitalRead(monitor_input) == HIGH) 
{
   if (!monitor_input_Active) 
   {
      monitor_input_StartTime = millis();
      monitor_input_Active = true;
   }

   unsigned long monitor_input_currentMillis = millis();
   if (monitor_input_currentMillis - monitor_input_StartTime >= 30000) 
   {
       if (digitalRead(monitor_input) == HIGH) 
       {
          digitalWrite(RELAY2, LOW);
          digitalWrite(monitor_input_LED, HIGH);
          digitalWrite(Relay1_Led, LOW);
          delay(1000);
          digitalWrite(RELAY2, HIGH);
          delay(waitTime); // Wait for 45 mins
          relay1Activated = false;
          // After the delay, reset the timer and allow the sce1 logic to trigger
          relayStartMillis = 0;
      } 
      else 
      {
          monitor_input_Active = false;
      }
   }
} 
else 
{
   monitor_input_Active = false;
}

```

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 8:22am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/14 "2026-04-08T08:22:04Z")

</div>

yes this is the block which is not working or behaving like malfunctioned

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 8:23am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/15 "2026-04-08T08:23:30Z")

</div>

You can easily test this monitoring block using UNO.

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 8:23am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/16 "2026-04-08T08:23:39Z")

</div>

Do you see any abnormalities in the code?

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 8:25am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/17 "2026-04-08T08:25:52Z")

</div>

> [@chandu-mca06](#):
>
> Do you see any abnormalities in the code?

This can only be seen by testing the code. Have you written this code yourself or is it AI assisted code?

Explain in plain text what do you want achieve here?

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 8:26am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/18 "2026-04-08T08:26:46Z")

</div>

Hello, I already mentioned that I tested this and also tried other logics before posting here. Still no luck.

---

<div class="post-metadata">

**Author:** ![chandu-mca06](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@chandu-mca06](https://forum.arduino.cc/u/chandu-mca06)\
**Post date:** [April 8, 2026, 8:28am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/19 "2026-04-08T08:28:02Z")

</div>

I have written initially which was not working so I used AI to fix them but AI tools are creating more issues than fixing the current issue ☹

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [April 8, 2026, 8:28am UTC](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932/20 "2026-04-08T08:28:49Z")

</div>

> [@chandu-mca06](#):
>
> Hello, I already mentioned that I tested this and also tried other logics before posting here. Still no luck.

If you can't explain what you want to achieve from the execution of these code, the chance of getting help is remote.

[Next page](https://forum.arduino.cc/t/input-monitoring-logic-is-not-working/1438932.md?page=2)
