-2
\$\begingroup\$

I did a project on automated metal detector, but I am not clear on the circuit.

I built the circuit connecting a resistor to pin A4 on the Arduino, and a diode capacitor setup in series too.

I don't understand the circuit nor why the components and their values were used. When I built it, it worked, but the sensitivity of the detector is very low. Metals with low cross sectional area are not detected at all and some with larger cross sectional area needs to touch the coil for the LED and buzzer to come on.

I wound a copper coil around a container with an area of 24cm2, the length of the coil is 0.9 cm, and the number of turns is 30.

I want to know:

  1. The explanation of the circuit and why the components were used.
  2. How to calculate the current passing through the inductor.
  3. The explanation of the code.
  4. Why these values were used for the components.
#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() 
{
  Serial.begin(9600);
  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
    pinMode(capPin, OUTPUT);
    digitalWrite(capPin, LOW);
    delayMicroseconds(20);
    pinMode(capPin, INPUT);
    applyPulses();
    
    //read the charge of capacitor
    int val = analogRead(capPin); //takes 13x8=104 microseconds
    minval = min(val, minval);
    maxval = max(val, maxval);
    sum += val;
    
    long unsigned int 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(led, LOW);
      noTone(buz);
    }  
    else if (buzState == 1)
    {
      tone(buz, 2000);
      digitalWrite(led, HIGH);
    }
    
    else if (buzState == 2)
    {
      tone(buz, 500);
      digitalWrite(led, HIGH);
    }
  }
  //subtract minimum and maximum value to remove spikes
  sum -= minval; 
  sum -= maxval;
  
  if (sumExpect == 0) 
  sumExpect = sum << 6; //set sumExpect to expected value
  long int avgsum = (sumExpect + 32) >> 6; 
  diff = sum - avgsum;
  if (abs(diff) < avgsum >> 10)
  {
    sumExpect = sumExpect + sum - avgsum;
    ignor = 0;
  } 
  else 
    ignor++;
  if (ignor > 64)
  { 
    sumExpect = sum << 6;
    ignor = 0;
  }
  if (diff == 0) 
    buzPeriod = 1000000;
  else 
    buzPeriod = avgsum / (2 * abs(diff));    
}
void applyPulses()
{
  for (int i=0; i<3; i++) 
  {
    digitalWrite(pulsePin, HIGH); //take 3.5 uS
    delayMicroseconds(3);
    digitalWrite(pulsePin, LOW);  //take 3.5 uS
    delayMicroseconds(3);
  }
}

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Sounds like you were given an assignment to design something, copied it as-is, and now you need to write a report what you did and how it was done? If the original circuit did not contain this info, we can't know either why these components were used and why their values are what they are. \$\endgroup\$
    – Justme
    Jan 11 at 12:54
  • \$\begingroup\$ If you have access to an oscilloscope, probe across the coil and see what it's doing electrically, then corroborate this with the code. \$\endgroup\$
    – rdtsc
    Jan 11 at 13:01
0
\$\begingroup\$

Metal detectors which detect metals and other conductive materials near the coil are most often based on the fact that AC current in the coil (or as well pulses) generate a changing magnetic field.

The changing magnetic field induces eddy currents to the conductive piece.

Eddy currents also generate a magnetic field which invariably cancels a part of the original field, so effectively the inductance of the coil is reduced.

There are numerous ways to detect the inductance reduction. You have a coarse inductance measuring device which as a side product generates also the needed magnetic field by feeding pulses to the coil through a resistor. The reduction of the inductance probably must be several percents before a circuit this simple (= a RL voltage divider, its output is measured with a rectifier + A/D converter) sees reliably any inductance reduction happened.

If it happens that you know nothing (including calculations) of the behaviour of coils in AC circuits, this answer, of course is useless.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.