Internet meter

I am pondering on how to make a internet meter. A meter that should show the activity on my WAN port on my router.

My plan is to first observe how fast it can flash. So see how long between flashes there are, I made this little code


int sensorPin = 5;    // select the input pin for the sensor
int sensorValue = 0;  // variable to store the value coming from the sensor

unsigned long ping;
boolean isSet = false;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(sensorPin);
  unsigned long output;

  if (!isSet)
  {
    if (sensorValue < 800)
    {
      isSet = true;
      output = millis()-ping;
      ping = millis();
      Serial.print((double)(output/1000.0)); Serial.println(" sec");
    }
  }
  else
  {
    if (sensorValue > 800)
    {
      isSet = false;
    }
  }
}

This will show in seconds (with two decimals) how long there are between the LED flashing. If more accuracy needed, I can just remove the /1000.0 where it is printed by serial.

0.92 sec
2.68 sec
0.82 sec
4.04 sec
0.20 sec
0.27 sec
2.01 sec
0.78 sec
0.36 sec
0.24 sec
1.19 sec
0.19 sec
0.14 sec

Output after testing on the hdd led on my computer for a few seconds.

Leave a Reply