ข้ามไปที่เนื้อหาหลัก

ส่งงานครั้งที่ 12

Arduino Metal Detector

อุปกรณ์

  1. Arduino (any)
  2. Coil
  3. 10nF capacitor
  4. Buzzer
  5. The 1k resistor
  6. 330-ohm resistor
  7. LED
  8. 1N4148 diode
  9. Breadboard or PCB
  10. Connecting jumper wire
  11. 9v Battery
Diagram


Code


#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 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);
    }
}

Credit By : https://circuitdigest.com/microcontroller-projects/arduino-metal-detector-circuit-code

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ส่งงานครั้งที่ 17

Air Pollution Monitoring อุปกรณ์ MQ135 Gas sensor Arduino Uno Wi-Fi module ESP8266 16X2 LCD Breadboard 10K potentiometer 1K ohm resistors 220 ohm resistor Buzzer Diagram Code #include "MQ135.h" #include <SoftwareSerial.h> #define DEBUG true SoftwareSerial esp8266(9,10); // กำหนดขา 9 ของ Arduino เป็น RX pin และ ขา 10 ของ Arduino เป็น the TX pin const int sensorPin= 0; int air_quality; #include <LiquidCrystal.h> LiquidCrystal lcd(12,11, 5, 4, 3, 2); void setup() { pinMode(8, OUTPUT); lcd.begin(16,2); lcd.setCursor (0,0); lcd.print ("circuitdigest "); lcd.setCursor (0,1); lcd.print ("Sensor Warming "); delay(1000); Serial.begin(115200); esp8266.begin(115200);   sendData("AT+RST\r\n",2000,DEBUG); // reset module   sendData("AT+CWMODE=2\r\n",1000,DEBUG); // กำหนดค่า  access point   sendData("AT+CIFSR\r\n",1000,DEBUG); // รับ ip address   sendData("AT+CIPMUair_quali

ส่งงานครั้งที่ 16

Smoke Detector Using MQ2 อุปกรณ์ Arduino UNO Smoke Detector Arduino Shield (Self Designed) Power Supply Smoke Sensor (MQ2) Resistors (10K and 1K) Buzzer 16x2 LCD 10k POT LED LM358 Burg strips Diagram Code #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define buzzer 9 #define sensor A0   #define load_Res 10   #define air_factor 9.83                                                   float SmokeCurve[3] ={2.3,0.53,-0.44};    // (x, y, slope) x,y พิกัดของจุดหนึ่งและความลาดชันระหว่างสองจุด                                                                                       float Res=0;                 void setup() {   lcd.begin(16,2);   lcd.print("Calibrating.....");                 Res = SensorCalibration();                                                                                           lcd.print("Calibration done.");   lcd.setCursor(0,1);   lcd.print("Res=");   lcd.print(

ส่งงานครั้งที่ 18

12 V Battery Charger อุปกรณ์ Transformer 12V 1Amp IC LM317 (2) Diode Bridge W005 Connector Terminal Block (2) Capacitor 1000uF, 1uF Capacitor 0.1uF (5) Variable resistor 100R Resistor 1k (5) Resistor 10k Diode- Nn007  (3) LM358 – Opamp 0.05R - Shunt Resistor/wire LCD-16*2 (optional) Arduino Nano (optional) Diagram Code #include <LiquidCrystal.h>// ประกาศเมื่อใช้LCD LiquidCrystal lcd(11, 12, 10, 9, 8, 7); float voltage,current;  void setup() {   Serial.begin(9600);   //ตั้งค่าLCD   lcd.begin(16, 2);   // Print a message to the LCD.   lcd.setCursor(0, 0);   lcd.print("12V Charger");   lcd.setCursor(0, 1);   lcd.print("-Circuit Digest");   delay(2000);   lcd.clear();   lcd.setCursor(0, 0);   lcd.print("Voltage = ");   lcd.setCursor(0, 1);   lcd.print("Current = "); } void loop() {   voltage = (analogRead(A0)) * 0.0140625;   current = (analogRead(A1)) * 0.35;           lcd.setCursor(1