Monday, July 22, 2013

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 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!



45 comments:

  1. Great build! What was the model # of the Ikea lamp you used?

    ReplyDelete
  2. Awesome! I might have to build one with my son. I think an ATtiny45 would be enough...

    ReplyDelete
    Replies
    1. 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"

      Delete
  3. Great project! How sensitive did it turn out to be? how far(deep) can it detect a coin sized object ?

    ReplyDelete
  4. Nice ! Few days ago I decided to build one with my father, too. Odd :).
    What diameter is your wire ?
    Copper I guess ?

    ReplyDelete
  5. 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..

    ReplyDelete
    Replies
    1. Tiny45/85 came to my mind as saw the schematic too!

      Delete
  6. Well Done! I would appreciate if you elaborate a bit the frequency oscillation part of the circuit.

    ReplyDelete
  7. A very interesting project! The transistor must be necessarily 2n2222?
    I used the KT315, did not work.

    ReplyDelete
    Replies
    1. 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...

      Delete
    2. I actually ended up using BC547

      Delete
  8. 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)

    ReplyDelete
    Replies
    1. Remember to press and hold the NULL switch for a couple of seconds

      Delete
  9. Давно искал. Спасибо!

    ReplyDelete
    Replies
    1. собрал, пока не заработала, возможно я не правильно собрал, завтра буду еще пробовать, если у тебя заработало отпишись сюда пожалуйста

      Delete
    2. Собрал, работает. Транзистор поставил bc107b, но дальность обнаружения не большая. Разобраться бы как настроить

      Delete
    3. А катушку мотал как они писали ? просто я сделал 15 витков и может быть по этому не работает ?

      Delete
    4. Катушку мотал 30 витков, провод 0.33

      Delete
  10. 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!

    ReplyDelete
    Replies
    1. Cool. Thought about that too :) Let me know if it works.

      Delete
  11. What you need to do to change the sensitivity?

    ReplyDelete
    Replies
    1. Change the value in the code and reprogram

      Delete
  12. 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:(

    ReplyDelete
  13. Заработал ли у кого нибудь на Arduino UNO?
    PIN 5 analog или PIN 5 digital?

    -----------------------------------------------

    runs on Arduino UNO?
    PIN 5 PIN 5 analog or digital?

    ReplyDelete
  14. 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.

    ReplyDelete
    Replies
    1. 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?)

      Delete
  15. Hi what kind of capacitor did u use ? ( AC / DC ) ?

    ReplyDelete
  16. 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!

    ReplyDelete
  17. 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!

    ReplyDelete
  18. please tell me how to do a sketch that was not PIN5 the other?

    ReplyDelete
  19. Подскажите пожалуйста, как поменять в скетче номер пина (5) на как либо другой, никак не могу запустить этот девайс, есть подозрение что что-то с пином не то

    ReplyDelete
  20. Which construction of coil is the best? red or blue?

    ReplyDelete
  21. http://www.youtube.com/watch?v=qlUoBzxPgv4
    how to make coil

    ReplyDelete
  22. Could you clarify capacitor types and values please?

    ReplyDelete
  23. 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!

    ReplyDelete
  24. Are you sure this circuit works??? anyone here tested it, cause most of people here have issues.

    ReplyDelete
  25. 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!

    ReplyDelete
  26. 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!

    ReplyDelete
  27. 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?

    ReplyDelete
  28. 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.

    ReplyDelete
  29. 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

    ReplyDelete
  30. 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!

    ReplyDelete
  31. 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;
    }

    ReplyDelete