in

Metal detector with Arduino

Arduino based metal detector

Welcome to the quanta project, so this is our most interesting project. which can be part of many projects. and it is a very useful project which helps you to find the metal from the garden and from anywhere else. like if in the garden there are some metal parts. these metal parts can hurt your legs so, if you have this awesome metal detector you can find all the metal from the garden and get rid of this problem. also, you can use this metal detector to find the metallic waste from the waste materials. we are giving you the step by step guide to making it possible.  so, in this project, you will learn a lot about the basic electronic as well as the embedded system like Arduino also. let’s check out its working also.

How does it work?

when you take it to heart to the metal then it will detect and making a sound from the buzzer. it works on the principle of the proximity sensor. which detects the metal near it, so there is an RC circuit that activates the system and we use a coil as an inductor. we also use two 3 pins from the Arduino two for the input of the sensor which takes the input from the electronic circuit and 1 pin use as output which help to activate the buzzer.

Components Require:-

  • Arduino
  • 1N4148 Diode
  • 330 ohm Resistor
  • 220 ohm resistor
  • 10 nf capacitor

With the most minimal affectability setting, the metal locator can get huge things like soft drink jars, PDAs, and iron devices inside a couple of inches from the curl. On the most elevated affectability setting, littler things like steel rings, screws, and coins inside a similar closeness can likewise be distinguished. See the video at the highest point of the article for an exhibition!To broaden the scope of the locator, we can build an attractive field territory made by the inductor. This can be accomplished by expanding the present move through the inductor (by expanding voltage contribution to the oscillator, permitting a more noteworthy addition in the enhancer), or by expanding the quantity of wire encloses by the inductor curl.With an Arduino-based metal locator, we can do other intriguing things that are impossible with conventional BFO metal indicators. Stay tuned for future tasks on how we can exploit this metal distinguishing component for different purposes!

Circuit Diagram for metal detector:-

Code for metal detector:-

#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 13×8=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);

}

}

Upload the given code into the Arduino

What do you think?

0 points
Upvote Downvote

Written by shahid

Autonomous plant watering Rover

How to make automatic Street light