Metal Detector using Arduino

Metal Detector is a security device which is used for detecting metals which can be harmful, at various places like Airports, shopping malls, cinemas etc. Previously we have made a very simple Metal detector without a microcontroller, now we are building the Metal Detector using Arduino. In this project, we are going to use a coil and capacitor which will be responsible for the detection of metals. Here we have used an Arduino Nano to build this metal detector project. This is very interesting projects for all electronics lovers. Wherever this detector detects any metal near it, the buzzer starts beeping very rapidly.


Required Components:

  1. Arduino (any)
  2. Coil
  3. 10nF capacitor
  4. Buzzer
  5. The 1k resistor
  6. 330-ohm resistor
  7. LED
  8. 1N4148 diode
  9. Breadboard or PCB
  10. Connecting jumper wire
  11. 9v Battery


Working Concept:

Whenever some current passes through the coil, it generates a magnetic field around it. And the change in the magnetic field generates an electric field. Now according to Faraday's law, because of this Electric field, a voltage develops across the coil which opposes the change in magnetic field and that’s how Coil develops the Inductance, means the generated voltage opposes the increase in the current. The unit of Inductance is Henry and formula to measure the Inductance is:

L = (μο * N2 * A) / l

L- Inductance in Henries
μο- Permeability, its 4π*10-7 for Air
N- Number of turns
A- Inner Core Area (πr2) in m2
l- Length of the Coil in meters


When any metal comes near to the coil then coil changes its inductance. This change in inductance depends upon the metal type. It's decreases for non-magnetic metal and increases for ferromagnetic materials like iron.

Depending on the core of the coil, inductance value changes drastically. In the figure below you can see the air-cored inductors, in these inductors, there will be no solid core. They are basically coils left in the air. The medium of flow of magnetic field generated by the inductor is nothing or air. These inductors have inductances of very less value.

Air Cored Inductors


These inductors are used when the need for values of few microHenry. For values greater than few milliHenry these are not a suitable one. In below figure you can see an inductor with ferrite core. These Ferrite Core inductor has very large inductance value.

Ferrite Core Inductors


Remember the coil wound here is a air cored one, so when a metal piece is brought near the coil, the metal piece acts as a core for the air cored inductor. By this metal acting as a core, the inductance of the coil changes or increases considerably. With this sudden increase in inductance of coil the overall reactance or impedance of the LC circuit changes by a considerable amount when compared without the metal piece.  


So here in this Arduino Metal Detector Project, we have to find inductance of the coil to detect metals. So to do this we have used LR circuit (Resistor-Inductor Circuit) that we already mentioned. Here in this circuit, we have used a coil having around 20 turns or winding with a 10cm diameter. We have used an empty tape roll and wind the wire around it to make the coil.

Coil of Metal Detector


Circuit Diagram:

We have used an Arduino Nano for controlling whole this Metal Detector Project. A LED and Buzzer are used as metal detection indicator. A Coil and capacitor is used for detection of metals. A signal diode is also used for reduce the voltage. And a resistor for limiting the current to the Arduino pin.

Arduino Metal Detector Circuit Diagram

Metal Detector using Arduino hardware implementation


Working Explanation:

Working of this Arduino Metal Detector is bit tricky. Here we provide the block wave or pulse, generated by Arduino, to the LR high pass filter. Due to this, short spikes will be generated by the coil in every transition. The pulse length of the generated spikes is proportional to the inductance of the coil. So with the help of these Spike pulses we can measure the inductance of Coil. But here it is difficult to measure inductance precisely with that spikes because that spikes are of very short duration (approx. 0.5 microseconds) and that is very difficult to be measured by Arduino.

Metal Detector using Arduino in action

So instead of this, we used a capacitor which is charged by the rising pulse or spike. And it required few pulses to charge the capacitor to the point where its voltage can be read by Arduino analog pin A5. Then Arduino read the voltage of this capacitor by using ADC. After reading voltage, capacitor quickly discharged by making capPin pin as output and setting it to low. This whole process takes around 200 microseconds to complete. For better result, we repeat measurement and took an average of the results. That’s how we can measure the approximate inductance of Coil. After getting the result we transfer the results to the LED and buzzer to detect the presence of metal. Check the Complete code given at the end of this Article to understand the working.


Complete Arduino code is given at the end of this Article. In programming part of this project, we have used two Arduino pins, one for generating block waves to be fed in Coil and second analog pin to read capacitor voltage. Other than these two pins, we have used two more Arduino pins for connecting LED and buzzer.

You can check the complete code and Demonstration Video of Arduino Metal Detector below. You can see that whenever it detects some metal the LED and Buzzer starts to blink very fastly.


#define capPin A5
#define buz 9
#define pulsePin A4

#define led 10

long sumExpect=0; //running sum of 64 sums 
long ignor=0;   //number of ignored sums
long diff=0;        //difference between sum and avgsum
long pTime=0;
long buzPeriod=0; 

void setup() 
  pinMode(pulsePin, OUTPUT); 
  digitalWrite(pulsePin, LOW);
  pinMode(capPin, INPUT);  
  pinMode(buz, OUTPUT);
  digitalWrite(buz, LOW);
  pinMode(led, OUTPUT);

void loop() 
  int minval=1023;
  int maxval=0;
  long unsigned int sum=0;
  for (int i=0; i<256; i++)
    //reset the capacitor
    //read the charge of capacitor
    int val = analogRead(capPin); //takes 13x8=104 microseconds
    minval = min(val,minval);
    maxval = max(val,maxval);
    long unsigned int cTime=millis();
    char buzState=0;
    if (cTime<pTime+10)
      if (diff>0)
      else if(diff<0)
    if (cTime>pTime+buzPeriod)
      if (diff>0)
      else if (diff<0)
    if (buzPeriod>300)

    if (buzState==0)
      digitalWrite(led, LOW);
    else if (buzState==1)
      digitalWrite(led, HIGH);
    else if (buzState==2)
      digitalWrite(led, HIGH);

  //subtract minimum and maximum value to remove spikes
  if (sumExpect==0) 
  sumExpect=sum<<6; //set sumExpect to expected value
  long int avgsum=(sumExpect+32)>>6; 
  if (abs(diff)<avgsum>>10)
  if (ignor>64)
  if (diff==0) 

void applyPulses()
    for (int i=0;i<3;i++) 
      digitalWrite(pulsePin,HIGH); //take 3.5 uS
      digitalWrite(pulsePin,LOW);  //take 3.5 uS


Comments (14)

  • Kiran k v's picture
    Kiran k v

    Please send me the synopsis and full details of the project sir..

    Feb 13, 2018
  • Ghanim Radi khudear's picture
    Ghanim Radi khudear

    what the type of wire used in project ? diameter of wire

    Feb 28, 2018
  • AISHA's picture

    These are normal breadboard wires

    Mar 01, 2018
  • Ghanim Radi khudear's picture
    Ghanim Radi khudear

    but ? i need the think of wire used just that

    Mar 01, 2018
  • asd's picture

    what is the thickness of the wire to do the Coil???

    Mar 08, 2018
  • WhoIs's picture

    Very nice project , I have successfully made it using arduino uno r3, but the only problem I have experienced is it can't detect small objects like small leds, alligator clips, .. Is it okay that I used the built in USB-B Port of arduino connected to 5k Mah power bank as power supply?

    Mar 28, 2018
  • Mahesh's picture

    I have a UNO R3 too, is there any difference in circuit and code..Please can you help me through if there is any difference.

    Mar 29, 2018
  • Kiran k v's picture
    Kiran k v

    Bro how u build the electric wire coil

    Apr 07, 2018
  • kiran's picture

    please send me the correct code
    i have check the above program but it shows some error. so please mail the code sir.

    Apr 10, 2018
  • Lokeshwar's picture

    I could not able to able get the exact output. My LED and buzzer are blinking as such in a some random manner. I suspect my output is not right coz, even if i keep the metal very close to it, it is not working. Please help me .....
    Thanks in advance.

    Apr 13, 2018
  • Amit pratap's picture
    Amit pratap

    I m using coil , not wire it help me or not...if it can't help me which wire I used breadboard wire...
    Plz tell me ...plz

    Apr 04, 2018
  • B.Aswinth Raj's picture
    B.Aswinth Raj

    Coil should have also worked, just make sure if it is enameled!! The wire used here is normal breadboard wire 

    Apr 06, 2018
  • melvin poulose's picture
    melvin poulose

    high qaulity

    Apr 06, 2018
  • akif's picture

    can i use different diameter of tape to measure the sensitivity of the search coil? or it will effect the faulty of circuit?

    Apr 17, 2018

Leave a comment

TI Logo

TI Training        Learn. Solve. Innovate.