user2884: I've done this laser trip wire:
http://www.instructables.com/id/Another-Arduino-Laser-Tripwire/
Got it working, and now I'd like to send info to analytics - to measure how many times I enter the kitchen...
I tried to take bits of code and add it to my code from:
http://bigsnarf.wordpress.com/2013/12/24/arduino-sensor-python-and-google-analytics/
and one more which I can't post due to permissions....
but neither will work and adding this code breaks my basic functionality (I know as I measure it via the buzzer, it stops responding once I add this new code...
Is there anyone able to help?

Here is my basic working code for the laser trip wire that makes buzzer noise if someone walks through it:
/*
Jonathan Robson Feb 09.
Laser tripwire activates a buzzer. adapted from
http://www.instructables.com/id/Arduino_Laser_Tripwire/
*/

int buzzPin = 11; // buzzer connected to digital pin 11

void setup() {
  pinMode(buzzPin, OUTPUT); // sets the digital pin as output
}

void loop(){
  if(analogRead(0) < 850){ // this number depends on calibration of the photocell
    digitalWrite(buzzPin, HIGH); // turns buzzer on
    delay(1000); // waits for 1 second
    digitalWrite(buzzPin, LOW); // turns buzzer off
  } else{
    digitalWrite(buzzPin, LOW);
  }
}

Here is the code with analytics additions I’ve added:
/*
Jonathan Robson Feb 09.
Laser tripwire activates a buzzer. adapted from
http://www.instructables.com/id/Arduino_Laser_Tripwire/
*/
#include <SPI.h>
#include <Ethernet.h>

byte mac[]     = {  0x0C, 0xD2, 0x92, 0xAC, 0x75, 0x0B };

// To skip the DNS
IPAddress server(173,194,40,97); // www.google-analytics.com => 173.194.40.97
EthernetClient client;

int buzzPin = 11; // buzzer connected to digital pin 11


// Global switch (debug mode without API call)
boolean netword_enabled = true;

int sendEventToGA() {
  int responseCode      = 0;

  if (!netword_enabled) {
    return responseCode;  
  }

  // open the connection
  if (client.connect(server, 80)) {
    int responseSize      = 0;
    int responseSizeMax   = 1024;
    char response[1024];
    String eventData = "v=1&tid=UA-51525058-1&cid=123&t=event&ec=home%20movement&ea=door%20open&el=bedroom"; // Refer to the Google documentation

    Serial.println("Connection opened!");

    // Write the HTTP request to the Client    
    client.println("POST /collect HTTP/1.1");
    client.println("Host: www.google-analytics.com");
    client.print("Content-Length: ");
    client.println(eventData.length());
    client.println("Content-Type:application/x-www-form-urlencoded");
    client.println();
    client.println(eventData);

    Serial.println("Request sent.");

    // Wait a little bit
    delay(1000);

    // Read the response, looking for the Response Code.
    while (client.available() && client.connected() && responseCode < 100 && responseSize < responseSizeMax) {   

      response[responseSize] = client.read();
      responseSize++;
      response[responseSize] = '\0'; // Set manualy the end of string char

      // Here is the magic!
      sscanf (response, "HTTP/1.%*d %d", &responseCode);

      Serial.print("HTTP code ");
      Serial.print(responseCode);
      Serial.print(" founded in ");
      Serial.println(response);
    }
  }

  Serial.println("End of communications.");

  client.stop();
  return responseCode;
}


void setup() {
  pinMode(buzzPin, OUTPUT); // sets the digital pin as output
  Serial.begin(9600);

  // start the Ethernet connection
  if (netword_enabled && Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");

    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }

  // give the Ethernet shield a second to initialize:
  delay(1000);
}

void loop(){
  int responseCode;
  if(analogRead(0) < 850){ // this number depends on calibration of the photocell
    digitalWrite(buzzPin, HIGH); // turns buzzer on
    responseCode = sendEventToGA();
    delay(1000); // waits for 1 second
    digitalWrite(buzzPin, LOW); // turns buzzer off
  } else{
    digitalWrite(buzzPin, LOW);
  }
}


user19409: As with any piece of code that doesn't work, it is very easy to troubleshoot using the Serial.println() statement.
The big clue here is that the buzzer turns on but never turns off. Go ahead and add unique Serial.println() statements between each statement in the loop() function.  
My guess is that the digitalWrite(buzzPin, HIGH) executes but it never exits the sendEventToGA() function.
If this is the case, then go ahead and add unique Serial.println() statements in between each line of the sendEventToGA() code. 
Again, my guess is that the code goes into the while() statement and never comes out. This while statement is waiting for a response from the server. If you never get a response it won't exit. 
Perhaps add a timeout or determine why Google Analytics isn't returning a response.
Help on the topic can be found at the Arduino Libraries reference pages:  

EthernetClient() 
Ethernet Library


2884: <p>I've done this laser trip wire:
<a href="http://www.instructables.com/id/Another-Arduino-Laser-Tripwire/" rel="nofollow">http://www.instructables.com/id/Another-Arduino-Laser-Tripwire/</a></p>

<p>Got it working, and now I'd like to send info to analytics - to measure how many times I enter the kitchen...</p>

<p>I tried to take bits of code and add it to my code from:
<a href="http://bigsnarf.wordpress.com/2013/12/24/arduino-sensor-python-and-google-analytics/" rel="nofollow">http://bigsnarf.wordpress.com/2013/12/24/arduino-sensor-python-and-google-analytics/</a>
and one more which I can't post due to permissions....</p>

<p>but neither will work and adding this code breaks my basic functionality (I know as I measure it via the buzzer, it stops responding once I add this new code...</p>

<p>Is there anyone able to help?</p>

<hr>

<p>Here is my basic working code for the laser trip wire that makes buzzer noise if someone walks through it:</p>



<pre class="lang-cpp prettyprint-override"><code>/*
Jonathan Robson Feb 09.
Laser tripwire activates a buzzer. adapted from
http://www.instructables.com/id/Arduino_Laser_Tripwire/
*/

int buzzPin = 11; // buzzer connected to digital pin 11

void setup() {
  pinMode(buzzPin, OUTPUT); // sets the digital pin as output
}

void loop(){
  if(analogRead(0) &lt; 850){ // this number depends on calibration of the photocell
    digitalWrite(buzzPin, HIGH); // turns buzzer on
    delay(1000); // waits for 1 second
    digitalWrite(buzzPin, LOW); // turns buzzer off
  } else{
    digitalWrite(buzzPin, LOW);
  }
}
</code></pre>

<p>Here is the code with analytics additions I’ve added:</p>

<pre class="lang-cpp prettyprint-override"><code>/*
Jonathan Robson Feb 09.
Laser tripwire activates a buzzer. adapted from
http://www.instructables.com/id/Arduino_Laser_Tripwire/
*/
#include &lt;SPI.h&gt;
#include &lt;Ethernet.h&gt;

byte mac[]     = {  0x0C, 0xD2, 0x92, 0xAC, 0x75, 0x0B };

// To skip the DNS
IPAddress server(173,194,40,97); // www.google-analytics.com =&gt; 173.194.40.97
EthernetClient client;

int buzzPin = 11; // buzzer connected to digital pin 11


// Global switch (debug mode without API call)
boolean netword_enabled = true;

int sendEventToGA() {
  int responseCode      = 0;

  if (!netword_enabled) {
    return responseCode;  
  }

  // open the connection
  if (client.connect(server, 80)) {
    int responseSize      = 0;
    int responseSizeMax   = 1024;
    char response[1024];
    String eventData = "v=1&amp;tid=UA-51525058-1&amp;cid=123&amp;t=event&amp;ec=home%20movement&amp;ea=door%20open&amp;el=bedroom"; // Refer to the Google documentation

    Serial.println("Connection opened!");

    // Write the HTTP request to the Client    
    client.println("POST /collect HTTP/1.1");
    client.println("Host: www.google-analytics.com");
    client.print("Content-Length: ");
    client.println(eventData.length());
    client.println("Content-Type:application/x-www-form-urlencoded");
    client.println();
    client.println(eventData);

    Serial.println("Request sent.");

    // Wait a little bit
    delay(1000);

    // Read the response, looking for the Response Code.
    while (client.available() &amp;&amp; client.connected() &amp;&amp; responseCode &lt; 100 &amp;&amp; responseSize &lt; responseSizeMax) {   

      response[responseSize] = client.read();
      responseSize++;
      response[responseSize] = '\0'; // Set manualy the end of string char

      // Here is the magic!
      sscanf (response, "HTTP/1.%*d %d", &amp;responseCode);

      Serial.print("HTTP code ");
      Serial.print(responseCode);
      Serial.print(" founded in ");
      Serial.println(response);
    }
  }

  Serial.println("End of communications.");

  client.stop();
  return responseCode;
}


void setup() {
  pinMode(buzzPin, OUTPUT); // sets the digital pin as output
  Serial.begin(9600);

  // start the Ethernet connection
  if (netword_enabled &amp;&amp; Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");

    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }

  // give the Ethernet shield a second to initialize:
  delay(1000);
}

void loop(){
  int responseCode;
  if(analogRead(0) &lt; 850){ // this number depends on calibration of the photocell
    digitalWrite(buzzPin, HIGH); // turns buzzer on
    responseCode = sendEventToGA();
    delay(1000); // waits for 1 second
    digitalWrite(buzzPin, LOW); // turns buzzer off
  } else{
    digitalWrite(buzzPin, LOW);
  }
}
</code></pre>
 19409: <p>As with any piece of code that doesn't work, it is very easy to troubleshoot using the <code>Serial.println()</code> statement.</p>

<p>The big clue here is that the buzzer turns on but never turns off. Go ahead and add unique <code>Serial.println()</code> statements between each statement in the <code>loop()</code> function.  </p>

<p>My guess is that the <code>digitalWrite(buzzPin, HIGH)</code> executes but it never exits the <code>sendEventToGA()</code> function.</p>

<p>If this is the case, then go ahead and add unique <code>Serial.println()</code> statements in between each line of the <code>sendEventToGA()</code> code. </p>

<p>Again, my guess is that the code goes into the <code>while()</code> statement and never comes out. This while statement is waiting for a response from the server. If you never get a response it won't exit. </p>

<p>Perhaps add a timeout or determine why Google Analytics isn't returning a response.</p>

<p>Help on the topic can be found at the Arduino Libraries reference pages:  </p>

<ul>
<li><a href="https://www.arduino.cc/en/Reference/EthernetClient" rel="nofollow noreferrer">EthernetClient()</a>   </li>
<li><a href="https://www.arduino.cc/en/Reference/Ethernet" rel="nofollow noreferrer">Ethernet Library</a></li>
</ul>
