Analog value issue reading the analog pins on Arduino 2560.

I am using an Arduion 2560 as a tester for a printed circuit board. Currently, I do not have a design PCB or bread board to attach it to the unit under test. I am basically experimenting with the AD feature to see how well it works.

I have a small bread board (an Arduino 2560 bread board) attached to the device along with the Sparkfun 16 character LCD. I am using the serial pins 0 and 1 to talk to the LCD at a baud rate of 9600. I am using the Arduino LCD library to display my data.

All of this seems to be working well.

Now currently I am trying to read pin A0. With no signal or voltage applied it reads around 400 counts and floats around that as expected. When I apply +0vdc (power supply return) to the A0, I get 0 (as expected). I then apply +5vdc to A0 and I get 1023 (as expected).

I then physically disconnect the +5vdc and I get a floating integer number around 3000 to 5000 counts (a little weird). I then physically reapply the ground, and the reading stops and is steady at some value around 400 to 900 counts.

I've tried putting a delay before and after reading and I also read the value twice before I display the data on the LCD screen.

Currently, I am using Window's 7 as my operating system.

Here is a clip of my code (also attached) where I am reading the A/D.

This clip is in file "Read_A_to_D" under the function "sample_and_wait".

//---------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------  Sample and Wait  ------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------

void sample_and_wait(int address, int source)
{
  int button_press = 1;
  int first_button_press = 1;
  int second_button_press = 1;
  int spacer = 0;
  int my_sample = 0;
  

  clearScreen();
  LCD.print ("addrs =  ");                                   // This will display the data you want to look at.
  LCD.print (address,DEC);
  moveRight();
  moveRight();
  LCD.print(source,DEC);
  selectLineTwo();
  
  switch (address)
        {
          case 0:
              {
                LCD.print ("E MON:    ");
                //LCD.print (voltage_monitoring,DEC); 
                break;
              }
          
          case 1:
                {
                  LCD.print ("C MON Fsd:");
                  //LCD.print (current_monitoring,DEC); 
                  break;
                }
             
          case 2:
                {
                  LCD.print ("TPWR Fsd:");
                  //LCD.print (Tester_Power_Fused,DEC); 
                  break;
                }    
    
          
           case 3:
                {
                  LCD.print ("TPWR UnFs ");
                  //LCD.print (Tester_Power_Unfused,DEC); 
                  break;
                }  
                
                
            case 4:
                {
                  LCD.print ("UUT Fsd:  ");
                  //LCD.print (UUT_Power_Fused,DEC); 
                  break;
                }       
          
          
          
           case 5:
                {
                  LCD.print ("UUT UnFsd:");
                  //LCD.print (UUT_Power_Unfused,DEC); 
                  break;
                }  
                
           case 6:
                {
                  LCD.print ("+12vdc    ");
                  //LCD.print (pos_12_vdc,DEC); 
                  break;
                }  
                
           case 7:
                {
                  LCD.print ("+9vdc     ");
                  //LCD.print (pos_9vdc,DEC); 
                  break;
                }   
           
           
            case 8:
                {
                  LCD.print ("+3.3vdc   ");
                  //LCD.print (pos_3vdc,DEC); 
                  break;
                }   
            
             case 9:
                {
                  LCD.print ("Chas In   ");
                  //LCD.print (Chassis_Input,DEC); 
                  break;
                }    
              
              
               case 10:
                {
                  LCD.print ("Chas Out  ");
                  //LCD.print (Chassis_Controller_Out,DEC); 
                  break;
                }  
              
              
               case 11:
                {
                  LCD.print ("Chas A    ");
                  //LCD.print (Chassis_UUT_A,DEC); 
                  break;
                } 
             
              case 12:
                {
                  LCD.print ("Chas B    ");
                  //LCD.print (Chassis_UUT_B,DEC); 
                  break;
                }  
             
              case 13:
                {
                  LCD.print ("Chas C    ");
                  //LCD.print (Chassis_UUT_C,DEC); 
                  break;
                }  
             
        }
             
                
  
  while (button_press > 0)                                                                
        { 
          my_sample =analogRead(source); 
          delay (10);
          my_sample =analogRead(source);
          
          selectLineTwo();
          spacer = 0;
          while (spacer < 10) 
                 {
                   moveRight();
                   ++spacer;
                 }   
          LCD.print (my_sample,DEC);        
         
         first_button_press = digitalRead(response_button); 
         delay (100);                                                                     
         second_button_press = digitalRead(response_button);
         if ((first_button_press == LOW)&& (second_button_press== LOW)) button_press = 0;
                                     
         }
   while (!digitalRead(response_button));  
   
 
}

014-xxxx test software.zip (34.8 KB)

You are writing "500" on top of "1023", giving "5003" or similar. Put spaces at the end
of your print or clear the whole line first.