Mirko Pavleski
Published © GPL3+

DIY Pin Pointer Metal Detector

Simple metal detector capable of detecting a small coin at a distance of 4-5 cm.

IntermediateFull instructions provided13,277
DIY Pin Pointer Metal Detector

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
LED (generic)
LED (generic)
×3
Slide Switch
Slide Switch
×1
Pushbutton Switch, Push-Pull
Pushbutton Switch, Push-Pull
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Few resistors and capacitors
×1
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Code

Code

C/C++
int _gtv1;
int _gtv2;
bool _gtv4;
int _swi1;
bool _trgrt1 = 0;
bool _trgrt1I = 0;
bool _gen3I = 0;
bool _gen3O = 0;
unsigned long _gen3P = 0UL;
bool _trgt1 = 0;
bool _trgt1I = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _trgrt4 = 0;
bool _trgrt4I = 0;
bool _tim1I = 0;
bool _tim1O = 0;
unsigned long _tim1P = 0UL;
bool _tim3I = 0;
bool _tim3O = 0;
unsigned long _tim3P = 0UL;
bool _trgrt2 = 0;
bool _trgrt2I = 0;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _tim2I = 0;
bool _tim2O = 0;
unsigned long _tim2P = 0UL;
bool _bounseInputD6S = 0;
bool _bounseInputD6O = 0;
unsigned long _bounseInputD6P = 0UL;
bool _trgrt3 = 0;
bool _trgrt3I = 0;
bool _tim4I = 0;
bool _tim4O = 0;
unsigned long _tim4P = 0UL;

void setup()
{
pinMode(6, INPUT_PULLUP); 
pinMode(7, OUTPUT); 
digitalWrite(7, 0); 
pinMode(8, OUTPUT); 
digitalWrite(8, 0); 


_bounseInputD6O =  digitalRead(6);

}
void loop()
{


bool  _bounceInputTmpD6 =  (digitalRead (6));

if (_bounseInputD6S) 
    {
     if (millis() >= (_bounseInputD6P + 40)) 
         {_bounseInputD6O= _bounceInputTmpD6; _bounseInputD6S=0;}
     }
else
    {
     if (_bounceInputTmpD6 != _bounseInputD6O )
         {_bounseInputD6S=1; _bounseInputD6P = millis();} 
      } 




//Плата:1
if (!(_bounseInputD6O))
{ if (_tim3I) { if (_isTimer(_tim3P, 3000)) {_tim3O = 1;}} else {_tim3I =1; _tim3P = millis();}} else {_tim3O = 0; _tim3I = 0;}
if (_tim3O) { if (_trgrt4I) { _trgrt4 = 0;} else {_trgrt4 = 1; _trgrt4I = 1;} } else {_trgrt4 = 0; _trgrt4I = 0;}; 
 bool  _tmp1 = _trgrt4;
if (_tmp1)  { if (! _trgt1I) _trgt1 = ! _trgt1; } 
_trgt1I = _tmp1; 
if(_trgt1)
{_swi1=200;}
else
{_swi1=0;}
analogWrite(3, _swi1);
if (!(0)) { if (! _gen1I) { _gen1I = 1; _gen1O = 1; _gen1P = millis(); } } else { _gen1I = 0 ; _gen1O= 0;}
 if (_gen1I) {  if ( _isTimer ( _gen1P , 10 )) { _gen1P = millis(); _gen1O = ! _gen1O;}}
if (_gen1O) {
_gtv1 =  (analogRead (0));
}
if ((_gtv1) < (_gtv2))
{ if (_tim1I) { if (_isTimer(_tim1P, 100)) {_tim1O = 1;}} else {_tim1I =1; _tim1P = millis();}} else {_tim1O = 0; _tim1I = 0;}
if (_tim1O) { if (! _gen2I) { _gen2I = 1; _gen2O = 1; _gen2P = millis(); } } else { _gen2I = 0 ; _gen2O= 0;}
 if (_gen2I) {  if ( _isTimer ( _gen2P , (map((_gtv1), (0), ((_gtv2)), (0), (100))) )) { _gen2P = millis(); _gen2O = ! _gen2O;}}
if (!(0)) { if (_trgrt3I) { _trgrt3 = 0;} else {_trgrt3 = 1; _trgrt3I = 1;} } else {_trgrt3 = 0; _trgrt3I = 0;}; 
 if (( (_trgrt3) || (!(_bounseInputD6O)) || (_gtv4) )) { if (_trgrt2I) { _trgrt2 = 0;} else {_trgrt2 = 1; _trgrt2I = 1;} } else {_trgrt2 = 0; _trgrt2I = 0;}; 
 if(_trgrt2) {_tim2O = 1; _tim2I = 1;} else { if(_tim2I) {_tim2I = 0; _tim2P = millis();} else { if (_tim2O) {if ( _isTimer(_tim2P, 300000)) _tim2O = 0;}}}
if (!(_tim2O)) {if (! _gen3I) { _gen3I = 1; _gen3O = 1; _gen3P =  millis(); } } else { _gen3I = 0 ;  _gen3O= 0;  } if (_gen3I ) { if (_gen3O) { if ( _isTimer( _gen3P , 500 )) { _gen3P = millis(); _gen3O = 0; } } else  { if ( _isTimer( _gen3P , 100 )) {  _gen3P = millis(); _gen3O = 1;  } } }
if(( (( (_gen2O) || ((_gtv1) < (4)) )) || (_gen3O) )) {_tim4O = 1; _tim4I = 1;} else { if(_tim4I) {_tim4I = 0; _tim4P = millis();} else { if (_tim4O) {if ( _isTimer(_tim4P, 50)) _tim4O = 0;}}}
digitalWrite(7, _tim4O);
digitalWrite(8, ( (( (_gen2O) || ((_gtv1) < (4)) )) || (_gen3O) ));
_gtv4 = ( (_gen2O) || ((_gtv1) < (4)) );
if (!(0)) { if (_trgrt1I) { _trgrt1 = 0;} else {_trgrt1 = 1; _trgrt1I = 1;} } else {_trgrt1 = 0; _trgrt1I = 0;}; 
 if (( (_trgrt1) || (!(_bounseInputD6O)) )) {
_gtv2 = _gtv1;
}


}

bool _isTimer(unsigned long startTime, unsigned long period )
  {
  unsigned long currentTime;
currentTime = millis();
if (currentTime>= startTime) {return (currentTime>=(startTime + period));} else {return (currentTime >=(4294967295-startTime+period));}
  }

Credits

Mirko Pavleski

Mirko Pavleski

150 projects • 1283 followers

Comments