(DEFİNECİLERE ÖZEL TASARIM)
PULSE DEDEKTÖR-ALTIN DEDEKTÖRÜ
PROGRAMIN İÇİNDE BAĞLANTI ŞEKİLLERİ MEVCUT. FAZLASIYLA DETAYLI.

KODU AŞAĞIDA PAYLAŞIYORUM KUR ÇALIŞTIR
/*
* ============================================================================
* PROFESYONEL METAL DEDEKTORU SISTEMI v2.6 (EKRAN DÜZELTİLMİŞ)
* ============================================================================
*/
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
// — PIN TANIMLARI —
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
SoftwareSerial wifi(A2, A3);
SoftwareSerial gpsSerial(11, 12);
const int COIL_PIN = 3;
const int CS_SD = 13;
const int BACKLIGHT_PIN = 10;
const int SIGNAL_IN = A1;
const int FINE_1 = A4;
const int FINE_2 = A5;
const int BUZZER_PIN = 2;
const int BATT_PIN = A6;
const int LED_PIN = 12;
// — GLOBAL DEGISKENLER —
long hassasiyet = 5000;
int taramaHizi = 2;
int toprakAyar = 0;
int aramaModuSecim = 0;
int sesSeviyi = 5;
bool sesAktif = true;
float batMin = 3.0;
float batMax = 12.6;
unsigned long dusukGerilimBaslangic = 0;
bool dusukGerilimAlarmAktif = false;
const unsigned long DUSUK_GERILIM_SURESI = 3000;
int menuLvl = 0;
int menuIdx = 0;
int vIdx = 0;
bool wifiOn = false;
bool sdKartAktif = false;
bool gpsAktif = false;
long sinyal = 0;
int metalTipi = 0;
int bulunanMetalSayisi = 0;
unsigned long sonButonZamani = 0;
const int BUTON_GECIKME = 200;
unsigned long calismaBaslangic = 0;
// EEPROM Adresleri
const int ADDR_HASSASIYET = 0;
const int ADDR_TARAMA_HIZI = 4;
const int ADDR_TOPRAK_AYAR = 5;
const int ADDR_ARAMA_MODU = 7;
const int ADDR_BAT_MIN = 8;
const int ADDR_BAT_MAX = 12;
const int ADDR_SES_SEVIYE = 16;
// Menü Dizileri
const char* menuElemanlari[] = {
“TOPRAK AYARI”, “ARAMA MODU”, “HASSASIYET”, “TARAMA HIZI”,
“SES AYARI”, “BAT AYARI”, “VERI MERKEZI”, “ISTATISTIKLER”,
“FABRIKA AYARLARI”, “CIKIS”
};
const char* veriMerkeziMenusu[] = {
“1-WIFI AC/KAP”, “2-IP/PORT”, “3-MAC ADRES”, “4-CIHAZLAR”,
“5-PROT DURUM”, “6-TX BASLAT”, “7-SD OKU”, “8-SD SIL”,
“9-GPS KAYDET”, “10-AYAR YUKLE”, “11-AYAR KAYDET”, “12-GERI”
};
// — BUTON OKUMA —
int getBtn() {
if (millis() – sonButonZamani < BUTON_GECIKME) return -1;
int analogDeger = analogRead(A0);
int buton = -1;
if (analogDeger < 50) buton = 0; // OK
else if (analogDeger < 250) buton = 1; // Yukari
else if (analogDeger < 450) buton = 2; // Asagi
else if (analogDeger < 650) buton = 3; // Geri
else if (analogDeger < 850) buton = 4; // Menu
if (buton != -1) {
sonButonZamani = millis();
if (sesAktif) tone(BUZZER_PIN, 1200, 25);
}
return buton;
}
// — BATARYA OKUMA —
float okuGerilim() {
int adc = analogRead(BATT_PIN);
float volt = (adc / 1023.0) * 5.0 * 5.7;
return (volt < 0.1) ? 0.0 : volt;
}
int bataryaYuzdesi() {
float volt = okuGerilim();
if (volt <= batMin) return 0;
if (volt >= batMax) return 100;
return (int)((volt – batMin) / (batMax – batMin) * 100);
}
// — EEPROM —
void eepromYazLong(int addr, long deger) { EEPROM.put(addr, deger); }
long eepromOkuLong(int addr) { long d; EEPROM.get(addr, d); return d; }
void ayarlariKaydet() {
eepromYazLong(ADDR_HASSASIYET, hassasiyet);
EEPROM.write(ADDR_TARAMA_HIZI, taramaHizi);
EEPROM.put(ADDR_TOPRAK_AYAR, toprakAyar);
EEPROM.write(ADDR_ARAMA_MODU, aramaModuSecim);
EEPROM.put(ADDR_BAT_MIN, batMin);
EEPROM.put(ADDR_BAT_MAX, batMax);
EEPROM.write(ADDR_SES_SEVIYE, sesSeviyi);
lcd.clear(); lcd.print(“AYARLAR KAYIT!”); delay(1000);
}
void ayarlariYukle() {
hassasiyet = eepromOkuLong(ADDR_HASSASIYET);
if (hassasiyet < 1000 || hassasiyet > 10000) hassasiyet = 5000;
taramaHizi = EEPROM.read(ADDR_TARAMA_HIZI);
EEPROM.get(ADDR_TOPRAK_AYAR, toprakAyar);
aramaModuSecim = EEPROM.read(ADDR_ARAMA_MODU);
EEPROM.get(ADDR_BAT_MIN, batMin);
EEPROM.get(ADDR_BAT_MAX, batMax);
sesSeviyi = EEPROM.read(ADDR_SES_SEVIYE);
lcd.clear(); lcd.print(“AYARLAR YUKLENDI”); delay(1000);
}
void fabrikaAyarlari() {
hassasiyet = 5000; taramaHizi = 2; toprakAyar = 0;
aramaModuSecim = 0; batMin = 3.0; batMax = 12.6; sesSeviyi = 5;
ayarlariKaydet();
lcd.clear(); lcd.print(“FABRIKA AYARLARI”); lcd.setCursor(0,1); lcd.print(“YUKLENDI”); delay(1500);
}
// — WIFI —
void wifiServerBaslat() {
lcd.clear(); lcd.print(“WIFI ACILIYOR…”);
wifi.println(“AT+RST”); delay(2000);
wifi.println(“AT+CWMODE=2”); delay(500);
wifi.println(“AT+CIPMUX=1”); delay(300);
wifi.println(“AT+CIPSERVER=1,7575”); delay(300);
wifiOn = true;
lcd.clear(); lcd.print(“10.176.1.1:7575”); delay(2000);
}
// — SİNYAL OKUMA —
long sinyalOku() {
long toplam = 0;
int ornekSayisi = pow(2, taramaHizi);
for (int i = 0; i < ornekSayisi; i++) {
digitalWrite(COIL_PIN, HIGH); delayMicroseconds(250);
digitalWrite(COIL_PIN, LOW); delayMicroseconds(35);
toplam += analogRead(SIGNAL_IN);
}
long ort = toplam / ornekSayisi;
return abs(ort – (toprakAyar + (analogRead(FINE_1) + analogRead(FINE_2)) / 4));
}
int metalTipiBelirle(long s) {
if (s < (10000 – hassasiyet) / 10) return 0;
int vdi = map(s, 0, 1023, 0, 99);
if (vdi < 35) return 1;
return 2;
}
// — ARAMA EKRANI —
void aramaEkraniGoster() {
float volt = okuGerilim();
lcd.setCursor(0, 0); lcd.print(“S:”); lcd.print(sinyal); lcd.print(” “);
lcd.setCursor(8, 0); lcd.print(volt, 1); lcd.print(“V %”); lcd.print(bataryaYuzdesi());
lcd.setCursor(0, 1);
if (metalTipi > 0) {
lcd.print(metalTipi == 1 ? “DEMIR ” : “ALTIN “);
lcd.print(155.0 / (log10(sinyal + 1) * 1.7), 0); lcd.print(“cm “);
if (sesAktif) tone(BUZZER_PIN, metalTipi == 1 ? 600 : 2000, 50);
bulunanMetalSayisi++;
} else lcd.print(“Tariyor… “);
}
// — TOPRAK AYARI —
void toprakAyarla() {
lcd.clear(); lcd.print(“TOPRAK AYARI…”);
long toplam = 0;
for (int i = 0; i < 50; i++) { toplam += analogRead(SIGNAL_IN); delay(10); }
toprakAyar = toplam / 50;
lcd.setCursor(0,1); lcd.print(“TAMAMLANDI!”);
delay(1000); lcd.clear();
}
// — ARAMA MODU —
void aramaModuDegistir() {
lcd.clear(); lcd.print(“ARAMA MODU:”);
lcd.setCursor(0,1);
const char* modlar[] = {“Tum Metal”, “Ayirimli”, “Altin Modu”};
aramaModuSecim = (aramaModuSecim + 1) % 3;
lcd.print(modlar[aramaModuSecim]);
delay(1000); lcd.clear();
}
// — HASSASIYET —
void hassasiyetAyarla() {
lcd.clear(); lcd.print(“HASSASIYET:”);
lcd.setCursor(0,1); lcd.print(hassasiyet);
hassasiyet += 500;
if (hassasiyet > 10000) hassasiyet = 1000;
delay(1000); lcd.clear();
}
// — TARAMA HIZI —
void taramaHiziAyarla() {
lcd.clear(); lcd.print(“TARAMA HIZI:”);
lcd.setCursor(0,1); lcd.print(taramaHizi);
taramaHizi++;
if (taramaHizi > 5) taramaHizi = 1;
delay(1000); lcd.clear();
}
// — SES AYARI —
void sesAyarla() {
lcd.clear(); lcd.print(“SES SEVIYE:”);
lcd.setCursor(0,1); lcd.print(sesSeviyi);
sesSeviyi++;
if (sesSeviyi > 10) sesSeviyi = 1;
delay(1000); lcd.clear();
}
// — BAT AYARI —
void batAyarla() {
lcd.clear(); lcd.print(“BAT MIN/MAX”);
lcd.setCursor(0,1);
lcd.print(batMin,1); lcd.print(“/”); lcd.print(batMax,1);
batMin = 3.0; batMax = 12.6;
delay(1000); lcd.clear();
}
// — ISTATISTIKLER —
void istatistikEkrani() {
unsigned long calismaSuresi = (millis() – calismaBaslangic) / 1000;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“METAL: “); lcd.print(bulunanMetalSayisi);
lcd.setCursor(0, 1);
lcd.print(“SURE: “); lcd.print(calismaSuresi); lcd.print(“sn”);
delay(2000);
lcd.clear();
menuLvl = 1;
}
// — SETUP —
void setup() {
pinMode(COIL_PIN, OUTPUT); pinMode(BUZZER_PIN, OUTPUT);
pinMode(BACKLIGHT_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
digitalWrite(BACKLIGHT_PIN, HIGH);
lcd.begin(16, 2);
lcd.setCursor(0,0); lcd.print(“DIKICI2006”);
lcd.setCursor(0,1); lcd.print(“DEDEKTOR”);
delay(2000);
if (EEPROM.read(100) != 0xAA) {
fabrikaAyarlari(); EEPROM.write(100, 0xAA);
} else ayarlariYukle();
wifi.begin(9600);
if (SD.begin(CS_SD)) sdKartAktif = true;
calismaBaslangic = millis();
delay(1000);
lcd.clear();
}
// — LOOP —
void loop() {
int buton = getBtn();
// — ARAMA EKRANI —
if (menuLvl == 0) {
sinyal = sinyalOku();
metalTipi = metalTipiBelirle(sinyal);
aramaEkraniGoster();
if (buton == 0) { menuLvl = 1; lcd.clear(); }
}
// — ANA MENU —
else if (menuLvl == 1) {
static int oncekiMenuIdx = -1;
if (menuIdx != oncekiMenuIdx) {
lcd.clear();
lcd.setCursor(0,0); lcd.print(“ANA MENU”);
lcd.setCursor(0,1); lcd.print(“> “); lcd.print(menuElemanlari[menuIdx]);
oncekiMenuIdx = menuIdx;
}
if (buton == 1) { menuIdx = (menuIdx > 0) ? menuIdx – 1 : 9; }
if (buton == 2) { menuIdx = (menuIdx < 9) ? menuIdx + 1 : 0; }
if (buton == 3) { menuLvl = 0; lcd.clear(); oncekiMenuIdx = -1; }
if (buton == 0) {
lcd.clear();
switch (menuIdx) {
case 0: toprakAyarla(); break;
case 1: aramaModuDegistir(); break;
case 2: hassasiyetAyarla(); break;
case 3: taramaHiziAyarla(); break;
case 4: sesAyarla(); break;
case 5: batAyarla(); break;
case 6: menuLvl = 3; oncekiMenuIdx = -1; break;
case 7: istatistikEkrani(); break;
case 8: fabrikaAyarlari(); break;
case 9: menuLvl = 0; oncekiMenuIdx = -1; break;
}
}
}
// — VERI MERKEZI —
else if (menuLvl == 3) {
static int oncekiVIdx = -1;
if (vIdx != oncekiVIdx) {
lcd.clear();
lcd.setCursor(0,0); lcd.print(“VERI MERKEZI”);
lcd.setCursor(0,1); lcd.print(veriMerkeziMenusu[vIdx]);
oncekiVIdx = vIdx;
}
if (buton == 1) { vIdx = (vIdx > 0) ? vIdx – 1 : 11; }
if (buton == 2) { vIdx = (vIdx < 11) ? vIdx + 1 : 0; }
if (buton == 3) { menuLvl = 1; oncekiVIdx = -1; lcd.clear(); }
if (buton == 0) {
lcd.clear();
switch (vIdx) {
case 0: if (!wifiOn) wifiServerBaslat(); else { wifi.println(“AT+RST”); wifiOn = false; lcd.print(“WIFI KAPATILDI”); delay(1000); } break;
case 1: lcd.print(“IP:10.176.1.1”); lcd.setCursor(0,1); lcd.print(“PORT:7575”); delay(2000); break;
case 2: lcd.print(“MAC:68:8F:74:F2”); lcd.setCursor(0,1); lcd.print(“EA:56”); delay(2000); break;
case 3: lcd.print(“BAGLI CIHAZ:0”); delay(1500); break;
case 4: lcd.print(“PROTOKOL: AKTIF”); delay(1500); break;
case 5: lcd.print(“TX BASLADI”); delay(1500); break;
case 6: lcd.print(“SD OKUNUYOR…”); delay(1500); break;
case 7: lcd.print(“SD SILINDI”); delay(1500); break;
case 8: lcd.print(“GPS KAYDEDILDI”); delay(1500); break;
case 9: ayarlariYukle(); break;
case 10: ayarlariKaydet(); break;
case 11: menuLvl = 1; oncekiVIdx = -1; break;
}
lcd.clear();
}
}
delay(50);
}






