Metal detector with arduino

For a college project I have to build a metal detector that only indicates that its detected something if its been there for three seconds (like a traffic light)
I have access to many parts and wires
it is not necessary but I thought it would be easy to use an arduino

right now I have a collpitts oscillator with an inductor acting as the metal detector so when metal gets close to the coil the width of the oscillations increase from 12us to 20us
I thought I could use the pulseIn() function but after thinking about it I am worried that it won't read high as my peak to peak voltage of the sine wave is 340mV
I tried using an operational amplifier to increase the voltage but I couldn't get it to work.
Is this correct or is there a better way to do this?

You could certainly read this with an Arduino but I would have thought that you are better to read it using an analog pin so that you can set your threshold to whatever value you wish.

At the moment your peak is 340mV, which is only 7% of the full 5v range - not great for accuracy.

However, the Arduino has other internal voltage references and also can take an external reference signal: analogReference() - Arduino Reference

Make sure nothing is connected to the Arduino Analogue reference pin and then try:

analogReference(INTERNAL1V1);

That will set your analogRead function to use the internal 1.1V reference signal. You then have a peak at around 30% of the full-range, which is entirely workable.

Then you simply write a sketch that measures for one second and increments a counter every time the signal goes above 250 (for example) and then drops again. At then end of your second, compare the number of counts with a threshold value (e.g. less than 65,000 and you say you have detected something). Obviously, you could measure for less time, but why do you need to?

Three positive results in a row are then taken as a detection and you light an LED (or similar).

The thresholds may need tweaking but it should work well. Why not output the numbers to serial to start and see what you measure under "detecting" and "not detecting" conditions and pick thresholds appropriately.

Hope I'm not barking up the wrong tree here.

Ugi

Thank you so much!
this information was very helpful with my project which I procrastinated doing until today

Dr_Ugi:
You could certainly read this with an Arduino but I would have thought that you are better to read it using an analog pin so that you can set your threshold to whatever value you wish.

The Arduino A/D samples at about 10ksamples per second. That means between samples 100us will pass. The signal being detected only lasts 20us. That's going to present a problem.

montyman77:
I tried using an operational amplifier to increase the voltage but I couldn't get it to work.

What did you try and what actually happened?

You need the pulseIn() for accurate pulse dectection.
Perhaps one or two transistors is enough to make a digital signal. At least that is easier than an OpAmp.

I agree with the others, that the Arduino is a good choice for this project. The detection circuit needs a few analog components. You have to figure out how to do that.

The magnetometer HMC5883L is a cheap compass with digital interface. It can be used to detect metal, like cars.

Can you show a schematic of your oscillator circuit? 340mV seems very low for the peak voltage. What are you using for an inductor?

Try biasing the op-amp + input to 2.5V with a resistive divider made with two 10k resistors. Feed the output of your oscillator thru a capacitor (1uF?) then thru a 100 ohm resistor into the - input of the op-amp. Place a 4.7k resistor from the output of the op-amp back to the - input. This will give you a gain of approximately 50. You'll need to use an op-amp that has plenty of gain left at 100kHz.

Thanks for the input my project is now finished and this is what I ended up doing
I'm sure there are better ways but that's what ended up working for me

/* ELEC 294 Challenge Lab 
 Brendan Montgomery 10013551 Mar 2013 */

//pins
#define GreenLED 2
#define RedLED 3
#define VoltagePIN 4
#define Threshold 900
int oldTime;
long count;
int superCount=0;
int time;
int voltageIN;

void setup(){
  //analogReference(INTERNAL1V1);
  pinMode(GreenLED,OUTPUT);
  pinMode(RedLED,OUTPUT);

  digitalWrite(GreenLED,LOW);
  digitalWrite(RedLED,HIGH);

  Serial.begin(9600);

}

void loop(){

oldTime = millis();
count=0;
  do{
    voltageIN = analogRead(VoltagePIN);

    //Serial.println(voltageIN);
    if(voltageIN>0)
      count++;
    time = millis();
  }
  while(time-oldTime<1000);
  Serial.print("Count = ");
  Serial.println(count);

  if(count > 2100){
    superCount++;
  } 
  else{
    superCount=0; 
    digitalWrite(GreenLED,LOW);
    digitalWrite(RedLED,HIGH);
  }
  if(superCount==3){
    superCount=0;
    digitalWrite(GreenLED,HIGH);
    digitalWrite(RedLED,LOW);
    Serial.println("OMG A CAR!");
  }
  delay(10);
}

Is the drawing the actual circuit ?

For an oscillating coil detection, I would expect it to look like this:

Or with schmitt-trigger inverters:

If you finished the project and have some time, you might want to try a few different circuits.