Arduino Website Hit-counter

2008.12.06

For the final project in my New Media class, I assembled a little gadget that lights up whenever someone visits your website. The piece follows the guidelines provided in a tutorial I found for using an Arduino to ring a bell everytime a predetermined website is visited. I wanted an LED to light up instead of a bell ringing, so I kept the python script unaltered, but adjusted the Arduino code appropriatly to make the light turn on. The project uses 3 separate scripts:

-A php script that is saved to the root directory of the website Im counting the hits on. This script just counts how many times this site is visited. This script was unaltered from the tutorial and can be found at the link I provided.

-An Python script that retrieves the counter information from the php script and delivers it to the Arduino board. I only altered this script so it would communicate with the specific domain I wanted. This code can also be found in the tutorial.

-And an Arduino sketch that I have uploaded to my Arduino board that turns a LED on each time the Python script tells it that the website has received a hit. The code for this sketch has been requested, so Ill post it here:

long nextMillis = 0;

int blinks = 0;         // amount of blinks

int state = 0;         // for the state machine

void setup() {

int ledPin = 13;

pinMode(ledPin, OUTPUT);  // Set LED pin as an output pin

Serial.begin(9600);

}

// define states for the state machine

#define PULSE_ON       0

#define PULSE_OFF      2

#define WAIT_PULSE_OFF 3

void loop() {

if (Serial.available() > 0) {

blinks += Serial.read();

Serial.println(blinks);

}

while (blinks > 0) {

int ledPin = 13;

digitalWrite(ledPin, HIGH); //sets LED on

delay(1000);     //waits for a second

digitalWrite(ledPin, LOW);  //sets LED off

blinks–;

}

}

This is the Arduino board itself with the LED, that I sanded to diffuse the light, plugged into ground and pin 13, the pin that Arduino has conveniently connected a resistor to, so I dont  have to.

Here is the guts of the housing. It used to be a cheap alarm clock from a novelty shop, but now its going to house my Arduino Board.

Final product!

5 comments

  1. [...] simpler projects I’d also like to do. One is a physical hit counter for my blog. I helped Christina set up hers, so it shouldn’t be very hard at all to get my own running by following the tutorial she [...]

    blog.dfyb | justin pierce, December 9, 2008
  2. any chance you will upload the scripts??

    michael, January 9, 2009
  3. Hi Michael, I just updated this entry to include the code I used. Sorry it took so long for me to get around to it!

    christina day, January 26, 2009
  4. You didn’t really understand what you were doing when you altered that arduino sketch, did you? Half of that code isn’t even pertinent to your project.

    tony, July 5, 2009
  5. I left alot of ‘extra’ code from the project’s original tutorial. I could probably clean it up but I dont really care. Im an art student, not a programmer. Plus, this project was dismantled a long time ago. The original code can be found in the link I provided to the tutorial if youre really interested.

    christina day, July 6, 2009

Leave a comment