Arduino Nano Metal Detector
The Metal Detector project demonstrates how to build a simple Arduino‑based metal detector using an Arduino Nano, a search coil, a capacitor, and a few discrete components. When metal comes near the coil, the detector recognizes the change in the magnetic field and triggers a buzzer and LED to indicate the presence of metal.
About the Metal Detectors Project
This metal detector is based on the “pulse induction” or “LC‑circuit” principle, where a coil and capacitor form a resonant circuit. Metal objects near the coil disturb the resonance, changing the charge‑time of the capacitor, which the Arduino Nano detects by reading an analog pin repeatedly and comparing the average value to a baseline.
This is a beginner‑friendly, educational project intended for hobby and experimentation, not for professional security or treasure‑hunting applications.
Components Needed
- Arduino Nano
- Search coil (hand‑wound inductor, 100–200 turns of enameled wire, 10–15 cm diameter)
- 10 nF ceramic capacitor (or similar small capacitor)
- Signal diode (e.g. 1N4148)
- 100 kΩ resistor
- Buzzer (piezo or magnetic)
- LED (any color)
- 220 Ω resistor (for LED)
- Jumper Wires
- Breadboard
Circuit Setup
1. Connect the LC Sensor Part to Arduino Nano:
Create the LC sensing circuit as follows:
- Connect one side of the search coil to the anode of the signal diode.
- Connect the cathode of the diode to capacitor C1 (10 nF) and to Arduino analog pin A5.
- Connect the other side of the capacitor to GND.
- Place the 100 kΩ resistor between the capacitor node (A5) and GND to form a discharging path.
Use analog pin A4 as the pulse‑generation pin that drives the coil periodically.
2. Connect Indicator Devices:
- Connect the buzzer to digital pin 9 (with one pin through a small resistor or directly if it is a 5V‑compatible buzzer).
- Connect the LED anode to digital pin 10 through a 220 Ω resistor.
- Connect the LED cathode to GND.
How the Metal Detector Works
The Arduino Nano sends short pulses through the coil using the pulse pin. These pulses charge the capacitor through the coil–diode path. The Arduino then measures the capacitor voltage via `analogRead(A5)` and takes many samples to calculate a running average. When metal is near the coil, the inductance changes, altering how fast the capacitor charges, so the average value shifts from the baseline. The code detects this deviation and triggers the buzzer and LED.
A simple feedback loop ignores very small fluctuations and ignores the measurement for a short time after detecting a change, which helps avoid false triggers and stabilizes the output sound.
/*
Metal Detector using Arduino Nano
Circuit based on LC coil, 10nF cap, and diode.
*/
#define capPin A5 // Capacitor sensing pin
#define buzPin 9 // Buzzer pin
#define pulsePin A4 // Pulse pin to drive the coil
#define ledPin 10 // LED indicator pin
long sumExpect = 0; // Running sum of 64 averages
long ignor = 0; // Counter of ignored readings
long diff = 0; // Diff from expected sum
unsigned long pTime = 0; // Last time buzzer changed
unsigned long buzPeriod = 0; // Period for buzzer tone
void setup() {
Serial.begin(9600);
pinMode(pulsePin, OUTPUT);
digitalWrite(pulsePin, LOW);
pinMode(capPin, INPUT);
pinMode(buzPin, OUTPUT);
digitalWrite(buzPin, LOW);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
int minval = 1023;
int maxval = 0;
unsigned long sum = 0;
// Take 256 samples
for (int i = 0; i < 256; i++) {
// Reset the capacitor
pinMode(capPin, OUTPUT);
digitalWrite(capPin, LOW);
delayMicroseconds(20);
pinMode(capPin, INPUT);
// Send short pulses to the coil
applyPulses();
// Read capacitor voltage
int val = analogRead(capPin);
minval = min(val, minval);
maxval = max(val, maxval);
sum += val;
}
// Remove min and max to trim spikes
sum -= minval;
sum -= maxval;
if (sumExpect == 0) {
sumExpect = sum << 6; // Set initial expectation
}
long avgsum = (sumExpect + 32) >> 6;
diff = sum - avgsum;
// If the change is small, update the baseline
if (abs(diff) < (avgsum >> 10)) {
sumExpect = sumExpect + sum - avgsum;
ignor = 0;
} else {
ignor++;
}
if (ignor > 64) {
sumExpect = sum << 6;
ignor = 0;
}
unsigned long cTime = millis();
char buzState = 0;
if (cTime < pTime + 10) {
if (diff > 0)
buzState = 1;
else if (diff < 0)
buzState = 2;
}
if (cTime > pTime + buzPeriod) {
if (diff > 0)
buzState = 1;
else if (diff < 0)
buzState = 2;
pTime = cTime;
}
if (buzPeriod > 300)
buzState = 0;
if (buzState == 0) {
digitalWrite(ledPin, LOW);
noTone(buzPin);
} else if (buzState == 1) {
tone(buzPin, 2000);
digitalWrite(ledPin, HIGH);
} else if (buzState == 2) {
tone(buzPin, 500);
digitalWrite(ledPin, HIGH);
}
buzPeriod = (diff == 0) ? 1000000 : avgsum / (2 * abs(diff));
}
void applyPulses() {
for (int i = 0; i < 3; i++) {
digitalWrite(pulsePin, HIGH);
delayMicroseconds(3);
digitalWrite(pulsePin, LOW);
delayMicroseconds(3);
}
}
Instructions
1. Construction of the Search Coil:
Wind 100–200 turns of thin enameled copper wire onto a circular non‑metallic form (e.g. a plastic lid or a 10–15 cm diameter ring). Secure the turns with tape or glue so the coil stays rigid. This coil acts as the inductor in the LC circuit.
2. Circuit Assembly:
Build the LC sensor circuit and connect the buzzer and LED as described in the circuit setup. Double‑check that the diode is oriented correctly (anode toward the coil, cathode toward the capacitor and A5).
3. Code Upload:
Connect the Arduino Nano to your computer via USB, open the Arduino IDE, paste the metal‑detector code, and upload it to the board.
4. Testing:
Power the setup and bring a small metal object (such as a coin, key, or screw) near the coil. The buzzer should emit a different tone and the LED should light up when metal is detected.
Adjust the pulse count or timing in `applyPulses()` if the detector is too sensitive or not sensitive enough for your environment.
Applications
Educational Demonstrations: Use this project in classrooms or workshops to demonstrate electromagnetic induction, LC circuits, and microcontroller‑based measurement.
Hobby Metal Detection: Build a simple handheld detector for small metal objects in soil, sand, or underwater environments (with proper waterproofing).
Security Awareness: As a DIY security device, it can help beginners understand the principles used in professional metal detectors examined in airports and malls.
Troubleshooting
- No detection at all? Check the coil connections, diode direction, and capacitor; ensure the LC node is connected to A5 and the pulse pin to A4.
- False or erratic beeping? Place the detector on a non‑metallic surface, away from other coils, motors, and power cables, which can interfere with the magnetic field.
- No sound from buzzer? Verify the buzzer type (active vs passive); active buzzers need just HIGH/LOW, while passive buzzers need `tone()` or PWM.
Best Practices and Notes
- Keep the coil and sensor components away from metal‑rich environments during calibration so the baseline remains stable.
- Use a stable power supply; noisy power can cause irregular readings and false metal‑detection signals.
- For better sensitivity, experiment with different coil sizes, number of turns, and capacitor values while noting the effect on the average reading.
Extensions and Ideas
You can extend this project by adding an LCD or OLED display to show the raw or averaged sensor value, or by implementing a menu‑based system using buttons or a keypad to adjust the sensitivity threshold or detection mode. Another advanced extension is to combine the metal detector with GPS or logging to record metal‑object locations in a defined area for hobby‑level surveys.