I have made a couple of metal detector circuits controlled by the Arduino
The simplest one is a self oscillating circuit that I adapted from a BFO circuit
The outputs are run to pins 2 and 3 and the pulses counted
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// LiquidCrystal lcd(2, 3, 6, 7, 8, 9);
LiquidCrystal lcd(10, 4, 6, 7, 8, 9);
volatile unsigned int ref_coil_count;
volatile unsigned int sensor_coil_count;
void setup() {
attachInterrupt( 0, ref_coil, RISING );
attachInterrupt( 1, sensor_coil, RISING );
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a splash screen to the LCD.
lcd.print("detector Test");
lcd.setCursor(0, 1);
lcd.print(" v1.0 ");
delay(2000);
}
void loop() {
int offset;
long ref_count;
long sensor_count;
ref_coil_count = 0;
sensor_coil_count = 0;
delay(1000);
ref_count = ref_coil_count;
sensor_count = sensor_coil_count;
offset = analogRead(A0)-512;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("R ");
lcd.print(ref_count);
lcd.print(" S ");
lcd.print(sensor_count);
lcd.setCursor(0,1);
lcd.print("V ");
lcd.print((sensor_count - ref_count)-offset );
delay(50);
}
void ref_coil()
{
ref_coil_count++;
}
void sensor_coil()
{
sensor_coil_count++;
}
I was using a 10k pot to adjust the balance between the coils via the analog in.