Floating pins on Arduino Mega 2560 Board

Hi there, I am working on a project over Arduino Mega 2560, just to read the pins status high and low with the help of some switches. But the pins are floating. On Arduino Forum, i found, we can use internal pullup resistors or external pullup/down resistors to stop the interference. Pins (22 to 50) are used with digitalRead(). But still observing the same issue. in pullup, Serial monitor goes freeze. Then i have to unpulg and plug again the board to use it. in external pull down, still pins are floating. (resistance values used in between 2K to 6K).

Please Help me in this, how to remove the interference.

You have some stuff wired to the Arduino, in some mysterious fashion.

You have some code that you didn't bother to post.

Please Help me in this, how to remove the interference.

Common sense, realistic expectations, and proper code.

hemants: Please Help me in this, how to remove the interference.

PaulS: Common sense, realistic expectations, and proper code.

@OP 1. Remove all wiring from these IO pins: 22 - 50. 2. Press RESET Button of Arduino. 3. Use DVM; measure and record the voltage at DPin-22. 4. Connect a pull-down resistor (2.2k/4.7K) with DPin-22. 5. Use DVM; measure and record the voltage at DPin-22. The voltage should be around ~=0V. If not, it must be below 0.9V and not fluctuating.

6. Connect one end of a PUSH with DPin-22. Connect the other end of the PUSH switch with 5V. Connect a DVM with DPin-22. Press the switch. The DVM should read ~5V. If not, it must be above 4.2V and not fluactuating.

7. Similarly, deal with DPin-23.

Is there any floating condition on DPin-22 or DPin-23?

@Golam Mostafa.
Thank you for suggestion, let me try it once.

Please find the code as below:

#include<string.h>

#define MESSAGE "Arduino"

// Current and Previous value storage for digital pins
int ab, prev_ab = 1;
int bc, cd, eff_cd, prev_eff_cd = 0;
int lde, rde, eff_de, prev_eff_de = 0;
int ef_low, ef_high, eff_ef, prev_eff_ef = 0;
int fg_low, fg_high, eff_fg, prev_eff_fg = 0;

void setup() {

  // Setting the intial mode of digital input pins
  for (int i = 22; i <= 30; i++)
  {
    pinMode(i, INPUT_PULLUP);
    digitalWrite(i, HIGH);
  }

  // Beginning serial communication
  Serial.begin(9600);
  // Handshake MESSAGE with the PC
  char buf[8];
  int res;
  Serial.print(MESSAGE);
  do {
    res = Serial.readBytes(buf, sizeof(buf));
    buf[res] = 0;
  } while (strcmp(buf, MESSAGE) != 0);
}

void loop() {
  char strBuf[1024];
  String outputStr = String("") ;

  // Read the digital input pins and send the values to the PC
  ab = digitalRead(22);
  if (ab != prev_ab)
  {
    outputStr.concat("<22,");
    if ( ab == 0 )
      outputStr.concat("1");
    else
      outputStr.concat("0");
    outputStr.concat(">");
    prev_ab = ab;
  }

  bc = digitalRead(23);
  cd = digitalRead(24);
  if (cd == 0)
  {
    eff_cd = 1;
  } else if (bc == 1)
  {
    eff_cd = 0;
  } else {
    eff_cd = -1;
  }
  if (eff_cd != prev_eff_cd)
  {
    outputStr.concat("<23,");
    if ( eff_cd == 1 )
      outputStr.concat("1");
    else if (eff_cd == 0)
      outputStr.concat("0");
    else
      outputStr.concat("-1");
    outputStr.concat(">");
    prev_eff_cd = eff_cd;
  }

  lde = digitalRead(25);
  rde = digitalRead(26);
  if (lde == 1 && rde == 1)
  {
    eff_de = 0;
  } else if (lde == 0 && rde == 1)
  {
    eff_de = 1;
  } else if (lde == 1 && rde == 0)
  {
    eff_de = -1;
  } else {
    eff_de = 2;
  }
  if (eff_de != prev_eff_de)
  {
    outputStr.concat("<25,");
    if ( eff_de == 1 )
      outputStr.concat("1");
    else if (eff_de == 0)
      outputStr.concat("0");
    else if (eff_de == -1)
      outputStr.concat("-1");
    else
      outputStr.concat("2");
    outputStr.concat(">");
    prev_eff_de = eff_de;
  }

  // Read the digital ef values and send the effective ef value to the PC
  ef_low = digitalRead(27);
  ef_high = digitalRead(28);
  if (ef_low == 1 && ef_high == 1)
  {
    eff_ef = 0;
  } else if (ef_low == 0 && ef_high == 1)
  {
    eff_ef = 2;
  } else if (ef_low == 1 && ef_high == 0)
  {
    eff_ef = 1;
  }
  if (eff_ef != prev_eff_ef)
  {
    outputStr.concat("<27,");
    if ( eff_ef == 1 )
      outputStr.concat("1");
    else if (eff_ef == 0)
      outputStr.concat("0");
    else
      outputStr.concat("2");
    outputStr.concat(">");
    prev_eff_ef = eff_ef;
  }

  // Read the fg input values and send the effective fg value to the PC
  fg_low = digitalRead(29);
  fg_high = digitalRead(30);
  if (fg_low == 1 && fg_high == 1)
  {
    eff_fg = 0;
  } else if (fg_low == 0 && fg_high == 1)
  {
    eff_fg = 2;
  } else if (fg_low == 1 && fg_high == 0)
  {
    eff_fg = 1;
  } else if (fg_low == 1 && fg_high == 1)
  {
    eff_fg = 2;
  }
  if (eff_fg != prev_eff_fg)
  {
    outputStr.concat("<29,");
    if ( eff_fg == 1 )
      outputStr.concat("1");
    else if (eff_fg == 0)
      outputStr.concat("0");
    else
      outputStr.concat("2");
    outputStr.concat(">");
    prev_eff_fg = eff_fg;
  }
 
  if( outputStr.length() > 0 )
  {
    outputStr.concat("*");
    outputStr.toCharArray(strBuf, 1024);
    Serial.print(strBuf);
  }
 }

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

@Golam Mostafa.

Dear Sir,

i tried as per your feedback but no floating condition of pin is there individually. If i am turning any pin LOW to HIGH, then pins are floating randomly. Its not like that its floating without any interference. for eg. if i am switching pin 23 LOW to HIGH then sometimes pin 27, sometimes pin 43 etc are floating but not the pin 23, as its already HIGH.

Dear team,

I am new to arduino.
As per the forum and guide, i have connected the circuit as per attachment, by pull up resistors to control the floating of the pins
But still having the same floating pins issue whenever i switch on/off any of the switch the other pin shows the float issue.
Connected around 17 switches all as per the image to arduino pins from 22 to 38.

Code used is as per following:

int prevPinVal[17];

void setup() {
 // put your setup code here, to run once:
 for(int i=22; i<=38;i++)
 {
   pinMode(i, INPUT);
   prevPinVal[i-22] = digitalRead(i);
 }
 Serial.begin(9600);

}

void loop() {
 // put your main code here, to run repeatedly:
 int pinVal;

 for(int i=22; i<=38; i++)
 {
   pinVal = digitalRead(i);
   if(pinVal != prevPinVal[i-22])
   {
     Serial.print("<");
     Serial.print(i);
     Serial.print(",");
     Serial.print(pinVal);
     Serial.print(">");
   }
   prevPinVal[i-22] = pinVal;
 }
 Serial.println("");
 delay(1000);

}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

@hemants, please do not cross-post. Threads merged.