Created
January 18, 2023 07:35
-
-
Save ikizoglu/10b409551237a6d79efd9c102676fc34 to your computer and use it in GitHub Desktop.
NodeMCU Buzzer Kullanımı
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NodeMCU Web Sunucu Üzerinden Buzzer Kontrolü | |
// ******************************************** | |
#include <ESP8266WiFi.h> | |
const char* ssid = " "; // Bağlantı kurulacak Wifi Ağ Adı | |
const char* password = " "; // Bağlantı kurulacak Wifi Parola | |
int buzzer = D1; // Buzzer'ın bağlı olduğu pini buzzer olarak tanımladık | |
int value = LOW; | |
WiFiServer server(80); // 80 portuyla serveri oluşturduk. | |
void setup() { | |
Serial.begin(115200); // Seri port frekansını 115200 olarak belirliyoruz | |
delay(100); | |
pinMode(buzzer, OUTPUT); // Buzzer'ı çıkış olarak tanımladık | |
digitalWrite(buzzer, LOW); // Buzzer'ı başlangıçta kapattık | |
Serial.println(); | |
Serial.println(); | |
Serial.print("Baglaniliyor.. "); | |
Serial.println(ssid); //Wifi bağlantısı başlıyor | |
WiFi.begin(ssid, password); //Ağa bağlantı gerçekleştiriliyor | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi baglandi!"); | |
server.begin(); //Server baslatılıyor | |
Serial.println("Server başladı"); | |
// Bağlantı sağlandıktan sonra seri monitorde IP adresi görüntüleniyor | |
Serial.print("Baglanti Linki: "); | |
Serial.print("http://"); | |
Serial.print(WiFi.localIP()); | |
Serial.println("/"); | |
} | |
void loop() { | |
// Bağlantının sunucuya bağlı olup olmadığını kontrol ediyoruz | |
WiFiClient client = server.available(); | |
if (!client) { | |
return; | |
} | |
Serial.println("Yeni Baglanti"); //Kullanıcının veri göndermesini bekliyoruz | |
while(!client.available()){ | |
delay(1); | |
} | |
String request = client.readStringUntil('\r'); // Gelen istekleri okuyoruz | |
Serial.println(request); | |
client.flush(); | |
// Buzzer için adres satırı komutları | |
// ********************************* | |
if (request.indexOf("/BUZZER-ACIK") != -1) { | |
digitalWrite(buzzer, HIGH); | |
value = HIGH; | |
} | |
if (request.indexOf("/BUZZER-KAPALI") != -1) { | |
digitalWrite(buzzer, LOW); | |
value = LOW; | |
} | |
//HTML kodlarıyla verileri arayüzüne yazıdırıyoruz. | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println(""); | |
client.println("<!DOCTYPE HTML>"); | |
client.println("<html>"); | |
client.print("<h3>Buzzer Kontrolu</h3>"); | |
client.print("Buzzer Durumu: "); | |
if(value == HIGH) { | |
client.print("ACIK"); | |
} else { | |
client.print("KAPALI"); | |
} | |
client.println("<a href=\"/BUZZER-ACIK\"\"> <button>Buzzer Ac</button></a>"); | |
client.println("<a href=\"/BUZZER-KAPALI\"\"> <button>Buzzer Kapat</button></a>"); | |
client.println("</html>"); //HTML kodu kapanış | |
delay(1); | |
Serial.println("Baglanti sonlandi"); | |
Serial.println(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment