Mirko Pavleski
Published © GPL3+

DIY Very simple Arduino Metal Detector

Despite its simplicity, it has a relatively good sensitivity and perfect stability during operation

BeginnerFull instructions provided11,883
DIY Very simple Arduino Metal Detector

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
LED (generic)
LED (generic)
×3
Buzzer
Buzzer
×1
Zener Single Diode, 4.3 V
Zener Single Diode, 4.3 V
×1
search coil
×1
Resistors
×1
Capacitors
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Circuit diagram Oscillator

Schematic(Arduino Part)

Code

Arduino Code

Arduino
#include <FreqCount.h>

//the baseline frequency of the main search coil
unsigned long baseLine = 0;

//Pins red, green and blue LEDs are attached to.
const int bluePin = A2;
const int greenPin = A4;
const int redPin = A5;
const int buzzerPin = 12;


void setup() {
  //set our LED pins as outputs
  pinMode(redPin,OUTPUT);
  pinMode(greenPin,OUTPUT);
  pinMode(bluePin,OUTPUT);
  pinMode(buzzerPin,OUTPUT);
  //Flash a sequence to test the LEDs and show we are starting up  
  digitalWrite(redPin,HIGH);
  delay(200);
  silence();
  digitalWrite(greenPin,HIGH);
  delay(200);
  silence();
  digitalWrite(bluePin,HIGH);
  delay(200);
  silence();

  //Read out baseline frequency count, 100ms intervals
  FreqCount.begin(100);
  while(!FreqCount.available())
  {
    delay(10);
  }
  baseLine = FreqCount.read();

  if(baseLine > 10000)
  {
    //Green, we started up OK
    digitalWrite(greenPin,HIGH);  
  }
  else
  {
    //Red, something went wrong, we didn't get a sensible count
    digitalWrite(redPin,HIGH);
  }
  delay(1000);

  silence();
}


void loop() {
  //no sample ready yet, exit.
  if (!FreqCount.available()) {
    return;
  }
  //Read how many pulses in 100 milliseconds
  unsigned long count = FreqCount.read();
  
  long difference =  baseLine - count;
  difference = abs(difference);
  
  //Difference is large, turn on the RED led
  if(difference > 5)
  {
    digitalWrite(greenPin,LOW);
    digitalWrite(bluePin,LOW);
    digitalWrite(redPin,HIGH);
    digitalWrite(buzzerPin,HIGH);
  }
  else if(difference > 2)  //medium difference, green
  {
    digitalWrite(greenPin,HIGH);
    digitalWrite(bluePin,LOW);
    digitalWrite(redPin,LOW);
    digitalWrite(buzzerPin,HIGH);
  }
  else if(difference > 1) //small difference, blue.
  {
    digitalWrite(greenPin,LOW);
    digitalWrite(bluePin,HIGH);
    digitalWrite(redPin,LOW);
    digitalWrite(buzzerPin,HIGH);
  }
  else
  {
    silence(); //no difference, turn off all LEDs
    digitalWrite(buzzerPin,LOW);
  }

  //Auto-adjust our baseline
  if(count > baseLine)
  {
    baseLine +=1;
  }
  else if (count < baseLine)
  {
     baseLine -= 1;
  }
}

  //Turn off all output pins
  void silence()
  {
    digitalWrite(redPin,LOW);
    digitalWrite(greenPin,LOW);
    digitalWrite(bluePin,LOW);
  }
    
  

Credits

Mirko Pavleski

Mirko Pavleski

147 projects • 1271 followers

Comments