Mekatronik Mühendisliği Forum


NODEMCU-ARDUINO IDE 4 -RELAY CONTROL
Değerlendir:
  • 0 Oy - 0 Yüzde
  • 1
  • 2
  • 3
  • 4
  • 5


Konu: 38
Mesaj: 66
Cinsiyet: Erkek
Kıdem: Apr 2017

NODEMCU-Relay Control
Gerekli ekipmanlar:
1- Nodemcu v1
2-4lü Relay modulü
3- jumper

[Resim: EPWY9n.png]

Bağlantı şekli:

vcc 3v3 (nodemcu) to vcc relay
gnd (nodemcu) to GND relay
D5 ----(nodemcu) IN1 röle
D6----- (nodemcu) IN2 röle
D7 -----(nodemcu) IN3 röle
D8 ----(nodemcu) IN4 röle




Kod:
#include <ESP8266WiFi.h>

const char* ssid = "wifiadınız";
const char* password = "wifişifre";

String readStrings = "";

int pin1 = 14; // GPIO 14 (D5)
int pin2 = 12; // GPIO 12 (D6)
int pin3 = 13; // GPIO 13 (D7)
int pin4 = 15; // GPIO 15 (D8)

WiFiServer server(88);
IPAddress ip(192, 168, 1, 109);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

void setup() {
  Serial.begin(115200);
  delay(10);

  pinMode(pin1, OUTPUT); //pin1 output
  pinMode(pin2, OUTPUT); //pin2 output
  pinMode(pin3, OUTPUT); //pin3 output
  pinMode(pin4, OUTPUT); //pin4 output

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  WiFi.config(ip,gateway,subnet);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());

}

void loop() {
  // put your main code here, to run repeatedly:
  WiFiClient client = server.available();

  if (client) {
    Serial.println("Yes client");

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();


        if (readStrings.length() < 100) {
          readStrings += c;
        }

        if (c == '\n') {
          Serial.println(readStrings);
          client.print("HTTP/1.1 200 OK\r\n");
          client.print("Content-Type: text/html\r\n\r\n");
          client.print("<!DOCTYPE HTML>\r\n");
          client.print("<HTML>\r\n");//html tag
          client.print("<HEAD>\r\n"); //
          //            client.print("<meta http-equiv='refresh' content='10'/>\r\n");
          client.print("<meta name='apple-mobile-web-app-capable' content='yes' />\r\n");
          client.print("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />\r\n");
          client.print("<link rel='stylesheet' type='text/css' href='http://slumberjer.com/hanis.css' />\r\n");
          client.print("<TITLE>Home Automation</TITLE>\r\n");
          client.print("</HEAD>\r\n");
          client.print("<BODY>\r\n");
          client.print("<H1>My Smart Home System</H1>\r\n");
          client.print("<hr />\r\n");
          client.print("<br />\r\n");
          client.print("<H2>Build Using Nodemcuv1 Arduino</H2>\r\n");
          client.print("<br />\r\n");
          client.print("<p><b>Front Gate</b></p><br />\r\n");
          client.print("<a href=\"/?button1on\"><font color = \"green\">ON   </font></a>\r\n");
          client.print("<a href=\"/?button1off\"><font color = \"red\">OFF  </font></a><br />\r\n");
          client.print("<p><b>Living Room</b></p>");
          client.print("<br />\r\n");
          client.print("<a href=\"/?button2on\"><font color = \"green\">ON   </font></a>\r\n");
          client.print("<a href=\"/?button2off\"><font color = \"red\">OFF  </font></a><br />\r\n");
          client.print("<p><b>Room A</b></p>");
          client.print("<br />\r\n");
          client.print("<a href=\"/?button3on\"><font color = \"green\">ON   </font></a>\r\n");
          client.print("<a href=\"/?button3off\"><font color = \"red\">OFF  </font></a><br />\r\n");
          client.print("<p><b>Room B</b></p>");
          client.print("<br />\r\n");
          client.print("<a href=\"/?button4on\"><font color = \"green\">ON   </font></a>\r\n");
          client.print("<a href=\"/?button4off\"><font color = \"red\">OFF  </font></a><br />\r\n");
          client.print("<br />\r\n");
          client.print("<p><b>All Switches</b></p>");
          client.print("<br />\r\n");
          client.print("<br />\r\n");
          client.print("<a href=\"/?buttonallon\"><font color = \"green\">ALL ON   </font></a>\r\n");
          client.print("<a href=\"/?buttonalloff\"><font color = \"red\">ALL OFF  </font></a><br />\r\n");
          client.print("<br />\r\n");
          client.print("</BODY>\r\n");
          client.print("</HTML>\n");

          delay(1);

          client.stop();
          if (readStrings.indexOf("?button1on") > 0) {
            Serial.println("1 on");
            digitalWrite(pin1, LOW);
          }
          if (readStrings.indexOf("?button1off") > 0) {
            Serial.println("1 off");
            digitalWrite(pin1, HIGH);
          }

          if (readStrings.indexOf("?button2on") > 0) {
            Serial.println("2 on");
            digitalWrite(pin2, LOW);
          }
          if (readStrings.indexOf("?button2off") > 0) {
            Serial.println("2 off");
            digitalWrite(pin2, HIGH);
          }
          if (readStrings.indexOf("?button3on") > 0) {
            digitalWrite(pin3, LOW);
            Serial.println("3 on");
          }
          if (readStrings.indexOf("?button3off") > 0) {
            digitalWrite(pin3, HIGH);
            Serial.println("3 off");
          }
          if (readStrings.indexOf("?button4on") > 0) {
            digitalWrite(pin4, LOW);
            Serial.println("4 on");
          }
          if (readStrings.indexOf("?button4off") > 0) {
            digitalWrite(pin4, HIGH);
            Serial.println("4 off");
          }
          if (readStrings.indexOf("?buttonallon") > 0) {
            digitalWrite(pin1, LOW);
            digitalWrite(pin2, LOW);
            digitalWrite(pin3, LOW);
            digitalWrite(pin4, LOW);
          }
          if (readStrings.indexOf("?buttonalloff") > 0) {
            digitalWrite(pin1, HIGH);
            digitalWrite(pin2, HIGH);
            digitalWrite(pin3, HIGH);
            digitalWrite(pin4, HIGH);
          }
          readStrings = "";
        }//if(c == '\n')
      }//if(client.available())
    }//while(client.connected())
  }//if(client)
}//void loop()

Cevapla
Teşekkür Edenler
.
Konu: 114
Mesaj: 181
Cinsiyet: Erkek
Kıdem: Oct 2015

Teşekkürlerr
Mekatronik Mühendisi
 kilicaslanabdullah95@gmail.com

Cevapla
Teşekkür Edenler
.


Benzeyen Konular
Konu: Yazar Cevaplar: Gösterim: Son Mesaj
  NodeMCU --BUTON İLE LED CONTROL Alper_Arslantas 0 245 06-03-2018, 00:04 AM
Son Mesaj: Alper_Arslantas
  ESP8266 Arduino LED Control Alper_Arslantas 0 506 23-09-2017, 22:47 PM
Son Mesaj: Alper_Arslantas

Foruma atla:


Konuyu görüntüleyenler: 1 Misafir

Türkçe Çeviri : MyBB Türkiye
MyBB, © 2002-2018 MyBB Group.