Skip to content

Hammad-911/Metal-Discriminator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Metal Discriminator

Phase-Shift Based Metal Classification System

ATmega32A · Induction Balance Coil · Bare-Metal AVR C

Mechatronics & Robotics Engineering — Alexandria University | 2025
Ahmed Mohamed Hammad · Omar Mohab Mansour · Eyad Ahmed Sakr
Supervised by Dr. Hossam Abdelbaky


Overview

A metal discriminator that classifies metals by measuring the phase shift between a transmitted and received signal through an Induction Balance (IB) coil pair. When metal enters the field, it breaks the null balance between the two coils, producing a phase deviation characteristic of the metal type. All firmware runs bare-metal on an ATmega32A with no external libraries or frameworks.


How It Works

12V Supply → 7805 (+5V) + MAX660 (-5V)
     ↓
IRF9540N/IRF540N CMOS Oscillator (50 kHz)
     ↓
TX Coil (100 µH) ──── drives field
     ↓                        ↓
DC Bias + LM339N          RX Coil (100 µH, opposite winding)
     ↓                        ↓
TX Square Wave          TL082C Op-Amp → LM339N Comparator
     ↓                        ↓
  INT0 (PD2)             INT1 (PD3)
          ↘              ↙
          ATmega32A
       Timer1 Phase Measurement
              ↓
        100-Sample Median
              ↓
        USART @ 115200

Results

Material Phase Reading (°) Type
Air (Baseline) 353.5° Reference
Aluminium 160° – 180° Non-ferrous
Copper 130° – 150° Non-ferrous
Iron / Steel 20° – 40° Ferrous
Stainless Steel 215° – 230° Partially ferrous

Readings are before baseline subtraction. Values vary between builds — calibrate before use.


Hardware

Component Part Role
Microcontroller ATmega32A Phase measurement, median filter, USART
P-ch MOSFET IRF9540N CMOS oscillator high-side
N-ch MOSFET IRF540N CMOS oscillator low-side
Op-Amp TL082C RX signal amplification
Comparator LM339N TX and RX analog → digital conversion
Voltage Inverter MAX660 Generates −5V rail for TL082C
TX / RX Coils 2× 100 µH IB null coil pair (10cm, 13 turns, 0.5mm)
Tank Capacitors 2× 330 nF LC tank with TX coil
Power Supply 12V 2A Main input

Firmware

Written in bare-metal AVR C (no Arduino, no HAL).

Key constants:

#define PERIOD_TICKS    320.0f   // ticks per TX cycle @ 16MHz / 50kHz
#define DEAD_TIME_TICKS 240      // 15µs debounce guard
#define NUM_SAMPLES     100      // median filter buffer
#define BASELINE_DEG    126.0f   // air reading offset

Phase calculation:

int16_t diff = (int16_t)(rxCount - txCount);
diff = ((diff % (int16_t)PERIOD_TICKS) + (int16_t)PERIOD_TICKS) % (int16_t)PERIOD_TICKS;
float phase     = ((float)diff / PERIOD_TICKS) * 360.0f;
float corrected = phase - BASELINE_DEG;
if (corrected < 0.0f) corrected += 360.0f;

Resolution: ~1.125° per tick


Build & Flash

Requirements: MPLAB X IDE + AVR-GCC toolchain + ProgISP

  1. Open project in MPLAB X, set device to ATmega32A, toolchain to AVR-GCC
  2. Ensure F_CPU is defined as 16000000UL
  3. Click Clean and Build → generates .hex in dist/
  4. Open ProgISP → select ATmega32Load Flash → navigate to .hexAuto

Limitations

  • Proximity dampening — metal too close to the coil can dampen the oscillator, freezing the serial output until removed
  • Settling time — readings take 3–4 seconds to stabilize due to the 100-sample buffer; wait between tests
  • Thermal drift — continuous power draw warms the circuit over time, shifting the baseline

Future Work

  • Sleep mode — shut down oscillator during idle to reduce heat and baseline drift
  • LCD + LED output — standalone display without needing a PC terminal
  • Tare switch — on-demand baseline re-zero without reflashing

Full Report

📄 Metal Discriminator Report.pdf

The full report covers theory of operation, complete hardware design, firmware architecture, schematic diagrams, coil winding procedure, step-by-step recreation guide, and test results.


Repository Structure

├── Code/                              # Firmware source files
├── Schematic/                         # Circuit schematics
├── Metal Discriminator Report.pdf     # Full project report
└── README.md

License

Academic project — Alexandria University, 2025.

About

This project's goal is to differentiate between metals accurately by measuring phase shift between 2 coils.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages