#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h> // Hem Bluetooth hem ESP için kullanılacak
// DS18B20 veri pini
#define ONE_WIRE_BUS 8
// Bluetooth yazılım seri pinleri
#define BT_RX 2
#define BT_TX 3
// ESP8266 WiFi modül yazılım seri pinleri
#define WIFI_RX 9
#define WIFI_TX 8
// LCD tanımı (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 10, 7, 6, 5, 4);
// Yazılım seri portları
SoftwareSerial bluetooth(BT_RX, BT_TX); // Bluetooth
SoftwareSerial esp8266(WIFI_RX, WIFI_TX); // ESP8266 WiFi
// OneWire ve DallasTemperature
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress sensor1, sensor2;
// Zamanlama
unsigned long previousMillis = 0;
const unsigned long interval = 600000; // 10 dakika
// WiFi ayarları
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* host = "yourserver.com"; // örn: 192.168.1.100 veya alan adınız
void setup() {
lcd.begin(16, 2);
lcd.setCursor(2, 0);
lcd.print("Hos Geldiniz");
delay(2000);
lcd.clear();
sensors.begin();
bluetooth.begin(9600);
esp8266.begin(9600);
if (!sensors.getAddress(sensor1, 0)) {
lcd.print("Sensör 1 yok!");
}
if (!sensors.getAddress(sensor2, 1)) {
lcd.setCursor(0, 1);
lcd.print("Sensör 2 yok!");
}
sensors.setResolution(sensor1, 10);
sensors.setResolution(sensor2, 10);
// ESP8266'ya AT komutları ile bağlan
sendCommand("AT+RST", 2000);
sendCommand("AT+CWMODE=1", 1000);
sendCommand("AT+CWJAP=\"" + String(ssid) + "\",\"" + String(password) + "\"", 5000);
}
void loop() {
sensors.requestTemperatures();
float temp1 = sensors.getTempC(sensor1);
float temp2 = sensors.getTempC(sensor2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("S1: ");
lcd.print(temp1);
lcd.write(223); // ° simgesi
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("S2: ");
lcd.print(temp2);
lcd.write(223);
lcd.print("C");
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// --- Bluetooth mesajı ---
bluetooth.println("10 Dakika Sicaklik Raporu:");
bluetooth.print("Sensor 1: ");
bluetooth.print(temp1);
bluetooth.println(" C");
bluetooth.print("Sensor 2: ");
bluetooth.print(temp2);
bluetooth.println(" C");
bluetooth.println("--------------------");
// --- WiFi mesajı gönder ---
String url = "/temperature_logger.php?temp1=" + String(temp1) + "&temp2=" + String(temp2);
sendDataToWiFi(host, 80, url);
}
delay(1000);
}
// ESP8266'ya AT komutu gönder
void sendCommand(String command, const int timeout) {
esp8266.println(command);
long int time = millis();
while ((time + timeout) > millis()) {
while (esp8266.available()) {
char c = esp8266.read();
// Serial.print(c); // Debug için açabilirsin
}
}
}
// ESP8266 ile HTTP GET isteği gönder
void sendDataToWiFi(String host, int port, String url) {
sendCommand("AT+CIPSTART=\"TCP\",\"" + host + "\"," + String(port), 2000);
delay(100);
String getRequest = "GET " + url + " HTTP/1.1\r\nHost: " + host + "\r\nConnection: close\r\n\r\n";
sendCommand("AT+CIPSEND=" + String(getRequest.length()), 1000);
esp8266.print(getRequest);
delay(2000);
}