metal detector banner

Metal detector circuit

DIY Metal detector project based on PIC12F1840 microcontroller.


This is open hardware project. It is possible to make either pinpointer or a full size metal detector based on this circuit.

Here are some links to videos made by users of the circuit:


2.Good video about how to make a pinpointer.Thanks to Juha:


One day I decided that I need a metal detector. Motivation to that came from repeatedly sawing into hidden metal inside wood with my chainsaw mill, and ruining my saw chain. So logical step was to get a metal detector. Then I researched market for metal detectors. And of course found out that cheap ones are probably crap and better ones I can´t afford. Then searched web for DIY metal detectors. I soon realised that all available circuits are not for me. Well, microcontrollers have been around now forever and those small ones are so cheap and relatively powerful. So why bother building some ancient design metal detector with several opamps and bunch of resistors and other components. Surely we can do better nowadays -- We can do it with one 8 pin PIC microcontroller and very few external components! I guess I make separate article about my sawmilling system some day.

So here is, how to build build good metal detector for only microcontroller cost, all other components and coil wire can be obtained from electronics crap laying around everywhere, and if you want to program PIC yourself, you need some programmer device compatible with PIC12F1840. I personally use PICKIT3. I bought PICKIT3 because sadly i discovered that PIC12F1840 was not supported by my JDM and Parallel TAIT programmers. If you do not have programmer you can purchase preprogrammed microcontroller from my shop.

Figure 1. This is the whole circuit:

metal detector circuit

  • Very easy to build.
  • Search coil is simple monocoil with no adjustment needed. Just wind some turns of wire and start detecting.
  • Moving mode detecting, search algorithm automatically adapts to the coil parameters and detects as those change in time. So there is no manual tuning.
  • Detects all metals. All different metals do the same beep. There is no discrimination between metals.
  • Led "power on" indication.
  • Push button ON/OFF switch
  • Low power consumption 20-50 mA
  • Runs directly from 4 NiMH cells

 Of course this is not the first version I made and probably also not the last. I kept pursuing my original goal, to keep the schematic as simple as possible with as few components as possible, yet to have good sensitivity, and this approach did cost me many hours and days of work. But it is success now -- completed detector fulfills my original needs completely. Reason I publish all details is that I want others also benefit from the hard work I have already done.

Schematic pdf file:

Download pdf file here:metaldetector.pdf (updated: 5.03.2014)

Black and white version (may be better for printing): metaldetector_bw.pdf

Parts list:

Download pdf file here:partslist.pdf (Updated: 5.03.2014)

Quick link to the PIC12F1480 datasheet:41441B.pdf

Coil making:

This circuit has been tested to work with different coils. Software algorithm automatically adapts to the coil parameters.

Basic coil is 20cm diameter, and 27 turns of 0,74mm2 electrical installation wire. Regular 0,5mm or less diameter insulated solid copper coil wire is also good. There are many good coil making instructions in the net.

Coil inductance in the circuit is given as a guide only. You can use variety of coils with different inductances. Circuit must still work. Possibly the reasonable range is 80uH to 350uH. Coil resistance about 2 ohms.

Technical description:

I call this “Pulse oscillation decay” type detector or just "Pulse oscillation" detector. In principe it is inspired by commonly known pulse induction detectors. Current pulse is sent to the coil and then response is measured. In my detector circuit the coil is not dumped by dumping resistor as found in common pulse induction detectors. High current pulse is applied to the coil and after the pulse is cut off, oscillation occurs in a tank circuit formed by search coil and capacitor in parallel with it. This oscillation is by the way relatively HIGH VOLTAGE. So all circuit must be well isolated to avoid electric shock! Oscillation is then of course decaying fast, because of losses, and because energy supply to the circuit is cut off. Mainly there are constant resistive losses in oscillator circuit, and apart from that there are EDDY CURRENT losses in possible metal target. Microcontroller just have to measure the decay time, to detect differences in oscillator circuit losses. And by all means, if resistive losses are constant, any other decay time change means there is METAL TARGET near the coil.

Coil oscillation frequency is roughly set by coil inductance and parallel capacitor value. And frequency also changes slightly depending of the target metal properties. The ferromagnetic metal target objects decrease free oscillation frequency and non-magnetic metals increase oscillation frequency. So it is even possible to discriminate between targets with this method, although this is not included in current firmware.

Oscillation maximum voltage is also dependent of the C1 value. Capacitor C1 is chosen so that voltage at the coil never exceeds about 150v, the MOSFETs rated voltage. Mosfet I use in latest working rig is IRL630. Most logic level drive 200V mosfets should work. Mosfet avalanche must be avoided, it is possibly not very stable woking region. Higher voltage mosfets have always larger on-state resistance which in turn limits maximum current for given supply voltage. It is reasonable to choose 200V maximum voltage mosfet transistor, if supply voltage is 4,8V from 4 AA NiMH cells.

Figure 2. Search coil one pulse voltage.

Metal detector html 3e5f7367

In my design pulses occur at 2 millisecond intervals. Pulse duration is 140 microseconds. Pulse timing is taken care by PIC microcontroller and MOSFET is directly driven by PIC output pin trough R3. Coil Pulse current is limited only by MOSFET on-state resistance and search coil resistance. This makes pulse current as high as possible – more sensitivity. At the same time, as pulses are very short, circuit average current consumption is very low – no need to carry huge batteries with you. Use ONLY 4 NiMH or NiCd cells to supply this circuit! There is no supply voltage limiting circuit and four Alkaline batteries voltage will be 6V, which is too high for PIC microcontroller!

I repeat: This circuit is designed to use 4 AA NIMH cells in series for power supply.

 Figure 3. Receiver side block diagram:

reciever block schematic copy

 This is equivalent circuit about what  is happening inside PIC12F1840. The PIC internal features are configured in the way shown. Input pin is configured to comparator -input, comparator +input is internally connected to Digital to Analog Converter which supplies reference, 32 voltage levels between V+ and V- possible. Comparator output is internally connected to TIMER1 gate. This valuable function only lets the Timer1 to count when comparator output is high. Program then activates Timer1 just after the coil pulse is ended and reads the value from the timer before starting the new pulse. And this is our measurement. Timer1 runs at system ferequency of 32MHz and so has resolution of 31.25nsec.

 Of course we can not let the high voltage signal reach the microcontroller. This is why there is limiting circuit of R4,D2,D3. Schottky diodes D2 and D3 dump the excessive voltage to supply rails. So voltage reaching PIC input is always in the range of supply voltage. Diodes D1 and D2 must be Schottky type, regular diodes are not fast enough and microcontroller likely gets damaged.

Figure 4. Limited voltage waveform at Microcontroller input.

oscilloscope1 PicInput 800pix

 Notice how upper part of the oscillation is almost completely limited out, and lower part is limited to negative supply V-. Oscillation center point is positive supply V+.


PIC 12F1840 firmware is written entirely in assembler using MPLAB IDE v8.83.

Firmware pushes this little microcontroller to its limits regarding speed and takes full advantage of the PIC´s on-board peripherals. Using PIC microcontroller superior power management capabilities it made possible to eliminate physical power switch form circuit. All functions are controlled only by one push button. When circuit is turned off PIC is in sleep and current draw is virtually none. Much less than NiMH batteries self discharge anyway.

Sound generator just uses timer2 to toggle speaker outputs. Speaker is connected between two outputs because this creates sort of bridge circuit, voltage is doubled, sound is stronger, and signal do not have DC offset.

PIC resources used:Interrupts, Interrupt-on-change, Sleep mode,DAC, Comparator, all Timers(Timer0,Timer1,Timer2).

More information and assembler source code on the special firmware page: Metal detector firmware page

Here is the ver1.00 hex image for PIC12F1840: POmetaldetector.hex

Printed circuit board (PCB):

Here is the PCB I designed. It is one sided board. Thumbnails links to the pdf files. The pdf file should be printed 1:1 to get correct size printout. You may or may not need mirrored image for printing depending on your PCB manufacturing technology. I recommend that PIC should be socketed, to make firmware update easier. It was not possible to incorporate "In Circuit Serial Programming"(ICSP) to this circuit, so PIC must be removed from circuit for reprogramming.PCB dimensions 30 x 60 mm. Here is also parts layout and picture of completed board:

color parts placement thumb Metal detector board thumb

PCB no mirror thumb

pcb view form bottom side mirrored:pdf

PCB mirror thumb

pcb view from the bottom (copper) side:pdf

PCBs are also available in my shop.


Discussion and information backup in the forums:

for general electronics and microcontrollers:

Thanks for everybody who participates in those forums, it has helped me a lot to go forward with this project.

Now I hope this site contains all needed information to sucessfully build the PO metal detector.

E-mail me if you have any comments: This email address is being protected from spambots. You need JavaScript enabled to view it.


since26.03.2013 --I keep updates log and history on the special page: Updates page

MetaldetectorKIT thumb

Buy KIT of parts for building the metal detector.

27.- EUR+ shipping