digitalRead stays high when using ethernet control

Hello, I'm a student working on my final project and it's the first time i'm using an arduino. My project is a robot that runs automaticaly with a laser scanner and manualy with push buttons. The auto mode and the man mode work fine when in there own documents but when combined the manual mode goes bananas. I traced the problem to the line Ethernet.begin(mac,ip);, if i delete this line the man mode works fine but when i leave it in there are 2 digital inputs that remain high even when they are not triggert by the fysical button. These inputs are "int voor = digitalRead(DRUKKNOPvooruit);" and " int rechts = digitalRead(DRUKKNOPrechts);".

Does anybody have a idea how i can fix this?

As you can see my code is in dutch so please excuse me for any typo's.

Thanks in advance,

Joris

void setup()
{ 
  Serial.begin(9600);                          // snelheid van de seriële communicatie vastleggen tussen arduino en pc 
  pinMode(STOPvoorwielrechts, OUTPUT);         // deze klemmen zullen een waarde uitsturen
  pinMode(STOPvoorwiellinks, OUTPUT);
  pinMode(STOPachterwiellinks, OUTPUT);
  pinMode(STOPachterwielrechts, OUTPUT);
  pinMode(ACHTERUITvoorwielrechts, OUTPUT);
  pinMode(ACHTERUITvoorwiellinks, OUTPUT);
  pinMode(ACHTERUITachterwiellinks, OUTPUT);
  pinMode(ACHTERUITachterwielrechts, OUTPUT);
  pinMode(DRUKKNOPvooruit, INPUT);
  pinMode(DRUKKNOPachteruit, INPUT);
  pinMode(DRUKKNOPlinks, INPUT);
  pinMode(DRUKKNOPrechts, INPUT);
  pinMode(schakelaar, INPUT);
  
  digitalWrite(STOPvoorwielrechts, HIGH);   
  digitalWrite(STOPvoorwiellinks, HIGH);
  digitalWrite(STOPachterwiellinks, HIGH);
  digitalWrite(STOPachterwielrechts, HIGH);
  
  Ethernet.begin(mac,ip);
  delay(2000);
  
  Serial.println("connecting...");
  
  retry:
  
  if (client.connect(server, 2111))
    { 
      Serial.println("connected");
    }
  else 
    {
      Serial.println("connection failed");
      goto retry;
    }
}                                              
.....

void loop()
  {
      
  int manueel = digitalRead(schakelaar);

if (manueel == HIGH)
      {  
     // Serial.println( "MANUELE mode" );
      
      
      snelheid = 80;  
      int voor = digitalRead(DRUKKNOPvooruit);
      int achter = digitalRead(DRUKKNOPachteruit);
      int links = digitalRead(DRUKKNOPlinks);
      int rechts = digitalRead(DRUKKNOPrechts);
      
      if(rechts == LOW && links == LOW && voor == LOW && achter == LOW)    
      { 
        stilstaan(); 
      }
      
      if(voor == HIGH)
      {   
        delay(250);
        rechtdoor(); 
        Serial.println( "1" );
        
      }
      
      
      if(achter == HIGH)
      { 
        delay(250);
        achteruit();
        
      }
    
     
      if(links == HIGH)
      { 
        delay(250);
        naarLinks();
        
      }
    
     
      if(rechts == HIGH)
      {
        delay(250);
        naarRechts();
        Serial.println( "2" );
        
      }

      }

What pins are you trying to read from? The Ethernet shield uses pins 4, 10, 11, 12, and 13.

I'm working with an arduino mega 2560. The pins i'm using are: const int DRUKKNOPachteruit = 50; const int DRUKKNOPlinks = 52; const int DRUKKNOPrechts = 51; const int schakelaar = 44;

Drukknop = pushbutton Schakelaar = switch

I'm working with an arduino mega 2560. The pins i'm using are: const int DRUKKNOPachteruit = 50; const int DRUKKNOPlinks = 52; const int DRUKKNOPrechts = 51;

Which are the Mega's SPI pins.

I'm affraid, I don't know what SPI pins are ?

I'm affraid, I don't know what SPI pins are ?

There is no reason to be afraid. Ignorance can be cured.

SPI is how the Arduino and the Ethernet shield (and a lot of other devices) communicate. When you have a device attached that uses SPI, you can not use those same pins for other purposes.

Thanks I understand. But where can I find what numbers are mine SPI pins?

But where can I find what numbers are mine SPI pins?

On the home page, there is a Products link. On that page, there is a picture of each board that is a link. On each of those links, there is a section that talks about SPI pins. For the Mega, it says:

SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication using the SPI library. The SPI pins are also broken out on the ICSP header, which is physically compatible with the Uno, Duemilanove and Diecimila.

Thank you very much! Now I understand why my manual program doesn't work.