BLOG > Physically Display Website Statistics via an Arduino + Multicolor LED

Behold! My newest little project. This one isn’t as complicated as some of my other creations, but it’s still a pretty cool little device that I put together.  I made this as a project for my INFO4320 class at Cornell: “Intro to Rapid Prototyping and Physical Computing”.  The assignment was to use a multicolor LED to react to some kind of stimuli.  So, I figured I’d make my stimuli this very blog!  Using a combination of PHP code on this site, a python script, and an arduino, I’m able to monitor website visits, and the OS/Browser of people visiting in (nearly) real time.  As always, I’m making the source code and schematics available below via a creative commons license, so go nuts!   A video is worth about 116,987,432 words by my calculations, so watch the video below to see how it works!

I have also made some other mini projects for this class.  I’m posting videos of all assignments for this class on a separate youtube channel here: http://www.youtube.com/jeremyeblum.  I’ll be posting the more interesting ones (like this one), on my normal channel as well.  But if you wanna see everything I’m up to, go subscribe to that other channel!  I’ve started work with three other group members on our final project for this class.  It’s ambitious, but if we can get it to work, it’s gonna be really cool (Hopefully on par with the Nerf Sentry Gun from last year)!

READ ON TO LEARN HOW IT WORKS AND TO DOWNLOAD SOURCE CODE/SCHEMATICS

DESIGN GOALS

For this project, my goal was to develop an LED display device that could provide me with real-time statistics about my website. I designed my project to collect and display three types of information:

  1. Number of Visits by Human Users
    1. Determine if a user is human, and record their visit as a timestamp, keep 1 month’s worth of timestamps
    2. Parse this list of timestamps to determine number of visits in last 24 hours, week, and month
    3. Set “goal” values and have LED increase in intensity as the number of visits gets closer to the goal for a given time frame
    4. A different LED color represents each time span (ie. Day , week, month)
  2. Browsers Being used by Visiting Users
    1. Gather browser statistics, and keep them for most recent 1000 visits
    2. Determine Browser Percentages and vary LED intensity for three colors corresponding to Firefox, Internet Explorer, and Other
  3. Operating Systems of Visiting Users
    1. Gather Operating System statistics, and keep them for most recent 1000 visits
    2. Determine OS Percentages, and vary LED intensity for three colors corresponding to Windows, Mac, and Linux

HOW IT WORKS

  1. PHP script running in footer on each page of my blog first checks against a list of webcrawler identities to determine if the visitor is human
  2. If visitor is believed to be human, the current unix epoch time stamp is appended to a text file
  3. Additionally, the text file is checked for entries over one month old and they are removed
  4. Length of OS and browser text files are checked. If there are more than 1000 entries, leading entries are removed
  5. Based on user agent string, OS and Browser are detected and each are appended to a text file
  6. Python Script running on local computer allows user to choose which statistic they would like to monitor
    1. Number of Visitors Mode
      1. Visitor text file is read into array from server
      2. Visits in past month are determined by length of array
      3. Visits in last week are determined by subtracting 1 week in seconds from current unix time
      4. Visits in last 24 hours are determined in similar fashion
      5. Statistics are printed and compared against goal values
      6. Command is translated into form for serial transmission to Arduino like this “004175250” – each three numbers represent brightness for an LED on scale from 0-255
      7. Values are sent over serial to Arduino
      8. Script repeats every 5 minutes, downloading updated information
    1. Browser Mode
      1. Browser text file is read into array from server
      2. Array is searched for string matches for each browser option
      3. Percentages are determined based on total list length
      4. Statistics are printed
      5. Command is translated into form for serial transmission to Arduino like this “050150050” – each three numbers represent brightness for an LED on scale from 0-255
      6. Values are sent over serial to Arduino
      7. Script repeats every 5 minutes, downloading updated information
    1. OS Mode
      1. OS text file is read into array from server
      2. Array is searched for string matches for each OS option
      3. Percentages are determined based on total list length
      4. Statistics are printed
      5. Command is translated into form for serial transmission to Arduino like this “050150050” – each three numbers represent brightness for an LED on scale from 0-255
      6. Values are sent over serial to Arduino
      7. Script repeats every 5 minutes, downloading updated information
  7. Arduino receives 9-bit value over serial connection
  8. First 3 bits determine green brightness, second 3 determine blue, and the last three determine red
  9. Arduino flashes through each of these colors adjusting their brightness to correspond to the values it received over serial
  10. On/Off Switch is connected to interrupt and can start/stop Arduino at any time, even in the middle of a sequence.

SOURCE CODE AND SCHEMATICS

These materials are made available via a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. Feel free to modify and improve upon this code as much as you like, but share your improvements and credit myself as the original author. Please do not use this code for commercial purposes without first asking for my permission.
Creative Commons License
Download LED Website Monitor Source Code and Schematics

16 comments

  1. This is great!

    I hope I can learn something from your schematics, next year I have to make some kind of end work and I was thinking to control hardware (a robot) from my website but I have no idea how I can let my website (php scripts) communicate with hardware.

  2. Hi,
    I was thinking, perhaps the PHP script could be modified to record an action on the site (a mouseclick), and that action would control the LED…do you think that is possible?

    Michael

  3. I have a problem in the reading part of serial. The serial displays “207” specifically in all of its entries. E.g. g[0], b[0], r[0], g[1],.. Thus the intensity of the LED is constant and doesn’t vary.
    Another thing, Serial.available returns 0 every time so I have done it without the if loop. (This may be a stupid mistake.)
    Please Help.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement