EMF Detector

My EMF detector made it onto the Make Blog, it was a very nice surprise.  This page contains the code for the project.

Original EMF Detector


EMF Detector Code

// Aaron ALAI EMF Detector April 22nd 2009 VERSION 1.0
// aaronalai1@gmail.com
// *future note, put in averaging function to average val which should result in a more
// smooth response from the led.  I will give you a hint on how to make an averaging function;
// it involves the use of an array

int inPin = 5;             // analog 5
int val = 0;                 // where to store info from analog 5
int pin11 = 11;         // output of red led

void setup() {

void loop() {
  val = analogRead(inPin);                    // reads in the values from analog 5 and
                                                                   //assigns them to val
  if(val >= 1){
    val = constrain(val, 1, 100);               // mess with these values                                      
    val = map(val, 1, 100, 1, 255);        // to change the response distance of the device
    analogWrite(pin11, val);                    // *note also messing with the resistor should change 
                                                                   // the sensitivity
   }else{                                                     // analogWrite(pin11, val); just tuns on the led with
                                                                  // the intensity of the variable val
    analogWrite(pin11, 0);                     // the else statement is just telling the microcontroller
                                                                 // to turn off the light if there is no EMF detected
 Serial.println(val);                                // use output to aid in calibrating

*Click for Updated Code*

You can also decrease the sensitivity of the device by making a loop with the antenna, like in the photo above, or by just shortening the length of the antenna.  Mess around with the configuration and have some fun.  I should have also pointed this out earlier.  If you are messing around with this project you should do so on a laptop not plugged into a wall outlet.  Plugging the laptop into a wall outlet essentially makes your laptop an antenna for electromagnetic noise and your Arduno board will return stochastic results. 

I have been getting requests for code that will average the readings; I intentionally did not  include it so people would make their own and learn more.  Some people have shown me some great code, but others still need a bit of help.  The following link will tell you how it is done, remember though this is only one technique and there countless others out there,  EMF Detector Averaging Code.  This link is to an averaging  program written by reader Zac Bohon. 

I changed the code a bit, added an LCD, and increased the antenna size of my old EMF detector. It's sensitive enough to detect the different speed settings in my ceiling fan. The numbers are unitless, thus are are only relative to themselves. I hope one of these days I can get my hands on a good digital EMF detector so I can calibrate mine and make something more useful.  I'll be posting more code and such for the project later this week.

New EMF Detector Design