On Arduino pins A2,A4 and A5 connect leds for indicating,on D12 buzzer and D5 goes to oscilator.
here is code for Arduino:
--------------------------------------------------------------------------------
#include <FreqCount.h>
//the baseline frequency of the main search coil
unsigned long baseLine = 10;
//Pins red, green and blue LEDs are attached to.
const int bluePin = A2;
const int greenPin = A4;
const int redPin = A5;
const int buzzerPin = 12;
void setup() {
//set our LED pins as outputs
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
pinMode(buzzerPin,OUTPUT);
//Flash a sequence to test the LEDs and show we are starting up
digitalWrite(redPin,HIGH);
delay(200);
silence();
digitalWrite(greenPin,HIGH);
delay(200);
silence();
digitalWrite(bluePin,HIGH);
delay(200);
silence();
//Read out baseline frequency count, 100ms intervals
FreqCount.begin(100);
while(!FreqCount.available())
{
delay(10);
}
baseLine = FreqCount.read();
if(baseLine > 10000)
{
//Green, we started up OK
digitalWrite(greenPin,HIGH);
}
else
{
//Red, something went wrong, we didn't get a sensible count
digitalWrite(redPin,HIGH);
}
delay(1000);
silence();
}
void loop() {
//no sample ready yet, exit.
if (!FreqCount.available()) {
return;
}
//Read how many pulses in 100 milliseconds
unsigned long count = FreqCount.read();
long difference = baseLine - count;
difference = abs(difference);
//Difference is large, turn on the RED led
if(difference > 5)
{
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);
digitalWrite(redPin,HIGH);
digitalWrite(buzzerPin,HIGH);
}
else if(difference > 2) //medium difference, green
{
digitalWrite(greenPin,HIGH);
digitalWrite(bluePin,LOW);
digitalWrite(redPin,LOW);
digitalWrite(buzzerPin,HIGH);
}
else if(difference > 1) //small difference, blue.
{
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,HIGH);
digitalWrite(redPin,LOW);
digitalWrite(buzzerPin,HIGH);
}
else
{
silence(); //no difference, turn off all LEDs
digitalWrite(buzzerPin,LOW);
}
//Auto-adjust our baseline
if(count > baseLine)
{
baseLine +=1;
}
else if (count < baseLine)
{
baseLine -= 1;
}
}
//Turn off all output pins
void silence()
{
digitalWrite(redPin,LOW);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);
}
Mine metal detector finished
Full youtube video How to make:
Its not mine project the author is this check out:https://siliconjunction.wordpress.com/2019/02/14/a-simple-arduino-metal-detector/
No comments:
Post a Comment