OpenVINOTM,给你看得见的未来!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 采用arduinoNano制作的一款简洁型金属探测器

共5条 1/1 1 跳转至

采用arduinoNano制作的一款简洁型金属探测器

工程师
2020-11-26 21:11:24    评分

金属探测器? 大家估计会喜欢吧?! 

如下是电路图和源码,大家可以按此制作DIY


image.png

BOM清单:

R1 = 330 Ω, resistor

R2 = 1 KΩ, resistor

C1 = 10nF, ceramic capacitor

D1 = 1N4148, diode

BUZ1 = Buzzer

LED1 = 5mm any color LED

Arduino UNO Board or equivalent


成品图:



#define vinPin 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(vinPin, 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(vinPin,OUTPUT);

    digitalWrite(vinPin,LOW);

    delayMicroseconds(20);

    pinMode(vinPin,INPUT);

    applyPulses();

    

    //read the charge of capacitor

    int val = analogRead(vinPin); //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);

    }

}





关键词: arduino     探测器     金属探测器    

工程师
2020-11-26 21:19:29    评分
2楼

电路,很简洁嘛!


助工
2020-11-26 21:22:58    评分
3楼

不知道探测距离有多远?


工程师
2020-11-26 21:26:26    评分
4楼

请问电感线圈 L1 如何制作或设计?


工程师
2020-11-26 22:03:22    评分
5楼

确实写的不错的


共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]