Webserver with alarm function

Hi Guys …

I have the Problem, that the buzzer always Plays at loading & refreshing the page but i want
that it only Plays the Sound when the button ON is pressed … it should be a Problem in the following Code:

  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi


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

#include <pitches.h>

int pinDHT11 = 7;
SimpleDHT11 dht11;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192, 168, 0, 20);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

String readString; 

int melody[] = {
int duration = 500;  // 500 miliseconds
int buzzer = 8 ;// setting controls the digital IO foot buzzer 

void setup() {
  // Open serial communications and wait for port to open:
pinMode (buzzer, OUTPUT) ;// set the digital IO pin mode, OUTPUT out of Wen 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  Serial.print("server is at ");

void loop() {

byte temperature = 0;
  byte humidity = 0;
  byte data[40] = {0};
  if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
    Serial.print("Read DHT11 failed");

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

       //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 

        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println("<!DOCTYPE HTML>");
          client.println("<body bgcolor=\"1d092c\">");
    client.println("<center><img src=\"http://edvrsa.com/edvrsa_raumkontrolle.jpg\">");
          // output the value of each analog input pin
            client.println("<b><font color=\"white\"><img src=\"http://edvrsa.com/temperatur.jpg\">Temperatur ist: ");
            client.println(" °C
            client.println("<img src=\"http://edvrsa.com/luftfeuchtigkeit.jpg\"> Luftfeuchtigkeit ist: ");
            client.println(" %r.F.
            client.println("Es wird momentan in der Lautstaerke geredet: ");
            client.println("<input type=button value=ON onmousedown=location.href='/?on8'>"); 

        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:


   ///////////////////// control arduino pin
          if(readString.indexOf('8') >0)//checks for 2
for (int thisNote = 0; thisNote < 8; thisNote++) {
    // pin8 output the voice, every scale is 0.5 sencond
    tone(8, melody[thisNote], duration);
    // Output the voice after several minutes


    Serial.println("client disconnected");
          if(readString.indexOf('8') >0)//checks for 2

No, it doesn’t.

Most of your comments are equally wrong. If you are not going to keep the useless comments up to date, get rid of them.

I do not see a relationship between readString containing the character ‘8’ and the ON button having been pressed. Your comments, and your post, should describe what the program should do, and should clearly state that relationship.