Website counter

Tuesday, April 19, 2016

adapting am radio metal detector to arduino board



I have seen on the net simple metal detector circuit which you can build yourself in 20 mint. See link www.talkingelectronics.com/html/MetalDetector.html to make clear to my last post, I used this ciruit and adapt it to arduino board to make arduino metal detector see vedio  https://www.youtube.com/watch?v=1Vw4EAmZyls  use the same sketch as befor-
// Arduino based metal detector
// (C)Dzl july 2013
// http://dzlsevilgeniuslair.blogspot.dk/

// Connect search coil oscillator (20-200kHz) to pin 5
// Connect piezo between pin 13 and GND
// Connect NULL button between pin 12 anf GND

// REMEMBER TO PRESS NULL BUTTON AFTER POWER UP!!


#define SET(x,y) (x |=(1<<y))                 //-Bit set/clear macros
#define CLR(x,y) (x &= (~(1<<y)))             // |
#define CHK(x,y) (x & (1<<y))                 // |
#define TOG(x,y) (x^=(1<<y))                  //-+

unsigned long t0=0;         //-Last time
int t=0;                    //-time between ints
unsigned char tflag=0;      //-Measurement ready flag

float SENSITIVITY= 1000.0;  //-Guess what

//-Generate interrupt every 1000 oscillations of the search coil
SIGNAL(TIMER1_COMPA_vect)
{
  OCR1A+=1000;
  t=micros()-t0;
  t0+=t;
  tflag=1;
}

void setup()
{
  pinMode(13,OUTPUT);    //-piezo pin
  digitalWrite(12,HIGH); //-NULL SW. pull up
  //-Set up counter1 to count at pin 5
  TCCR1A=0;
  TCCR1B=0x07;
  SET(TIMSK1,OCF1A);
}
//-Float ABS
float absf(float f)
{
  if(f<0.0)
    return -f;
  else
    return f;
}

int   v0=0;  //-NULL value
float f=0;   //-Measurement value
unsigned int FTW=0;    //-Click generator rate
unsigned int PCW=0;    //-Click generator phase
unsigned long timer=0; //-Click timer
void loop()
{
  if(tflag)
  {
    if(digitalRead(12)==LOW)  //-Check NULL SW.
      v0=t;                   //-Sample new null value
    f=f*0.9+absf(t-v0)*0.1;   //-Running average over 10 samples
    tflag=0;                  //-Reset flag

    float clf=f*SENSITIVITY;  //-Convert measurement to click frequency
    if(clf>10000)           
      clf=10000;
    FTW=clf;
  }
 
  //-Click generator
  if(millis()>timer)
  {
    timer+=10;
    PCW+=FTW;
    if(PCW&0x8000)
    {
      digitalWrite(13,HIGH);
      PCW&=0x7fff;
    }
    else
      digitalWrite(13,LOW);
  }
}

It does not detect gold, only metals.

Sunday, April 17, 2016

arduino metal detector

Arduino metal detector



Arduino metal detector
I have seen arduino metal detector circuit on net. see circuit
And see sketch cod: https://dl.dropboxusercontent.com/u/2248531/blog/metal_detector/metal_detector.ino
I have tried it on my arduino Uno r3 at mega 328 r-b ,it did not work. When up
loading sketch (library found not working).some did work for them, some are not.
To check if my circuit correct and working
 I checked circuit by powering it with 9 v battery near am radio and moved piece of metal over the coil, radio responding to metal movement.  
I think the reason was the timers.
He mentioned oscillator circuit feeds at around 160kHz signal to pin 5 of the Arduino
So checking if reason not working was timers of my arduino, I choose similar circuit with less kHz pulsing and it was am radio blf metal detector oscillator feeds 120 kHz. See circuit
And to make it work on my arduino with same code sketch, I just connected a wire from transistor E side to arduino pin 5 digital and reload same sketch and that is it, it worked. See modified sketch