Вы находитесь на странице: 1из 6

Diy Arduino based metal detector.

UPDATE: Try using BC547 as transistor people have reported problems with
2n2222.
Me and my son decided to go treasure hunting with a metal detector that we
have but we couldn't find it anywhere. Being proper makers we decided that
it would be more fun to build one ourselves rather than keep trying to find
it.
Most metal detectors uses a search coil that act as part of an oscillator
circuit. When metal is put in proximity of the search coil the frequency of
the oscilations changes.
Many metal detectors (including the one we can't find) uses another more
stable oscillator BFO (beat frequency oscillator) to act as a reference for
the frequency of the search coil. Usually the frequency of the BFO is
adjusted to exactly match that of the search coil oscillator when no metal
is present near this.
The signals from these two oscillators are then fed to a, usually analog,
circuit that create an output proportionally to the difference in frequency
og the two. This may be either an audiable tone and/or some meter reading.
Another device that are really good at detecting minute frequency changes
is a microcontroller. We decided to swap the BFO approach for a
microcontroller and came up with following simple circuit:

The oscillator circuit feeds a around 160kHz signal to pin 5 of the


Arduino. The Arduino sketch then measures the frequency of this pin very
accurately. When the 'NULL SW.' button is held this frequency is stored.
Any deviation from this frequency is then represented as a series of
'geiger counter' clicks on the piezo. The rate of the clicks increases as
metal approaches the coil.
We tried different search coils and found that around 30 turns of wirer
around a 15cm. plastic bucket worked well.
All we needed then was to tie it all to a discarded Ikea lamp and heypresto off to the beach to find treasures.
The metal detector has excellent sensitivity and by changing the
SENSITIVITY value in the Arduino sketch you are able to tune it for both
small and large objects.
Here is the source code if you want to build one yourself.
Happy hunting!
// Arduino based metal detector
// (C)Dzl july 2013

// http://dzlsevilgeniuslair.blogspot.dk/
// Connect search coil oscillator (20-200kHz) to pin 5
// Connect piezo between pin 13 and GND
// Connect NULL button between pin 12 anf GND
// REMEMBER TO PRESS NULL BUTTON AFTER POWER UP!!
#define
#define
#define
#define

SET(x,y)
CLR(x,y)
CHK(x,y)
TOG(x,y)

(x |=(1<<y))
(x &= (~(1<<y)))
(x & (1<<y))
(x^=(1<<y))

//-Bit set/clear macros


// |
// |
//-+

unsigned long t0=0;


int t=0;
unsigned char tflag=0;

//-Last time
//-time between ints
//-Measurement ready flag

float SENSITIVITY= 1000.0;

//-Guess what

//-Generate interrupt every 1000 oscillations of the search coil


SIGNAL(TIMER1_COMPA_vect)
{
OCR1A+=1000;
t=micros()-t0;
t0+=t;
tflag=1;
}
void setup()
{
pinMode(13,OUTPUT);
//-piezo pin
digitalWrite(12,HIGH); //-NULL SW. pull up
//-Set up counter1 to count at pin 5
TCCR1A=0;
TCCR1B=0x07;
SET(TIMSK1,OCF1A);
}
//-Float ABS
float absf(float f)
{
if(f<0.0)
return -f;
else
return f;
}
int
v0=0; //-NULL value
float f=0;
//-Measurement value
unsigned int FTW=0;
//-Click generator rate
unsigned int PCW=0;
//-Click generator phase
unsigned long timer=0; //-Click timer
void loop()
{
if(tflag)
{
if(digitalRead(12)==LOW) //-Check NULL SW.
v0=t;
//-Sample new null value
f=f*0.9+absf(t-v0)*0.1;
//-Running average over 10 samples
tflag=0;
//-Reset flag

float clf=f*SENSITIVITY;
if(clf>10000)
clf=10000;
FTW=clf;

//-Convert measurement to click frequency

//-Click generator
if(millis()>timer)
{
timer+=10;
PCW+=FTW;
if(PCW&0x8000)
{
digitalWrite(13,HIGH);
PCW&=0x7fff;
}
else
digitalWrite(13,LOW);
}

// Arduino based metal detector


// (C)Dzl july 2013
// http://dzlsevilgeniuslair.blogspot.dk/

// Connect search coil oscillator (20-200kHz) to pin 5


// Connect piezo between pin 13 and GND
// Connect NULL button between pin 12 anf GND

// REMEMBER TO PRESS NULL BUTTON AFTER POWER UP!!

#define SET(x,y) (x |=(1<<y))

//-Bit set/clear macros

#define CLR(x,y) (x &= (~(1<<y)))

// |

#define CHK(x,y) (x & (1<<y))

// |

#define TOG(x,y) (x^=(1<<y))

//-+

unsigned long t0=0;


int t=0;

//-Last time

//-time between ints

unsigned char tflag=0;

//-Measurement ready flag

float SENSITIVITY= 1000.0; //-Guess what

//-Generate interrupt every 1000 oscillations of the search coil


SIGNAL(TIMER1_COMPA_vect)
{
OCR1A+=1000;
t=micros()-t0;
t0+=t;
tflag=1;
}

void setup()
{
pinMode(13,OUTPUT);

//-piezo pin

digitalWrite(12,HIGH); //-NULL SW. pull up


//-Set up counter1 to count at pin 5
TCCR1A=0;
TCCR1B=0x07;
SET(TIMSK1,OCF1A);
}
//-Float ABS
float absf(float f)
{
if(f<0.0)
return -f;
else

return f;
}

int v0=0; //-NULL value


float f=0; //-Measurement value
unsigned int FTW=0;

//-Click generator rate

unsigned int PCW=0;

//-Click generator phase

unsigned long timer=0; //-Click timer


void loop()
{
if(tflag)
{
if(digitalRead(12)==LOW) //-Check NULL SW.
v0=t;

//-Sample new null value

f=f*0.9+absf(t-v0)*0.1; //-Running average over 10 samples


tflag=0;

//-Reset flag

float clf=f*SENSITIVITY; //-Convert measurement to click frequency


if(clf>10000)
clf=10000;
FTW=clf;
}

//-Click generator
if(millis()>timer)
{
timer+=10;
PCW+=FTW;

if(PCW&0x8000)
{
digitalWrite(13,HIGH);
PCW&=0x7fff;
}
else
digitalWrite(13,LOW);
}
}

Вам также может понравиться