# Digital pin 0 and 1 programming problem

**URL:** <https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658>\
**Category:** Programming\
**Created:** [March 29, 2022, 4:53am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658 "2022-03-29T04:53:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 29, 2022, 4:53am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/1 "2022-03-29T04:53:55Z")

</div>

After uploading the code via Arduino IDE, I disconnect USB cable and THEN i use battery power to the Arduno Uno board,

in this situation,

Is there any method, tips and tricks to use 0 and 1 pins connect with Buttons (pressed - High, not pressed LOW) without any interference (ARDUINO uno board)

it's essential requirement for my project, because all other pins already used except digital pin 0 and 1for the project,

waiting positive reply from experts.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [March 29, 2022, 5:00am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/2 "2022-03-29T05:00:22Z")

</div>

Try connecting the pins to a N.O. switch connected to GND.

Turn on pull-ups on the pins.

Show us the sketch.

---

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 29, 2022, 6:12am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/3 "2022-03-29T06:12:36Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/1/7/c/17ceb8cd78d31ee6859649facbd779737361b4a8.png)

---

<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 29, 2022, 6:16am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/4 "2022-03-29T06:16:10Z")

</div>

Hi,  
Are you using the analog input pins on the UNO.  
They can also be used as digital inputs.

```cpp
pinMode(A0, INPUT);

```

Tom.... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 29, 2022, 6:16am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/5 "2022-03-29T06:16:36Z")

</div>

take values HIGH and LOW properly, via these pin No 0, 1 and 2, but sometimes not take HIGH/LOW properly after POWER ON 3- 5 minutes later,

---

<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 29, 2022, 6:21am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/6 "2022-03-29T06:21:51Z")

</div>

Hi,  
Can you please post a circuit diagram so we can see if it is possible to add the extra inputs another way?

Thanks.. Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 29, 2022, 6:36am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/7 "2022-03-29T06:36:58Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/7/1/1/71106dbb10b4893314c76911513fb9fa87e7b707.jpeg)

this is circuit diagram, i have a code also, written by my friend,

my problem is in order to the wiring diagram, take get THREE sensor values HIGH and LOW properly, via these pin No 0, 1 and 2, but sometimes not take HIGH/LOW properly after POWER ON 3- 5 minutes later,

thank you.

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [March 29, 2022, 6:45am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/8 "2022-03-29T06:45:33Z")

</div>

The wiring of your 3 switches is odd and probably contributes to your problem, although I must say I find these Fritzy kind of drawings very confusing to read. A proper schematic is _much_ better.  
Also, you're using the same pins for sensors as well as buttons, which is likely to result in problems.

I would propose to use a GPIO expander like the MCP23017; this would solve your problem.

---

<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 29, 2022, 6:54am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/9 "2022-03-29T06:54:36Z")

</div>

Hi,  
As @anon35827816 said a port expander like MCP23017 just to control your LED indicators would solve your problem.  
A proper schematic would also make your circuit easier to read, having labels covering wiring does not make the diagram very readable.

Hand draw a schematic, carefully and post an image, using proper symbols for switches, LEDs and power supply components.  
Include component labels and pin names.

Thanks.. Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 29, 2022, 7:09am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/10 "2022-03-29T07:09:44Z")

</div>

if you have an account on Tinkercad account, you can see, code, circuit diagram also,

here is the link  
[Tinkercad](https://www.tinkercad.com/things/9sJmnh4UgkP-test-1/editel?sharecode=P-l_SYMMAD2pvsJjShOhJ4L037eRNHRLhxzdLvhfys0)

it is an Online Simulator, its working well, but the problem i said, working with physical circuit.

better if you could create an account, and see that link, please

thank you so much

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [March 29, 2022, 7:18am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/11 "2022-03-29T07:18:43Z")

</div>

> [@sanjeewamdn](#):
>
> its working well

Not really, it's created an unreadable schematic so far.

Please just do what @TomGeorge said above.

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [March 29, 2022, 7:19am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/12 "2022-03-29T07:19:02Z")

</div>

> [@sanjeewamdn](#):
>
> take values HIGH and LOW properly, via these pin No 0, 1 and 2, but sometimes not take HIGH/LOW properly after POWER ON 3- 5 minutes later,

If the inputs are operating properly for several minutes when first powered on, then I would suspect that the problem is in the code, not the wiring or the use of pins 0 and 1 for inputs.

I hope your actual circuit has resistors in series with the LEDs, otherwise you will damage the LED and/or the UNO.

---

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 29, 2022, 7:28am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/13 "2022-03-29T07:28:33Z")

</div>

> [@david\_2018](#):
>
> If the inputs are operating properly for several minutes when first powered on, then I would suspect that the problem is in the code, not the wiring or the use of pins 0 and 1 for inputs.

when i pressed reset on the Uno Board, then working well again..

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [March 29, 2022, 7:42am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/14 "2022-03-29T07:42:40Z")

</div>

I'll say it again: those buttons aren't wired in any logical way. It just doesn't make sense.  
All you need for a button is to connect one pin to GND, the other to an input pin, and configure the input as INPUT\_PULLUP. That's all. It will read HIGH by default and LOW if pressed.

Coincidentally this will free up the pins that are now apparently shared between sensors and buttons, so you can dedicate them to sensors. With the caveat some of them are still part of the Serial UART so you cannot debug this way, which doesn't help.

---

<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 29, 2022, 10:18am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/15 "2022-03-29T10:18:27Z")

</div>

Hi,  
Your Tinker diagram, different to original .

 ![Untitled444](https://europe1.discourse-cdn.com/arduino/original/4X/3/8/4/384ad9571f87e803bfb5151d1d9374d05711d0a9.jpeg)

1. Where are your current limit resistors for ALL your LEDS?
2. What are the 10K resistors for between the buttons and input D3, D4 and D5 respectively.
3. Why are you using 1K pullup and pull down resistors rather than 10K?

Have you tried any of this in the real world?

Tom.... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![Perehama](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perehama/32/256713_2.png) [@Perehama](https://forum.arduino.cc/u/Perehama)\
**Post date:** [March 29, 2022, 10:45am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/16 "2022-03-29T10:45:13Z")

</div>

Drive those LEDs through a CD4094 or similar shift register and ULN2803 or similar current sink array. 40 cents, 8 IO.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [March 29, 2022, 10:55am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/17 "2022-03-29T10:55:03Z")

</div>

@sanjeewamdn

Did all the problems from your previous thread on this project get solved?

Did all the questions we asked on your previous thread get answers from you?

I notice right away again, as have others, your odd circuitry…

And I too recommend the addition of hardware to provide more i/o pins or moving to an Arduino board that has more than enough already.

a7

---

<div class="post-metadata">

**Author:** ![dlloyd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dlloyd/32/751911_2.png) [@dlloyd](https://forum.arduino.cc/u/dlloyd)\
**Post date:** [March 29, 2022, 12:32pm UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/18 "2022-03-29T12:32:55Z")

</div>

Save 2 inputs (pins 0 and 1) by using a 3-bit [R2R ladder](https://www.tek.com/en/blog/tutorial-digital-analog-conversion-r-2r-dac) connected to an analog input for your digital inputs `waterLevelSensorLow`, `waterLevelSensorMedium` and `waterLevelSensorHigh`. Then update your code for water level detection.

Your code from TINKERCAD:

```cpp
#include <EEPROM.h>

const unsigned long debounceDelay = 50;

const int waterLevelSensorLow = 0;
const int waterLevelSensorMedium = 1;
const int waterLevelSensorHigh = 2;

const int btnPause = 3;
int btnPauseState;
int lastBtnPauseState = LOW;
unsigned long lastBtnPauseDebounceTime = 0;

const int btnAutoManual = 4;
int btnAutoManualState;
int lastBtnAutoManualState = LOW;
unsigned long lastBtnAutoManualDebounceTime = 0;

const int btnSemiAuto =5;
int btnSemiAutoState;
int lastSemiAutoState = LOW;
unsigned long lastBtnSemiAutoDebounceTime = 0;

const int ledWaterLevelLow = 6;
const int ledWaterLevelMedium = 7;
const int ledWaterLevelHigh = 8;

const int ledAuto = 9;
const int ledManual = 10;
const int ledPause = 13;
const int ledSemiAuto = A0;

const int waterMotor = A2;
const int buzzer = A3;

const int sumpTankLowSensor = A4;
const int ledSumpTankLow = A5;

const int ledRunning = 12;
const int ledStandby = 11;
int standbyLedBrightness = 0;
int standbyLedFadeAmount = 2;

const int ledTimer = A1;

bool isPaused = false;
bool isAuto = true;
bool isSemiAuto = false;

bool isPauseLedOn = false;
bool isRunningLedOn = false;
bool isTimerLedOn = false;

const long ledBlinkingTimeInMilliSeconds = 200;
long lastPauseLedChangedTime = 0;
long lastRunningLedChangedTime = 0;
long lastTimerLedChangedTime = 0;

//Water Level 0 = Empty, 1 = LOW, 2 = MEDIUM, 3 = HIGH
int waterLevel = -1;
int lastWaterLevel = -1; 

bool runWaterMotor = false;
bool isWaterMotorRunning = false;

bool isSumpTankLow = false;

long motorStarTime = 0;
//5 minutes
const long motorMaxRunTimeInMilliseconds = 300000;

void setup() {
  
  Serial.begin(9600);
  
  pinMode(btnPause, INPUT);
  pinMode(btnAutoManual, INPUT);
  pinMode(btnSemiAuto, INPUT);
  
  pinMode(ledPause, OUTPUT);
  pinMode(ledAuto, OUTPUT);
  pinMode(ledManual, OUTPUT);
  pinMode(ledSemiAuto, OUTPUT);
  pinMode(ledWaterLevelLow, OUTPUT);
  pinMode(ledWaterLevelMedium, OUTPUT);
  pinMode(ledWaterLevelHigh, OUTPUT);
  
  pinMode(waterLevelSensorHigh, INPUT);
  pinMode(waterLevelSensorMedium, INPUT);
  pinMode(waterLevelSensorLow, INPUT);
  
  pinMode(waterMotor, OUTPUT);
  pinMode(buzzer, OUTPUT);
  
  pinMode(sumpTankLowSensor, INPUT);
  pinMode(ledSumpTankLow, OUTPUT);
  
  pinMode(ledRunning, OUTPUT);
  pinMode(ledStandby, OUTPUT);
  
  pinMode(ledTimer, OUTPUT);
  
  readFromEEPROM();
  
  buzzerBeep();
  buzzerBeep();
}

void readFromEEPROM() {
  
  bool isEEPROMUpdated;
  EEPROM.get(EEPROM.length() - 1, isEEPROMUpdated);
  
  if (!isEEPROMUpdated){
    return;
  }
  
  int eeAddress = 0;
  
  EEPROM.get(eeAddress, isPaused);
  eeAddress += sizeof(bool);
    
  EEPROM.get(eeAddress, isAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, isSemiAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, lastWaterLevel);
  eeAddress += sizeof(int);
  
  EEPROM.get(eeAddress, runWaterMotor);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, isWaterMotorRunning);
  eeAddress += sizeof(bool);
  
  EEPROM.get(eeAddress, motorStarTime);
  eeAddress += sizeof(long);
}

void loop() {
  
  updateSumpTankWaterStatus();
  updateWaterLevel();
  updateButtonStatuses();
  handleWaterMotor();
  updateEEPROM();
}

void updateSumpTankWaterStatus() {
  int status = digitalRead(sumpTankLowSensor);
  
  isSumpTankLow = !status;
  digitalWrite(ledSumpTankLow, isSumpTankLow);
}

void updateWaterLevel() {
  setWaterLevel();
  handleWaterLevelLed();
}

void setWaterLevel() {
  
  int low = digitalRead(waterLevelSensorLow);
  int medium = digitalRead(waterLevelSensorMedium);
  int high = digitalRead(waterLevelSensorHigh);
  
  int calculatedWaterLevel;
  
  if (low == LOW && medium == LOW && high == LOW) {
  	calculatedWaterLevel = 3;
  } else if (low == LOW && medium == LOW && high == HIGH) {
  	calculatedWaterLevel = 2;
  } else if (low == LOW && medium == HIGH && high == HIGH) {
  	calculatedWaterLevel = 1;
  } else if (low == HIGH && medium == HIGH && high == HIGH) {
  	calculatedWaterLevel = 0;
  } else {
  	calculatedWaterLevel = -1;
  }
  
  if(waterLevel != calculatedWaterLevel) {
    
    if(lastWaterLevel == -1) {
      lastWaterLevel = calculatedWaterLevel;
    } else {
      lastWaterLevel = waterLevel;
    }
    
    waterLevel = calculatedWaterLevel;
  }
}

void handleWaterLevelLed() {
    
  if (waterLevel == 1) {
    
    digitalWrite(ledWaterLevelHigh, LOW);
    digitalWrite(ledWaterLevelMedium, LOW);
    digitalWrite(ledWaterLevelLow, HIGH);
    
  } else if (waterLevel == 2) {
    
    digitalWrite(ledWaterLevelHigh, LOW);
    digitalWrite(ledWaterLevelMedium, HIGH);
    digitalWrite(ledWaterLevelLow, HIGH);
    
  } else if (waterLevel == 3) {
    
    digitalWrite(ledWaterLevelHigh, HIGH);
    digitalWrite(ledWaterLevelMedium, HIGH);
    digitalWrite(ledWaterLevelLow, HIGH);
  
  } else {
  
    digitalWrite(ledWaterLevelHigh, LOW);
    digitalWrite(ledWaterLevelMedium, LOW);
    digitalWrite(ledWaterLevelLow, LOW);
  }
}

void updateButtonStatuses() {
  setAutoStatus();
  setPauseStatus();
  setSemiAutoStatus();
  
  handleAutoManualLeds();
  handlePauseLed();
  handleSemiAutoLed();
}

void setAutoStatus() {
  
  int reading = digitalRead(btnAutoManual);
  
  if (reading != lastBtnAutoManualState) {
    lastBtnAutoManualDebounceTime = millis();
  }
  
  if ((millis() - lastBtnAutoManualDebounceTime) > debounceDelay) {
    if (reading != btnAutoManualState) {
      btnAutoManualState = reading;

      if (btnAutoManualState == HIGH) {
        isAuto = !isAuto;
        buzzerBeep();
      }
    }
  }
  lastBtnAutoManualState = reading;
}

void handleAutoManualLeds() {
  
  bool isAutoLedOn = isAuto && !isPaused;
  digitalWrite(ledAuto, isAutoLedOn);
  
  bool isManualLedOn = !isAuto && !isPaused;
  digitalWrite(ledManual, isManualLedOn);
}

void setPauseStatus() {
  
  int reading = digitalRead(btnPause);
  
  if (reading != lastBtnPauseState) {
    lastBtnPauseDebounceTime = millis();
  }
  
  if ((millis() - lastBtnPauseDebounceTime) > debounceDelay) {
    if (reading != btnPauseState) {
      btnPauseState = reading;

      if (btnPauseState == HIGH) {
        isPaused = !isPaused;
      }
    }
  }
  lastBtnPauseState = reading;
}

void handlePauseLed() {
    
  if(isPaused) {
    
    long timeElapsedAfterLastChange = millis() - lastPauseLedChangedTime;
    
    if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
      
      isPauseLedOn = !isPauseLedOn;
      digitalWrite(ledPause, isPauseLedOn);
      lastPauseLedChangedTime = millis();
    }
  } else {
  
    digitalWrite(ledPause, LOW);
    isPauseLedOn = false;
  } 

  if(isPauseLedOn) {
    buzzerBeep();
  }
}

void setSemiAutoStatus() {
  
  int reading = digitalRead(btnSemiAuto);
  
  if (reading != lastSemiAutoState) {
    lastBtnSemiAutoDebounceTime = millis();
  }
  
  if ((millis() - lastBtnSemiAutoDebounceTime) > debounceDelay) {
    if (reading != btnSemiAutoState) {
      btnSemiAutoState = reading;

      if (btnSemiAutoState == HIGH) {
        isSemiAuto = !isSemiAuto && (waterLevel < 3 && waterLevel > 0);
        buzzerBeep();
      }
    }
  }
  lastSemiAutoState = reading;
  
  if (waterLevel == 3) {
    isSemiAuto = false;
  }
}

void handleSemiAutoLed() {
  digitalWrite(ledSemiAuto, isSemiAuto && isAuto && !isPaused);
}

void handleWaterMotor() {
  setWaterMotorRunStatus();
  
  if(isWaterMotorRunning != runWaterMotor) {
    
    if(runWaterMotor) {
      buzzerBeep();
      buzzerBeep();
      buzzerBeep();
      
      motorStarTime = millis();
    }
    
    digitalWrite(waterMotor, runWaterMotor);
    isWaterMotorRunning = runWaterMotor;
    
    if(!runWaterMotor) {
      buzzerBeep();
      buzzerBeep();
      buzzerBeep();
      
      motorStarTime = 0;
    }
  }
  
  handleRunningLed();
  handleSandbyLed();
  handleTimerLed();
}

void setWaterMotorRunStatus() {
  
  bool isWaterLevelLow = waterLevel == 0;
  bool isWaterLevelLowToHigh = waterLevel < 3 && waterLevel > 0;
  bool isTankFillingUp = isWaterLevelLowToHigh && waterLevel > lastWaterLevel;
  bool runMotorAutoMode = isAuto && (isWaterLevelLow || isTankFillingUp);
  bool runMotorSemiAutoMode = isSemiAuto && (isWaterLevelLowToHigh || isTankFillingUp);
  bool isTimerUp = isAuto && (millis() - motorStarTime) >= motorMaxRunTimeInMilliseconds;
  
  
  runWaterMotor = (runMotorAutoMode || runMotorSemiAutoMode || !isAuto) && !isPaused && !isSumpTankLow && !isTimerUp;
}

void handleRunningLed() {
    
  if(isWaterMotorRunning) {
    
    long timeElapsedAfterLastChange = millis() - lastRunningLedChangedTime;
    
    if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
      
      isRunningLedOn = !isRunningLedOn;
      digitalWrite(ledRunning, isRunningLedOn);
      lastRunningLedChangedTime = millis();
    }
  } else {
  
    digitalWrite(ledRunning, LOW);
    isRunningLedOn = false;
  } 

  if(isRunningLedOn) {
    buzzerBeep();
  }
}

void handleSandbyLed() {
  
  if(!isWaterMotorRunning && (isAuto || isSemiAuto) && !isPaused) {      
  	
    analogWrite(ledStandby, standbyLedBrightness);
  	standbyLedBrightness = standbyLedBrightness + standbyLedFadeAmount;

  	if (standbyLedBrightness <= 0 || standbyLedBrightness >= 255) {
    	standbyLedFadeAmount = -standbyLedFadeAmount;
  	}
    
  	delay(30);
    
  } else {
    digitalWrite(ledStandby, LOW);
  }
}

void handleTimerLed() {
  
  if(isWaterMotorRunning && motorStarTime > 0 && isAuto){
    
    long timeElapsedAfterLastChange = millis() - lastTimerLedChangedTime;
    
    if(timeElapsedAfterLastChange > ledBlinkingTimeInMilliSeconds) {
      
      isTimerLedOn = !isTimerLedOn;
      digitalWrite(ledTimer, isTimerLedOn);
      lastTimerLedChangedTime = millis();
    }
  } else {
     digitalWrite(ledTimer, LOW);
     isTimerLedOn = false;
  }
}

void buzzerBeep() {
  const int buzzerTime = 250;
  
  digitalWrite(buzzer, HIGH);
  delay(buzzerTime);
  digitalWrite(buzzer, LOW);
  delay(buzzerTime);
}

void updateEEPROM() {
  
  int eeAddress = 0;
  
  EEPROM.update(eeAddress, isPaused);
  eeAddress += sizeof(bool);
    
  EEPROM.update(eeAddress, isAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, isSemiAuto);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, lastWaterLevel);
  eeAddress += sizeof(int);
  
  EEPROM.update(eeAddress, runWaterMotor);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, isWaterMotorRunning);
  eeAddress += sizeof(bool);
  
  EEPROM.update(eeAddress, motorStarTime);
  eeAddress += sizeof(long);
  
  EEPROM.update(EEPROM.length() - 1, true);
}

```

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [March 29, 2022, 1:22pm UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/19 "2022-03-29T13:22:17Z")

</div>

Remove Serial.begin(), you do not want to initialize pins 0 and 1 for serial communications when you are using them for something else.

How are you driving the motor? What type battery are you using? Electrical interference from the motor is a common cause of problems.

---

<div class="post-metadata">

**Author:** ![sanjeewamdn](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sanjeewamdn](https://forum.arduino.cc/u/sanjeewamdn)\
**Post date:** [March 30, 2022, 4:51am UTC](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658/20 "2022-03-30T04:51:08Z")

</div>

No,

if All are OK, we can use relay for water motor switching by using Transistor connected with assigned Arduino motor pin know...?

[Next page](https://forum.arduino.cc/t/digital-pin-0-and-1-programming-problem/974658.md?page=2)
