Accidentally made a crude EMI detector/wire finder

While learning about interrupts (read: goofing off) I discovered that if I attached an interrupt to a pin set to input mode that wasn't actually connected to something I was getting a reading of 60 interrupts per second. A bit of contemplating pointed out to me that 60hz is standard USA AC frequency.
A bit more playing with different lengths of jumper wire antennae and different sized caps from the antenna to (arduino)ground for sensitivity and now I have a power line finder I can move over/around the walls and find power wires.
It works great on wires with a load on them, load-free wires it needs smaller (or no) caps.

(I'm using a 6" lead with a two tiny 15pf caps in series for an antenna, it's not perfect but it works)

Not sure how I can get a signal strength reading, that's the next project.

The code is very simple, it reads for 250ms then outputs the number of triggers via serial, and checks to see if it comes out to 60hz, if it does it turns an LED on, if it doesn't it turns it off.

/*  Bobnova's power line finder/EMI finder.
    Feel free to use this code, modify it, etc.
    Please credit me if you do.
    If you make money off this code or it's descendants
    I'd love to get some.
*/

unsigned long time;
unsigned long interval = 250;
unsigned int counter;


void setup()
{
  Serial.begin(57600);
  pinMode(2, INPUT);
  pinMode(5, OUTPUT);  //LED goes here, with a resistor of course
  attachInterrupt(0, trigger, RISING);  //Interrupt 0 being pin 2
}

void loop()
{
//  analogWrite(5, 50); // A very easy way to test your interrupt code is to aim a PWM pin at the interrupt pin. 

  if (millis() - time > interval){
    Serial.println(counter * 4);
    if (counter * 4 == 60){
    digitalWrite(5,HIGH);
  }
  else {
    digitalWrite(5,LOW);
  }
    counter = 0;
    time = millis();
  }
  
}

void trigger()
{
  counter++;
}

My hand touching the antenna insulation reads ~3000hz with no filter caps, or 60hz with filter caps. I figure I'm acting as a big antenna with the 60hz flavor.

Cool idea and thanks for sharing it with us.

I would bet you would get even better results is you used a tuned parallel 60hz L/C tank circuit, possibly using a ferrite rod for the L core. Ground one end to the tank circuit to the Arduino ground and make a tap connection at say 10-20% of the L winding to an Arduino analog input pin via a series diodes, cathode end to analog pin, and a small filter cap from analog pin to ground. Then you would have a variable digital value representing the signal strength and some directional control via the orientation of the ferrite rod as you rotate it while searching.

That is the same basic idea that simple RF direction finders use, with however maybe extra RF amplifier stage(s) and of course a variable capacitor to be able to search for a specific frequency.

Lefty