Metal detector (Part 1)

Dear cousin, I lost my keys in the middle of the meadows, would you please make a metal detector for me ? Urgent !

This is really how this project started ! More or less, as I have in mind the design of an Earth’s Field Nuclear Magnetic Resonance spectrometer which features magnetic fields sensors on which I already spent some time.

I started this metal detector project with a quick look at published projects on the web. Most, not to say all, projects feature a magnetic field sensor. The principle of operation consists in observing the changes in the magnetic permeability of the volume located on both sides apart a coil. There are multiple ways to implement this principle. One consists in emitting a magnetic pulse and measuring the strength of the echoed signal. The other consists in measuring the changes in frequency of a resonating tank. Both have their advantages and drawbacks. After few attempts, I decided to go for the second option which is far simpler in terms of mecatronics and electronics.

As mentioned above, the heart of the device is a resonating tank made of a coil and two capacitors. This configuration is known as the Collpits oscillator, named after its inventor Edwin H. Colpitts. The resonating frequency depends on the C1, C2 and L1 values, f = 1 / 2 . Pi . sqrt(L1. (C1 . C2) / (C1 + C2)).

Bipolar junction transistors, FET transistors or integrated op-amplifiers must be used to softly bias the oscillator and maintain a perpetual oscillation. I will use very popular small signal transistors such as the NPN 2N3904 or the 2N2222. For the passive components, I choose the following values: C1 = C2 = 10 nF and L1 = 600 µH, which results in a theoretical 92 kHz oscillating frequency. The reason for these choices lies in the capability of Arduino interrupts to cope with high frequencies. Staying close to 100 kHz was the objective and it proved to be alright. Various configurations exist and are described below:

First configuration:

C3 = 100 nF, R1 = R2 = 5 k, R3 = 1 k

Second configuration:

R1 = 100 k, R2 = 1 k, C3 = 10 nF

Third configuration:

C3 = 100 nF, R1 = R2 = 5 k, R3 = 1 k

Fourth configuration:

C3 = 1 nF, R1 = 470 k

Fith configuration:

C3 = 1 nF, C4 = 100 nF, R1 = R2 = 5 k, R3 = R4 = 1 k

As mentioned before, C1, C2 and L1 were chosen so that the resonating frequency is compatible with the sensing performances of the micro-controller. The use of lower frequencies will result in lower frequency shifts when a metallic object is present near the coil thus reducing the overall performances of the detector. I chose the first configuration which features a clean sine signal swinging from almost 0 V to almost 5 V.

The code is very straight forward in its basic version. Advanced users will add refinement for fine tuning the signal and taking into account frequency drifts caused by temperature mainly. It consists in sampling the number to cycles per second. The frequency stays idle at about 96 KHz and rises up to about 97 kHz when a metallic part enters the magnetic field.

volatile uint32_t pulse_counter; 
void setup(void) 
	/* Initialize the serial port */
	/* Configure sensing pin (Digital pin 2)*/
	pinMode(2, INPUT); 
	attachInterrupt(0, count_pulse, RISING); 
void loop(void) 
	/* Reset counter */
	pulse_counter = 0; 
	/* enable interrupts */
	/* disable interrupts */
	/* Plot data */
	Serial.print(millis() / 1000.0, 1); 
 /* Called when interrupted */
void count_pulse(void) 
	pulse_counter += 1; 


Time to use the metal detector… Well, it is not very sensitive however, it will do the job for finding keys fallen in the the grass.

Hello cousin ? No more worries, the keys were in my pocket ! Thanks anyway !

Well the followers of arduinoos will benefit from this quick and dirty project. Advanced users may decide to improve the design, starting from a the thermal stabilization of the oscillator as it is sensitive to temperature changes and drifts.






Leave a Reply

You must be logged in to post a comment.