Mirko Pavleski
Published © GPL3+

DIY Arduino Based Pulse Induction Metal Detector

The detector can detect a small metal coin at a distance of 15 centimeters.

IntermediateFull instructions provided76,273
DIY Arduino Based Pulse Induction Metal Detector

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Power MOSFET N-Channel
Power MOSFET N-Channel
×1
Operational Amplifier, Op Amp + Comparator + Reference
Operational Amplifier, Op Amp + Comparator + Reference
×1
1N4148 – General Purpose Fast Switching
1N4148 – General Purpose Fast Switching
×2
Capacitor 10 µF
Capacitor 10 µF
×1
Capacitor 1 µF
Capacitor 1 µF
×1
Single Turn Potentiometer- 100k ohms
Single Turn Potentiometer- 100k ohms
×1
Single Turn Potentiometer-47k
×1
12 resistors with different values
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

schematic

Code

code

Arduino
#include <EEPROM.h>
//#include <SoftwareSerial.h>
//int bluetoothTx = 5;
//int bluetoothRx = 6;//blutoth module terminal RX
//SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
#define pulsePine 2
int timer = 200;
const int button1 = 12;
int buttonState1 = 0;

char data;
//EEPROM variables
int addr_duty = 0;
int addr_freq = 1;
int stored_value;
int duty_cycle;
int duty_cycle_temp;
int freq;
int freq_temp;
int duty_def_value = 10;
int freq_def_value = 60;
//Balance variables
int value_count = 0;
int value_count_def = 100;
int balance_value = 0;
int balance_value_temp = 0;
//****
unsigned long startMillis;  
unsigned long currentMillis;
long period = 100000;  //the value is a number of microseconds
//Measuring of level of the battery
float resistencia1 = 101000; //Resistencia de 100K para medir la tencion (Voltios)/Resistance of 100k for test volts
float resistencia2 = 10000; //Resistencia de 10k para medir la tencion (Voltios)/Resistance 10k for test volts
float const arefVolt=4.8f; //pin "4.9v" SET EXACT VALUE HERE
float voutv;
float vinv;
unsigned long startMillisVolts;  
unsigned long currentMillisVolts;
long periodVolts = 2000;  //the value is a number of microseconds
int sensorValue ;

void setup() {
  //analogReference(INTERNAL);
 Serial.begin(115200);
 readFromStorage(addr_duty);
  duty_cycle = stored_value;
  readFromStorage(addr_freq);
   freq = stored_value;
  if(duty_cycle == 0 || duty_cycle == 255){
    writeToStorage(duty_def_value,addr_duty);
    readFromStorage(addr_duty);
  duty_cycle = stored_value;
  }
 
  if(freq == 0 || freq == 255 ){
    writeToStorage(freq_def_value,addr_freq);
     readFromStorage(addr_freq);
   freq = stored_value;
  }
 
 
 
  pinMode(pulsePine, OUTPUT);
 
}


void loop() { 
  currentMillis = micros();
  currentMillisVolts = millis();  
 
   if(Serial.available()>0)
 {
  data =  Serial.read();
  setDutyAndFreq  (data);
 
}

 

  
if (currentMillis - startMillis >= period)
 {
   
  period = 1000000 / freq;
  // Serial.println(period);
 digitalWrite(pulsePine, HIGH);
 duty_cycle_temp = duty_cycle * 10;
 delayMicroseconds(duty_cycle_temp); 
 digitalWrite(pulsePine, LOW);
  //sensorValue = analogRead(A0);
  
for(int i = 0;i < 3; i++){
  sensorValue = analogRead(A0);

}

delayMicroseconds(10);
sensorValue = analogRead(A0);
sensorValue = sensorValue / 5;
 sendData();
 
   
startMillis = currentMillis;
 }
 // Lectura voltios
 if (currentMillisVolts - startMillisVolts >= periodVolts)
 {
lecturaVoltios();
//Serial.println("Lectura voltios");
startMillisVolts = currentMillisVolts;
 }
 
}      



 void writeToStorage(int valor,int addr)
 {
   EEPROM.write(addr, valor);
     
 
 }
 int readFromStorage(int addr)
 {
    stored_value = EEPROM.read(addr);

  return stored_value;
 
 }
 void setDutyAndFreq  (char valor)
 {
   //"n" valor para aumentar duty cycle
   //"m" valor para disminuir duty cycle
   //"j" valor para aumentar la frequencia
   //"k" valor para des,inuir la frequencia
   //"+" valor para aumentar el balance
   //"-" valor para desminuir el balance
   if(valor == 'n')
   {
    // Serial.println("n Recived");
      readFromStorage(addr_duty);
  duty_cycle = stored_value;
  duty_cycle = duty_cycle + 1;
  writeToStorage(duty_cycle,addr_duty);
  
   }
   else if(valor == 'm')
     {
      //  Serial.println("m Recived");
           readFromStorage(addr_duty);
  duty_cycle = stored_value;
  duty_cycle = duty_cycle - 1;
  writeToStorage(duty_cycle,addr_duty);
  
     }
     else if(valor == 'j')
     {
    //    Serial.println("j Recived");
          readFromStorage(addr_freq);
  freq = stored_value;
  freq = freq + 10;
  writeToStorage(freq,addr_freq);
  
     }
     else if(valor == 'k')
     {
     //   Serial.println("k Recived");
                  readFromStorage(addr_freq);
  freq = stored_value;
  freq = freq - 10;
  writeToStorage(freq,addr_freq);

     }
      else if(valor == 'p')
     {
      //  Serial.println("m Recived");
         
  writeToStorage(0,addr_freq);
  writeToStorage(0,addr_duty);
  
     }
    
   
 
 
 }
  //Volt function
void lecturaVoltios(){
  vinv=0.0f;
  voutv=0.0f;
   for (int i=0;i < 100;i++){
  
   voutv = (analogRead(A7) * arefVolt) / 1023;  //Lee el voltaje de entrada
  vinv += voutv / (resistencia2 / (resistencia1 + resistencia2));  //Fórmula del divisor resistivo para el voltaje final
  if(vinv < 0.9){
  vinv=0.0f;
  }
  


}
vinv = vinv/100;


}
void sendData()

  {
     /* Serial.print("<");
 Serial.print(sensorValue);
  Serial.print("/");
   Serial.print(freq);
    Serial.print("/");
     Serial.print( duty_cycle);
       Serial.print("/");
     Serial.print( vinv);
 Serial.print(">");
  Serial.println();*/
  String data = "<";
  data +=sensorValue;
  data +="/";
  data +=freq;
  data +="/";
  data +=duty_cycle;
  data +="/";
  data +=vinv;
  data +=">";
 /* bluetooth.print("<");
 bluetooth.print(sensorValue);
  bluetooth.print("/");
   bluetooth.print(freq);
    bluetooth.print("/");
    bluetooth.print( duty_cycle);
       bluetooth.print("/");
     bluetooth.print( vinv);
 bluetooth.print(">");*/
  Serial.println(data);
    }

Credits

Mirko Pavleski

Mirko Pavleski

150 projects • 1287 followers

Comments