DIY Metal detector project with PIC12F1572 (or PIC12F1840) microcontroller.


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

Ported to the PIC12F1572 at 6.08.2107. PIC12F1840 still usable also.

Figure 1. This is the circuit:

Metal detector schematic


  • Very easy to build.
  • Search coil is simple monocoil with no adjustment needed. Just use standard inductor or wind some turns of wire yourself 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.
  • Discrimination between different metals. Non-ferrous result in lower tone than ferrous metals.
  • Led "power on" indication.
  • Push button ON/OFF switch
  • Low power consumption 20-50 mA
  • Runs directly from 4 NiMH cells
  • Basic discrimination features. Gold makes slightly different sound from iron.
  • In circuit programming (ICSP) connector for easy firmware uploading. NEW!

  I keep pursuing my original goal, to keep the schematic as simple as possible with as few components as possible, yet to have good sensitivity. Reason I publish all details is that I want others also benefit from the hard work I have already done.

Design files:

Version 3.00:

Quick link to the PIC12F1840 datasheet:41441B.pdf

Firmware source code version 1.80:;   HEX file for



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 copper 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 internet.

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 150μH to 470μH. Coil resistance in the range of 0,25 to 2 ohms.

For pinpointer it is preferred to use off the shelf ferrite core inductor for the coil. I've found that 470μH and 1,8A 0,28Ω rating works fine.



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.

Technical description:

I call this “Pulse oscillation decay” type detector or just "Pulse oscillation" detector. In principle 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, and this function is included in latest 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 IRLI630. Most logic level drive and 150V MOSFETs should work. MOSFET avalanche must be avoided, it is possibly not very stable working region. Higher voltage MOSFETSs have always larger on-state resistance which in turn limits maximum current for given supply voltage. Therefore it is reasonable to choose MOSFET transistor with 200V maximum voltage, if supply voltage is 4,8V (taken from 4 NiMH cells).


Figure 2. Search coil one pulse voltage.

coil voltage


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 NIMH cells(AA or AAA) in series for power supply.


 Figure 3. Receiver side block diagram:

 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 frequency 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 D2 and D3 must be Schottky type, regular diodes are not fast enough and microcontroller likely gets damaged. (To be exact I also tried the circuit without the diodes D1 and D2 and it seemed to work well because of the PIC internal protection diodes, but there is too few testing done to really reccommend that as standard practice.)


Figure 4. Limited voltage waveform at Microcontroller input.

Voltage at PIC input

 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 firmware is now written in assembler using MPLAB X environment. When I started the project I used  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).

Active version 2.00:


  • Slight discrimination between different metals. The non-ferrous metals make lower tone than ferrous metal(iron).
  • Single button push turns detector on.
  • Double push on the button changes operating mode.There are 4 modes:
  1. discriminating mode, standard on/off sound
  2. gradual beeping(distance indication), now with discrimination
  3. discriminating mode, less filtered than mode1
  4. silent mode, only LED on/off
  • Longer push on the button turns detector off

Source code version 2.00 (for PIC12F1572) whole MPLAB X

Firmware source code version 1.80:  HEX file for PIC:HEX file (for PIC12F1840)

Older versions (no discrimination yet):

version 1.25 with RS232 (COM port) communication(10.01.2013) assembler source ver1.25 hex file:metaldetector125.hex

Button double push activates the serial rs232 sending, single push returns to normal mode, longer push turns power off.

ver1.10(22.12.2012):metaldetector110.asm ver1.10 hex file:metaldetector110.hex This is not recommended version, but I leave it here for now.

Ver 1.00 :metaldetector100.asm  Ver1.00 hex file :metaldetector100.hex  most basic version but works. No discrimination.

Printed circuit board (PCB):

Currently there is three versions of PCB-s designed.

V1.00 First version was one sided board.

V2.00 version was two sided board (actually by design may work with only bottom layer) but when I designed second version I converted to newer Kicad version and redraw the schematic, and did accidentally swap the LED connection and piezo speaker connection to PIC pins (5;6). So  ver.2.00 need slightly modified firmware. But I already managed to order bunch of those boards from the PCB factory. Non of those boards shipped from my shop.

V3.00 is two sided board. Compatible with version 1.00 with following improvements:

  • C2 and Q1 mounted horizontally to enable mounting the circuit inside the tube.
  • now has mounting holes in the corners
  • switch mounting in the center position, to enable better button shaft mounting
  • ICSP connector

I recommend that PIC should be socketed, although ver.3 board have "In Circuit Serial Programming"(ICSP) possibility. PCB dimensions 30 x 60 mm.

PCBs and kits of parts are also available in my shop.

Users contributions:

Here is exellent article by Robert Batey  KF7FTQ of his coil and detector construciton. With his kind permission the pdf file:my_md_article.pdf (5,5Mb)

Here is a video of one possible decent construction at the Frozen Toes Entertainment youtube channel:


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 working metal detector.

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