usage of digitalRead()

Hi!

I would like to jump in my function, if there is a contact on pin 7.
The client should call the following script on my web server: http://192.168.1.10:81/index.php
The problem is that the Arduino reports also on my server if no one presses the button.
Did I made ??a mistake in the implementation?

Greetings,
Philip

#include <SPI.h>
#include <Ethernet.h>

const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin =  9; // the number of the LED pin

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x5D, 0x1C }; // mac addr. Arduino
byte ip[] = { 192, 168, 1, 31 }; // local IP Arduino
byte server[] = { 192, 168, 1, 10 }; // IP web server

EthernetClient client;

void setup()
{
	pinMode(ledPin, OUTPUT); // initialize the LED pin as an output      
	pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:     
	Ethernet.begin(mac, ip);
}

void loop()
{
	if (digitalRead(buttonPin) == HIGH)
	{
		delay(1000);
		digitalWrite(ledPin, HIGH); //LED on
    
		if (client.connect(server, 81))
		{
			client.println("GET index.php");
			client.println("User-Agent: Arduino");
			client.println();
			delay(1000);
			while (client.available()) 
			{
				char c = client.read();
			}
			if (!client.connected())
			{
				client.stop();
			}
		}
		else
		{
			//could not connect to IPS
		}
	}
	else
	{
		digitalWrite(ledPin, LOW); //LED off 
	}  
}

How is your button connected?
Do you have a pulldown resistor?

I've attached my diagram.
I don't use the LED.

Source:
http://www.katun.ch/2011/02/01/diy-turklingel-push-notification-fur-das-iphone/

Doorbell.png

Get rid of the resistor. Use the internal pullup resistor, instead. Connect one side of the switch to the digital pin. Connect the other side to ground.

	pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
        digitalWrite(buttonPin, HIGH); // Turn on pullup reistor

Then, HIGH will be released, and LOW will be pressed.