Counting pulses - have counts even with no input.. [SOLVED]

I want to count clean 5V digital pulses and followed the sketch below.

But even with nothing connected to Pin 5 I get '53413' on the serial monitor after reset - about 30 Seconds later I get '1'.

How come, and is there a way to prevent it?

Xp Arduino 1.0.5 UNO (clone)

/*
 * HardwareCounting sketch
 *
 * uses pin 5 on 168/328
 * Source: https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-18/recipe-18-7
 */

const int hardwareCounterPin = 5;   // input pin fixed to internal Timer
const int ledPin             = 13; 

const int samplePeriod = 1000;   // the sample period in milliseconds
unsigned int count;


void setup()
{
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
  // hardware counter setup (see ATmega data sheet for details)
  TCCR1A=0;        // reset timer/counter control register A
}  

void loop()
{
  digitalWrite(ledPin, LOW);
  delay(samplePeriod);
  digitalWrite(ledPin, HIGH);  
  // start the counting
  bitSet(TCCR1B ,CS12);  // Counter Clock source is external pin
  bitSet(TCCR1B ,CS11);  // Clock on rising edge  
  delay(samplePeriod);
  // stop the counting 
  TCCR1B = 0;           
  count = TCNT1;
  TCNT1 = 0;  // reset the hardware counter
  if(count > 0)
     Serial.println(count);
}

But even with nothing connected to Pin 5

Never have nothing connected to an input pin because it will float:- http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Let me try....

3K3 to GND - 53413 after reset 10K to GND - same Pin 5 to GND - same

3K3 to 5V - same 10K to 5V - same Pin 5 to 5V - didn't try

No change at all. What else I can try?

The 53413 is what is left in the counter register after the boot loader. If you want to clear it then change the code to read:-

  // start the counting
    TCNT1 = 0; // reset the hardware counter
  bitSet(TCCR1B ,CS12);  // Counter Clock source is external pin

You can enable the internal pull up resistors by putting this line in the setup function:-

 pinMode(hardwareCounterPin, INPUT_PULLUP);

Note this counter is very fast and will count all the bounces on a button.

It looks like it's working! Thank you so much!