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.
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 hey-presto 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!
Great build! What was the model # of the Ikea lamp you used?
Awesome! I might have to build one with my son. I think an ATtiny45 would be enough…
I think it should work just fine as it has a total of 5 available pins… you could even add a button for sensitivity "up" or "down"
Great project! How sensitive did it turn out to be? how far(deep) can it detect a coin sized object ?
Nice ! Few days ago I decided to build one with my father, too. Odd :).
What diameter is your wire ?
Copper I guess ?
It detects a 1euro coin at about 15 cm distance if you are patient…
Wire is just plain 0,12mm2 plastic coated wire not critical..
I will try and make a TINY45/85 version and post it here..
Tiny45/85 came to my mind as saw the schematic too!
Well Done! I would appreciate if you elaborate a bit the frequency oscillation part of the circuit.
A very interesting project! The transistor must be necessarily 2n2222?
I used the KT315, did not work.
The 2N2222 has quite little gain (hFe) of about 30 (depending on the current flowing). The KT315 may have a much higher gain of about 100-200 – maybe that causes trouble with the base current on the npn transistor. You could try higher values for the resistors. As far as I understand the circuit it's just a kind of voltage divider and as that functions as a base current limiter for the transistor. Not sure if it affects the circuit if you alter the values…
I actually ended up using BC547
Nice work !
I've built mine, But after some tests I think it needs some tuning. I've tried in my garden, but some objects (bike, table etc..) seems to alter the frequency so this is quite hard to localise a coin. (50 euro cents)
Remember to press and hold the NULL switch for a couple of seconds
Давно искал. Спасибо!
собрал, пока не заработала, возможно я не правильно собрал, завтра буду еще пробовать, если у тебя заработало отпишись сюда пожалуйста
Собрал, работает. Транзистор поставил bc107b, но дальность обнаружения не большая. Разобраться бы как настроить
А катушку мотал как они писали ? просто я сделал 15 витков и может быть по этому не работает ?
Катушку мотал 30 витков, провод 0.33
Nice project – Any improvements you have come up with after some field testing? I added a 10K pot to an analog pin, using the value to set the sensitivity at the same time as null. Have not had a chance to test it out outdoors yet, but my kids are sure to enjoy this!
Cool. Thought about that too 🙂 Let me know if it works.
What you need to do to change the sensitivity?
Change the value in the code and reprogram
Not working. does not work, three days is trying to make, and the ratings are correct and fully detail transistor 2n2222 and it does not respond:(
Try using BC547 or similar
Заработал ли у кого нибудь на Arduino UNO?
PIN 5 analog или PIN 5 digital?
———————————————–
runs on Arduino UNO?
PIN 5 PIN 5 analog or digital?
pin5 цифровой
Digital pin 5
Nice project! I got this to work using the BC547 as you suggested. One thing I'd like to point out to your readers who also try this circuit is that you need to be wary of prototyping this on a breadboard. The parasitic inductance, capacitance, and resistance can cause problems at this frequency in the circuit. I could only keep this circuit stable for about a minute or two before these effects broke it down.
For those who try, this is how I got it working. Without any changes to the circuit or the sketch, try setting the sensitivity real low (Ok, one change in the sketch) and then sense a big piece of metal (I set 100, sensing a pair of pliers at 5 cm). That should be good enough for a proof of concept. I used 30 turns of 29 gauge magnet wire around a 15cm diameter form. Also watch the quality of your loop as that will impact performance – keep it tight and compact. Finally, I suggest prototyping with an external supply voltage to further remove secondary effects from your PC connection. I used a 9V battery to an Uno board.
Really awesome and thanks again. Clever circuit. I'm going to etch a board in the coming weeks as time allows to build this proper.
which sensitivity you had managed to reach (for 1 euro coin)
and which construction of coil do yo recommend (red or blue(see pictures)? Which you use?)
Hi what kind of capacitor did u use ? ( AC / DC ) ?
I got It working but it is really sensitive to electric environment.
Could someone post a firmware sketch with variable sensitivity with a Pot adjustment. That would be awesome!
Great project. Thous I am not very familiar with metal detector stuff and don't completely understand how everything works. I add some stuff to Your code – also pot adjustment. Maybe will soon put code and entire project on my blog.
I use 2n2222a and it works ok. Range could be better.
Questions:
1. If we use 12v to coil could it boost up detecting depth?
2. Why not to generate pulse with arduino microcontroller? Then it would give possibility to test different frequencies. Of course we need to add additional components.
3. I read about BFO concep. But did not completely understand how timing calculation works in this code. Can somebody explain code in details?
Anyway many thanks!
please tell me how to do a sketch that was not PIN5 the other?
Подскажите пожалуйста, как поменять в скетче номер пина (5) на как либо другой, никак не могу запустить этот девайс, есть подозрение что что-то с пином не то
how did you do with it, did it work with you? mine not, i have arduino unor3- i changed windows up to 10 and different arduino software. it up loads the sketch but never respond.
Which construction of coil is the best? red or blue?
http://www.youtube.com/watch?v=qlUoBzxPgv4
how to make coil
Could you clarify capacitor types and values please?
Hi all,
I used 2n2222a and I'm not able to make it work. I can read the frecuency modifying source code in void loop():
Serial.print("Frecuency: ");
Serial.println(f);
And before and after I press NULL SW button, Frecuency value is the same: Frecuency: 0.0
Could you please help me to solve this issue?
Many Thanks in advance!
Are you sure this circuit works??? anyone here tested it, cause most of people here have issues.
Hi Kotsos5,
Many thanks for your reply :).
I'm not really sure….
Do you know where is the right place to put the speaker? and.. Whats means "piezo" in the circuit… maybe means "piezo-electric crystal"?
Many Thanks for your help!
yes it's a piezo electric like this http://i1-news.softpedia-static.com/images/news2/Piezoelectric-Crystals-Turn-Roads-into-Power-Plants-2.jpg, one pin goes to ground of arduino and the other goes to pin13 of arduino, watch out for polarity!
The circuit works, but I did not use the code mentioned here, I created my own, so I cant really comment the code.
Nice project, but I'd like to know more about the oscillator circuit… a LC circuit produces a oscilatory signal when you apply a DC current? … didnt know that.
the transistor part of the circuit, is it just to change the voltage level? it has nothing to do with the oscillator part?
hi xouri can you upload your code? Because i've triple checked the schematic and my coil is fine but still doesn't work, but I couldn't understand the code well cause i'm a beginner in programming.
Hi
this is really very helpful article. I go through this site really very nice information.thank for sharing such a nice information. ecofriendly construction
Hello,
I am trying to build this on my own, and I would like to know if you built it using a breadboard or a PCB. and if you could tell me more about it. Thanks!
Ok for some reason my null switch isn't working and I have another question about this code. What does this do for the code and why does it not ever get called? //-Generate interrupt every 1000 oscillations of the search coil
SIGNAL(TIMER1_COMPA_vect)
{
OCR1A+=1000;
t=micros()-t0;
t0+=t;
tflag=1;
}
Hi
I was very pleased to find this site. I definitely enjoyed reading post regarding regarding < and I have it bookmarked to check out new stuff posted regularlySanta Barbara Green building
hello i have a layout in gif format for non arduino component for making an easy pcb
where should i post it?
thanks to author for showing this project to public
next try
https://sites.google.com/site/detektorschmiede/
See it working on youtube: http://youtu.be/LlLRAXsdo28
Current Sensitivity value: 2000
Hi, i have problem. Your shemat and Dzl's Evil schemat doesn't work. And I dont know why.
Here you have my project, maybe you see whot is wrong with it: https://imageshack.com/a/Pfkz/1
Do you run this scheme?
Why my "metal detector" always makes the sound, even if I press the "null" button and I change the sensitivity? Help please, thanks.
sorry but pin 13 is the led pin in arduino Uno series. so how is this supposed to work? i tried it but didnt work
There is some discussions on topic: http://www.thunting.com/smf/metal_detectors/simple_diy_bfo_metal_detector-t48310.0.html
I only obtained @25KHz oscillation using the 22nanoFarad caps (.022 uF or microFarad) suggested in his drawing; when I changed the pair to .001 uF the oscillator ran about 250KHz (target was @160KHz). I could not detect a coin; but it worked on a hammer. Thinking I need higher Q capacitors and to dead-bug the assembly instead of protoboard.
Wonderful blog, and full of interesting information. Gold Detector Dubai|Detech metal Detectors|Metal Detector Dubai
Hi, I'm try to upload this code in arduino mega and it doesn't work. I guess the problem is a timer. I'm very newbie and I don't know how to fix it.
I have 2 problems. The BC547 misplaced (lol) and Mega only have 2 external timer 0 and 5. I changed timer 1 for 0.
its amazing project >>
but i have a small question .. if i want to increase the range of detection to about 40 or 50cm under ground ..
what should i do ???
I believe that the diameter of the coil reflects the distance. Larger coil equals longer distance but also require proportionally larger objects.
Sinusoidal oscillations on emitter of transistor are weak with waveform voltage swing from +2V to +3V in my example. Depending on components can be even lesser and this is maybe not enough for arduino to consider this as binary 0 / 1. It is good to add one additional BC547 saturating amplifier between emitter of oscillator transistor and arduino, which will ensure that voltage swing is 0 to +5V. (copy schematic to notepad fixed font)
·······································
_______________________________+5V·····
····················|··················
····················_··················
···················|·|·················
···················|·|·680·············
············22K····|_|·················
·············____···|··················
··········–|____|———–ard.·pin·5
··········|········/·c·················
emiter····|···b··|/····················
—–||———-|·····················
····220pF········|·e··················
······································
······································
______________________________GND······
·······································
·······································
I just finished building and testing. It works great!! The only change in circuit values I made was to use a BC337-25 transistor (since I had a bunch of them that I'm trying to use up.) My coil is 30 turns of #27 magnet wire wound around a plastic jar lid 12.5 cm diameter. I set the Sensitivity parameter at 1500 in the sketch but it works fine from 500 to 3000. At 1500 it will reliably detect a US penny coin from around 5 cm. It will detect an aluminum beer can from around 14 cm away. It seems more sensitive to non-ferrous metals than to ferrous but detects my pocket knife quite well at 8 cm distance. I put a red LED and 1.8K resistor in parallel across the Piezo element to act as a visual indication since the Piezo ticking is low in volume.
I used poly film capacitors for all 4 caps and constructed the circuit on a piece of wood with bare copper wire busbars and a socket for the transistor. The Arduino code compiled and runs without problems on the genuine Uno. The base frequency with the coil I made is around 90kHz.
I'm going to add a pot and statements in the code to set Sensitivity using analogRead and map statements, but at 1500 it seems to work quite well.
Thanks for a cool project!
I made a short video demonstration of my build of the project:
http://www.youtube.com/watch?v=CJTvB079k-4
Thanks again for a neat and instructive project!
I can't get this to work. I newer get to the part of the code:
if(digitalRead(12)==LOW) //-Check NULL SW.
I have tried with 2 different push buttonts but no success.
I don't know what to try anymore. Can someone please help me? I have put Serial.print -messsages around the code and that part is newer executed. Thank you for your help!
What Arduino version are you using? I copy-pasted the sketch code directly from the link above, into the IDE and it compiled and ran properly without any alterations. But because of the way the timers are called in the code, it may be specific to the ATMega328P . I just tried it on an Arduino MEGA with the ATMega2560 chip and it does not work, but it works fine with the Uno and ATMega328P chip. I think this is because of the way the timers/interrupts are called in the sketch.
You may want to refer to the references here:
https://arduinodiy.wordpress.com/2012/02/28/timer-interrupts/
to see if modifying the timer numbers will help.
Or just try it with an Uno using the 328P chip.
Hi. Can someone draw layout for this project?
Can the author (or anyone who has successfully used the schematic) clarify the capacitor values, since the handwriting is a little ambiguous? I initially assumed the units were microfarads (μ), but my friend thinks it's nanofarads (n). Thanks!
I also thought the drawing said (μ), but if you read some of the comments above, you will read that others are using (n) and that theirs work. Look at
James Dinsmore post on November 30, 2014. Also some have videos. Like TinselKoala post from June 13, 2015.
To all the people that say that the NULL button doesn't work. You are probably not getting a signal from your oscillator. Check your circuit. Make sure you are using Nano Farad capacitors.
Nanofarads 🙂 and remember the transistor is a BC547 not 2N2222!
Good luck
Poderia me enviar o codigo que voce usou no arduino? eu iniciante em programação vai me ajudar
gilmardelalibera@hotmail.com.br
plz send me the arduino code plz plz plz
at matiurrehman96@yahoo.com
Very well done, I made it today exactly according your description except the transistor which I use the BC547 and it works fine from the beginning. I like to know or some one has a description and code for adjusting with potmeter.
Thanks
Today I use it as a pinpointer small coil around ferret rod.
Also change to sound to more high tone, see part of sketch below.
//-Click generator
if(millis()>timer)
{
timer+=10;
PCW+=FTW;
if(PCW&0x8000)
{
//digitalWrite(13,HIGH);
PCW&=0x7fff;
// Play the pitch *** Detection ***
tone(13, 3000, 30); // Play over pin D13 tone, pitch
delay(20); // delay in between
noTone(13); // Stop tone
}
else
// digitalWrite(13,LOW);
noTone(13); // Stop tone
}
The sketch refuses to compile. I get this error message:
Arduino: 1.6.7 (Windows XP), Board: "Arduino/Genuino Uno"
collect2.exe: error: ld returned 5 exit status
exit status 1
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Uno"
Build options changed, rebuilding all
metal_detektor:1: error: 'v' does not name a type
metal_detektor.ino: In function 'void __vector_11()':
metal_detektor:27: error: 't0' was not declared in this scope
'v' does not name a type
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
hi i built the metal detector but my was un stable and relly jumping around eaven when not moving anything, and when i went out in lower temperature about 0degrees celsius it went ballistic. how can i solve that problem?
i have tried it on my arduino uno r3 atmega 328 r-b ,it did not work. when up loading sketch (libray found not working).i checked circuit by powring it with 9 v battery near am radio and moved piece of metal over the coil, radio responding to metal movment. i am new to arduino and need your help. thank you
I ever read the article about how to make metal detector but I didn't have a try. we sell metal detectors, including metal detectors for kids on KingDetector
i built the oscillator circuit with some temporary materials. work fine. drifts a little at the beginning, but not bad considering im using 40 years old caps 😀
waiting for the proper components and wire. then will connect the artduino. great project.
Если 30 витков проводом 0.2 по каркас 13 см, работать будет?
to those who can not make it work. see changes i made to make it work at http://shortwa.blogspot.com/
Some findings:
1) This Sketch does not work on an Arduino Mega 2560! (this is due to the lack of the T1 pin)
2) The oszillator-circuit is some sort of "common base collpit-oscillator", try wikipedia to get more informations
3) You can definitely use an BC337-25 Transistor instead of the mentioned one
4) The capacitor values are nanofarads!
5) If you use an arduino MEGA, use the following code and Pin 47 instead of Pin 5:
// 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!!
// Präprozessor Makros
// Beeinflussen Bit Nr. y im Bivektor x
#define SET(x,y) (x |= (1< löst erst wieder in 1000 Takten vom externen Oszillator aus
t = micros() – t0; // Wieviel Zeit ist zwischen diesem und dem letzten Interrupt vergangen?
t0 += t; // Merke dir die aktuelle Zeit für den nächsten Interrupt
tflag = 1; // Lässt Loop() starten
}
void setup()
{
// Piezo-Element an Pin 13
pinMode(13, OUTPUT);
// Interner PullUp für den Null-Taster an Pin 12
digitalWrite(12,HIGH);
// Set up counter1 to count at pin 5
TCCR5A = 0; // Timer/Counter1 Control Register A
TCCR5B = 0x07; // Timer/Counter1 Control Register B, 0x07: Externe Quelle am T1 Pin, steigende Flanke
SET(TIMSK5, OCF5A); // Bei erreichen des Wertes im OCR1A soll ein Interrupt ausgelöst werden. OCF1A: Output Compare Flag 1A
// Für's debuggen
Serial.begin(9600);
Serial.println("hi there!");
}
//-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;
//Serial.println(f);
}
//-Click generator
if(millis()>timer)
{
timer+=100;
PCW+=FTW;
if(PCW&0x8000)
{
digitalWrite(13,HIGH);
PCW&=0x7fff;
}
else
digitalWrite(13,LOW);
}
}
Code above does not work since some parts of the program are missing. Does anyone of you guys have code running on an ardiuno mega 2560?
Your blog is much effective and thanks for sharing information..
Gold detector
Deep gold detector
metal detectors
Diamond detector
Water detectors
only for small metal detector ,what change this code
Voce pode me dizer quais sao os resistores da esquerda do esquema?
Does anyone have code for the arduino Mega 2560? since T1 is missing i was not able to get it run with Timer5, T5 on Pin47 :-/.
Hi. This metal detector design is very good. I'm trying to make one, but I'm having problems with the capacitors, could you tell me what voltage the capacitors are used in this circuit? Thank you 🙂