Tecnicamente's Weblog

Just another WordPress.com weblog

Arduino and EMF detector

Usually I write my short note in italian, but I guess that sometime is better switch to english due to the fact that I can “improve” and I can reach more people in the web, so why do not start to write my post in english? (or better, I’m try to do that😉 ).

OK let’s go, in some of my previous post I described my little project around an EMF detector using arduino, please read this, this and this.

Thanks to this project I had the opportunity to investigate some interesting things like:

  • Theory of antenna;
  • Digital filters;
  • The use of millis() in order to emulate a multitasking on my Arduino Uno;
  • Fourier transform.

Very interesting topics, so I can say that my project isn’t completed, but it gave me a lot of points where I can study and enlarge my knoledge.

Coming to the project I can write a simple sentence that can summarize the result: “ALL EMF DETECTOR PROJECTS THAT USE ARDUINO, WIRES AND RESISTORS ARE BULLSHIT”

First of all you cannot read or measure MAGNETIC FIELS, but only ELECTRIC FIELDS, so what you can see directly whit you arduino is the variation of the electric field in the enviroment.

Here in Italy the frequency of the electric lines is 50Hz, so I guess that the variation of the EF is reletad to this frequency, but please look at next picture:

5msYou can see the measurement with different antennas, the results is that the antenna is not so importat about the frequency, and that the frequencies are quite far from 50Hz, very strange. I’m aquiring the data at 200Hz in order to avoid the aliasing with a signal of 50Hz.

In the next picture you can see the aquisition of data near to electric light, the variation of the EF is measured but there is no changes on the FFT analysis, so the main frequency of the field is  about 250 Hz as before

5ms-sorgente

The question is what is the reason for a EF at 250Hz? Nice to investigate.

Now what appen if I change the sample rate from 200Hz to 100Hz.

Here the result:

10ms

And now what I find at 50Hz of sample rate:

20ms

Someone can suggest howto detect the field at 50Hz?

I used different leght for antennas and impedence, but the only thing that seems focus on the EF frequency is the sample rate.
Here the code, very raw😉

#include <Arduino.h>
#define VERSIONE 4.01-27/10/2014
#define C 0.0048828125
#define T1 20
#define T2 60000

int flag = 0;

void waitForFlush(void){
/*******************************************
* scopo di questa funzione e non impegnare *
* la comunicazione seriale nei primi X *
* secondi. In tal modo il flush e sempre *
* facilmente realizzabile. *
*******************************************/
#define TIMETOWAIT 5000 /* ms */
unsigned long t0,t1;

t0 = millis();
t1 = millis();

while( t1-t0 < TIMETOWAIT){
   t1 = millis();
}
}
void setup(){
/*attivo la comunicazione seriale */
Serial.begin(57600);

/*do disponibilità a flush del controllore*/
waitForFlush();

/*Intezzazione del programma */
Serial.print("EMF DETECTOR V. ");
Serial.println(VERSIONE);
}
float valore, valore1;

void loop(void){
unsigned long t;

t = millis();
/* con t%10 campiono 100 volte al secondo, quindi a 100 Hz
con t%5 campiono 200 volte al secondo, quindi a 200 Hz
*/

if(t%T1 == 0){

valore = analogRead(A0)*C;
valore1 = analogRead(A5)*C;

/*
Serial.print(t);
Serial.print("\t");
*/

Serial.print(valore,5);
Serial.print("\t");
Serial.print(valore1,5);
Serial.println();
}
}

[UPDATE 9-Nov-2014]

I spent last days, to be honest the last free hours, investigating about the source of the signal and how to apply a filter.
So it was good, I opened a new door about digital filters and at the I discovered some important things:

  1. Low and High pass filters are interesting, but to much resource are necessary, due to this in mandatory leave the arduino IDE and use a pure C or Assembler approach to the controller, but I’m not sure about the results.
  2. There are others more simple approach to filter the input signal:
    1. moving average
    2. slide window average.

I tried to implement both, sorry for the dirty code, I will arrange it better in a second life😉

 

#include <Arduino.h>
#define VERSIONE "4.03-09/11/2014"

#define C 0.0048828125

#define T1 5
#define T2 60000

#define NCAMPIONI 10

//int flag = 0;

void waitForFlush(void){
/*******************************************
* scopo di questa funzione e non impegnare *
* la comunicazione seriale nei primi X *
* secondi. In tal modo il flush e sempre *
* facilmente realizzabile. *
*******************************************/
#define TIMETOWAIT 5000 /* ms */
unsigned long t0,t1;

t0 = millis();
t1 = millis();

while( t1-t0 < TIMETOWAIT){
   t1 = millis();
}
}

void setup(){

/*attivo la comunicazione seriale */
Serial.begin(57600);

/*do disponibilità a flush del controllore*/
waitForFlush();

/*Intestazione del programma */
Serial.print("EMF DETECTOR V. ");
Serial.println(VERSIONE);
}


float valore;
float campioni[NCAMPIONI];
float campioniSlideWindow[NCAMPIONI];

float somma=0;
float sommaSlideWindow=0;

float mediaMobile = 0;
float mediaSlideWindow = 0;

short int contatore = 0;
short int flag = 0;
short int i;

void loop(void){
unsigned long t;

t = millis();
/**********************************************************
 *con t%10 campiono 100 volte al secondo, quindi a 100 Hz *
 *con t%5 campiono 200 volte al secondo, quindi a 200 Hz  *
 *Applicano il fitro i campionamenti avvengono ogni 10*T  *
 *********************************************************/

if(t%T1 == 0){
  valore = analogRead(A0)*C;
  
  if (contatore < 10){
    campioni[contatore] = valore;
    //somma = somma + campione[contatore];
    contatore++;
  }


  
  if (contatore < NCAMPIONI && flag ==0){
    flag = 1;
    for (i=0; i<NCAMPIONI; i++){
      sommaSlideWindow = campioniSlideWindow[contatore]+sommaSlideWindow;
    }
    sommaSlideWindow = 0;
  }

  if (contatore < NCAMPIONI && flag !=0){
    campioniSlideWindow[contatore] = valore;
   
   for (i=0; i<NCAMPIONI; i++){     sommaSlideWindow = sommaSlideWindow + campioniSlideWindow[i];    }       mediaSlideWindow = sommaSlideWindow/NCAMPIONI;    sommaSlideWindow = 0;   }   if ( contatore >= NCAMPIONI){
      contatore =0;
      for (i=0; i<NCAMPIONI; i++){
         somma = somma + campioni[i];
      }
      mediaMobile = somma/NCAMPIONI;
      somma = 0;
  }
  

  Serial.print(t);
  Serial.print("\t");
  Serial.print(valore,5);
  Serial.print("\t");
  Serial.print(mediaMobile,5);
  Serial.print("\t");
  Serial.print(mediaSlideWindow,5);
  Serial.println();

}
}


In the next picture you can see the graphical results of the filters.
The filter based on the simple moving average seems better (2nd col).

20141106_5ms

and after some minutes:

20141106_5mmms

 

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger cliccano Mi Piace per questo: