Learn how to build a metal detector using a Colpitts oscillator and an Arduino.

How Do Metal Detectors Work?

Tank circuit

The tank circuit


In the above circuit, the series capacitor and inductor form a tank circuit. In a tank circuit, energy is transferred repeatedly between a capacitor and an inductor, resulting in oscillation. Current discharged from the capacitor flows through the inductor; when the capacitor is completely discharged, the inductor's decreasing magnetic field maintains the current flow. The capacitor will then charge with the opposite polarity, and when the magnetic field has completely collapsed, the capacitor will discharge, resulting in current flow in the direction opposite to that of the original current. This cycle continues.

The inductor of the above tank circuit forms the detector of the metal detector (a large coil of wire). When metallic material approaches the center of the inductor (the detector coil), it enters the magnetic field created by the inductor. This changes the magnetic permeability of the inductor’s core, causing the inductance to change. The change in inductance, in turn, changes the oscillating frequency of the tank circuit.

If the components were ideal, the tank circuit would oscillate indefinitely without an external power source. But, in practice, the components are non-ideal. The unwanted resistance of the components will introduce energy loss, causing the oscillating current to taper to a stop. To counter this, a single stage BJT inverting amplifier is used to continuously add gain into the tank circuit.


Colpitts oscillator

The Colpitts oscillator


Since the oscillation at the nodes before and after the inductor are 180° out of phase of with each other, one of the nodes will supply the oscillation to the transistor base, amplify and invert the signal at the collector, then return it in phase to the other node of the tank circuit. This entire circuit is called the Colpitts oscillator.

The Colpitts oscillator above provides a steady oscillation with a frequency in the 100kHz range. Metals from household items changing the permeability of the inductor core will fluctuate this frequency around 10kHz. Since this frequency range is outside of the human audio spectrum (20Hz to 20kHz), we will need to translate the oscillation into an audible tone.

Traditional BFO (beat-frequency oscillator) metal detectors overcome this problem by incorporating another tank circuit with a fixed frequency equal to the frequency of the detector tank circuit without the influence of any metals. Then, taking the difference between the two frequencies will isolate the fluctuating frequencies of the detector circuit and bring it down to an audible range.

For this metal detector project, we will be using an Arduino to process the oscillation signal instead of offsetting the oscillation with a second tank circuit. The Arduino will store the fixed frequency and continuously compare the incoming frequency of the detector circuit with the stored frequency (more on the Arduino program below).


Materials for your DIY Metal Detector

Weed-whacker toy


For this project, a toy weed-whacker was chosen to house all the components. It includes the following features:

  • a trigger button, which we will repurpose to trigger the speaker
  • a side button, which we will use to set the fixed frequency
  • a battery compartment (3xAA batteries) with an ON/OFF switch
  • a speaker, which we will play the tone through
  • a motor with LEDs attached which we will be activated when the frequency difference exceeds a certain threshold
  • a circular head where we will fit a coil of wire into for the inductor of the tank circuit 

We will also add a potentiometer (silver) to make the sensitivity of the tone changes adjustable.


Detector coil


The inductor coil is made from approximately 50 wraps of 26 AWG wire around a spool of 5.5 inches in diameter.


Inside the housing


Inside the housing, we will replace the original circuit board with our own circuit and attach all the peripherals to the circuit with pin headers.


Metal Detection Circuit Schematics

Full schematics


I used an Arduino UNO to program a DIP ATMega328. I then removed the ATMega328 from the development board and embedded into a perfboard along with the rest of the circuit.

The Colpitts oscillator, on the bottom left on the diagram, feeds the oscillation into counter 1 (pin T1) of the chip (marked as digital pin 5 on the Arduino UNO), where it constantly counts the frequency of oscillation.

On the top level of the diagram, a power supply of 4.5V (3xAA batteries, with bypass capacitors) is used to power the ATmega328, oscillator, speaker, and motor (with LEDs).

To keep the current draw of the microcontroller’s digital pins at a safe level (40 mA per pin maximum for the ATmega328), an NPN transistor (C2878) is used to drive the speaker, and an N-channel MOSFET (SUB45N03) to drive the motor.

Both the trigger and reset (sets fixed frequency) switches are wired to digital pins using internal pull-up configuration. Small capacitors are added in parallel to debounce the switches.

The sensitivity potentiometer is set up as a voltage divider, and the division is read using an analog pin.


Code Walkthrough

The full source code for this project can be found here:

Below is a detailed walkthrough of the code.


Setup Function

To keep track of the detector oscillation frequency through timer counter 1, we first need to configure the timer/counter controller registers (TCCR). These TCCRs are accessed through the three integers: TTCR1A, TTCR1B, and TTCR1C.


                    TCCR1A = 0b00000000;
TCCR1B = 0b00000111;

We will need to set the waveform generation to normal mode by setting the WGM flags of TCCR1A and TCCR1B to 0, and set the clock speed selection mode to external clock source by setting CS flags of TCCR1B to mode 3 (external clock on rising edge). In this configuration, the register OCR1A will decrement by 1 every time a rising edge is detected from the oscillation.


                    TIMSK1 |= (1 << OCIE1A);

Next we'll need to enable timer/count interrupt A by setting the OCIE1A flag in TIMSK1 register. This will enable the SIGNAL(TIMER1_COMPA_vect) interrupt function to be called whenever OCR1A register reaches 0.


                    OCR1A = 1;

Now initialize OCR1A to 1 so that the interrupt function is called as soon as the first rising edge is detected.


Interrupt Function

This is the SIGNAL(TIMER1_COMPA_vect) function. It's called when the OCR1A register reaches 0. In this function, we want to keep track of the number of microseconds elapsed since the last time the function was called. This time delta is stored as signalTimeDelta.

storedTimeDelta is the “fixed frequency” time delta that signalTimeDelta is compared to in the main loop. storedTimeDelta is set to signalTimeDelta when storedTimeDelta is zeroed (on bootup and when the reset switch is pressed).


                    OCR1A += CYCLES_PER_SIGNAL;

After performing interrupt operations, OCR1A needs to be reset by incrementing it with our predefined constant, CYCLES_PER_SIGNAL (number of cycles before next interrupt occurs).


Loop Function

In the loop function, we check if the trigger is pressed. If so, then read the analog value of the sensitivity potentiometer and linearly interpolate the analog value (0 to 1023) to an easier to use scale (0.5 to 10.0).


                    int storedTimeDeltaDifference = (storedTimeDelta - signalTimeDelta) * sensitivity;

The difference between the fixed frequency (storedTimeDelta) and measured frequency (signalTimeDelta) is calculated and multiplied by the sensitivity value.


                    tone(SPEAKER_PIN, BASE_TONE_FREQUENCY + storedTimeDeltaDifference);

This value is then summed with an audible base tone frequency, BASE_TONE_FREQUENCY, and played out the speaker using the Arduino tone() function.

If the difference exceeds the threshold defined by SPINNER_THRESHOLD, then the motor is activated.

If the trigger is released, then the speaker tone is stopped (by calling noTone() function) and the motor is deactivated.

If the reset button has been pressed, it will zero storedTimeDelta, allowing the next interrupt call to set a new value.


How Functional is Our Arduino-Based Metal Detector?

With the lowest sensitivity setting, the metal detector can pick up large items like soda cans, cell phones, and iron tools within a few inches away from the coil. On the highest sensitivity setting, smaller items like steel rings, screws, and coins within the same proximity can also be detected. See the video at the top of the article for a demonstration!

To extend the range of the detector, we can increase the magnetic field area created by the inductor. This can be achieved by increasing the current flow through the inductor (by increasing voltage input to the oscillator, allowing a greater gain in the amplifier), or by increasing the number of wire wraps in the inductor coil.

With an Arduino-based metal detector, we can do other interesting things that cannot be done with traditional BFO metal detectors. Stay tuned for future projects on how we can take advantage of this metal detecting mechanism for other purposes!


  Metal Detector Arduino Code  

Give this project a try for yourself! Get the BOM.




  • AEKron 2016-10-03

    We didn’t have Arduinos when I mead my metal detector in 8th grade electronics class back in 1973. We did get to make the PCB, vacu-form the coil mold, and pour acrylic plastic into the mold for the detector.
    Mine never worked…

  • upand_at_them 2016-10-03

    When the magnetic field of an inductor collapses the current created flows in the SAME direction as the current that charged it.

  • Fixate 2016-10-08

    Hey Evan!

    Do you have any specs on the performance of this metal detector? (Penetration, size of the detection “box”)

    Also, how can we make it BETTER?? smile
    (More penetration)

    • redrooster01 2016-10-10

      He explained how to do that when he said how to extend the range? More Voltage=more current=more gain=more magnetism=more penetration. Oh and more windings on the coil. lol

  • ali bakhtiyari 2016-12-15

    Can i use this oscillator circuit with a bigger loop( 1.8×1.8 meters about 130uH) and arduino due to make a car detector?

  • Albert Albert 2017-09-18

    how to increase voltage input to the oscillator , is it safe to use a 12v power supply instead of 4.5v ?

    • Robert Keim 2017-09-26

      You would have to check to see if your microcontroller board can tolerate a 12V power supply.

  • EasyGoing1 2017-10-05

    VERY nice write-up - well done with excellent detail!  I need to build something like this but the loop needs to be about 1.5 feet in diameter to detect the passing of a bullet. Your article has helped in my pursuit.  Thank you

    • xmass 2018-01-03

      did you finished your “bullet passing” project? I used a computer soundcard, two ir leds and sensors, two AA batetries and Audacity to count the time passed from first impulse to the second one; it was an airsoft chronograph

  • bassmanjess 2018-01-19

    hi, i put this oscillator circuit together on a bread board but the most variation on the frequency is about 100hz. the article says it should be about 100 times that. i am measuring the frequency with my multimeter, could this be doing anything to the circuit? or maybe the breadboard?
    any help on this would be appreciated.

    • RK37 2018-02-01

      I wouldn’t expect a multimeter or a breadboard to cause that amount of deviation from the expected frequency. A great way to get help with a problem such as this is to post it as a question in the forum.

  • AlexOlesco 2018-03-29

    Any one already try this?, how’s the range of this, in how many meters? Thanks

  • abe_akif 2018-04-23

    hi. may i know length of the wire that you use i search coil? and how about simulation that you used in this project?

  • CONN1 2018-05-24


  • Erik84750 2018-10-27

    Nice program, works well. However oscillator needs minimal 10V to supply stable and usefull signal, preferably even 20V. Also would be advisable to use 100nF cap from collector to output in order to eliminate the DC component; also recommended to use 74HC132 schmitt trigger to supply nice square wave to the Arduino input.

  • hamid reza 2019-01-05

    I want to use gold to find it. Will it be?
    What is the rumor of finding metal?

  • boiporitto 2019-04-30

    I am interested actually about gould nuggets and treasure. Can it be used for detecting Gold? If yes, then awesome. If not, please suggest me the best option as per your knowledge.

  • Slarti Fartfast 2019-07-07

    Nice work,  Evan;  I subbed a 548 transistor for the 338, used a smaller 45 turnx50mm coil from another (failed) detector project, and dropped the buzzer and motor control stuff in favour of a simple LED alert on pin 9, and it still worked!  My plan is for this to be a cat detector (triggered from copper wire in their collars!) because my RFID detector wasn’t sensitive enough.

    (yeah, I know - if the neighbours put a bell on THEIR cat , he might get past, but hey I’ll worry about that then!)

  • Ajeet Rajawat 2019-07-16

    you are using a crystal on your pcb circuit… but you never says anything about it ... and not showing in our circuit diagram…