Arduino Ethernet Escape Room Numbers LCD Combination Interactive

Hľadaný kód pre miestnosť KE-012

Escape Room - Arduino + Ethernet, Webclient - výhra hráča

Escape-Spiel - Webclient - Arduino


Hardwarebeschreibung:

  • Arduino Nano / Uno / Arduino Mega 2560
  • Ethernet-Abschirmung Wiznet W5100
  • 5x Umschalttaste
  • LCD-Anzeige 16x2 / 20x4
  • I2C-Konverter für LCD-Anzeige
  • Elektromagnetisches Relais SRD-05VDC-SL-C / SSR-Relais OMRON G3MB-202P
  • Magnetverschluss 12/24 V
  • Funktionsbeschreibung:

  • Der Player verfügt über 5 Zifferneingabetasten.
  • Mit vier Tasten erhöht der Player die Nummer in jeder der vier Positionen.
  • Die fünfte Schaltfläche enthält Daten, die an den Webserver gesendet werden und den Nutzlastzugriff / das Nutzlastproblem zurückgeben.
  • Im Falle einer "Access" -Nutzlast wird das Relais aktiviert und die Magnet-Türverriegelung geöffnet, sodass sich die Spieler im Spiel weiter bewegen können.
  • Bei Nutzlast "Problem" bleibt das Relais offen, das Schloss öffnet nicht. Die Tür kann nicht geöffnet werden.
  • Der Player kann auch durch einen Summer oder eine LED mit Anzeige über den Fehler informiert werden.
  • Implementierungen:

  • One Number: - Verwenden Sie die Tasten 1-5, um eine Nummer (1,2,3,4,5) zu senden, von denen eine korrekt ist. Max. Die Kombination aus 5 enthält nicht die Eingabetaste.
  • Vier sich wiederholende Nummern: - Verwenden Sie die Tasten 1-4, um eine Zahl zwischen 0 und 9 für jede der vier sich wiederholenden Positionen zu erhöhen. Max. 10.000 Kombinationen.
  • Vier Zahlen ohne Wiederholung: - Implementierung ohne Wiederholung von Zahlen (Funktionalität wie bei der Wiederholung von vier Zahlen), Kombination von maximal 5040.
  • Weboberfläche:

  • Die Weboberfläche bietet die Möglichkeit, die Suchnummer in jeder der drei Implementierungen zu ändern (kann gleichzeitig verwendet werden).
  • Berücksichtigt die Einschränkungen aller Implementierungen (Wiederholung, numerische Codelänge).
  • Anmeldedaten können geändert werden. Es ist möglich, die Protokollierung und Statistik der vom Arduino-Mikrocontroller empfangenen Daten zu aktivieren. Statistik des Spielererfolgs mit Aufzeichnung der erhaltenen Zahlenkombinationen, Akzeptanzzeiten.
  • Schaltplan:

    Schéma zapojenia - Escape Room - Arduino + Ethernet, Webclient

    Block scheme

    Bloková schéma - Escape Room - Arduino + Ethernet, Webclient

    Arduino + Ethernet W5100 program:

    /*|----------------------------------------------------------|*/
    /*|SKETCH FOR ESCAPE ROOM - Arduino + Ethernet W5100         |*/
    /*|Author: Bc. MARTIN CHLEBOVEC                              |*/
    /*|FB: https://www.facebook.com/martin.s.chlebovec           |*/
    /*|EMAIL: martinius96@gmail.com                              |*/
    /*|WEB: https://arduino.php5.sk?lang=en                      |*/
    /*|----------------------------------------------------------|*/
    #include <SPI.h>
    #include <Ethernet.h>
    
    byte mac[] = { 0xAA, 0xBB, 0xCC, 0xAA, 0xBB, 0xCC };
    IPAddress ip(192, 168, 1, 101);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress subnet(255, 255, 255, 0);
    char serverName[] = "192.168.1.254"; //or hostname
    int serverPort = 80;
    
    const int buttonPin1 = 9;
    const int buttonPin2 = 8;
    const int buttonPin3 = 7;
    const int buttonPin4 = 6;
    const int buttonPin5 = 5;
    const int relay = 3;
    
    int buttonState1 = HIGH;
    int buttonState2 = HIGH;
    int buttonState3 = HIGH;
    int buttonState4 = HIGH;
    int buttonState5 = HIGH;
    
    int lastButtonState1 = HIGH;
    int lastButtonState2 = HIGH;
    int lastButtonState3 = HIGH;
    int lastButtonState4 = HIGH;
    int lastButtonState5 = HIGH;
    
    unsigned long lastDebounceTime1 = 0;
    unsigned long lastDebounceTime2 = 0;
    unsigned long lastDebounceTime3 = 0;
    unsigned long lastDebounceTime4 = 0;
    unsigned long lastDebounceTime5 = 0;
    unsigned long debounceInterval = 50;
    
    
    
    EthernetClient client;
    int number = 0;
    String url = "/sendnumber.php";
    void setup() {
      Serial.begin(115200);
      pinMode(relay, OUTPUT);
      digitalWrite(relay, HIGH); //lock door
      pinMode(buttonPin1, INPUT_PULLUP);
      pinMode(buttonPin2, INPUT_PULLUP);
      pinMode(buttonPin3, INPUT_PULLUP);
      pinMode(buttonPin4, INPUT_PULLUP);
      pinMode(buttonPin5, INPUT_PULLUP);
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      Serial.println("IP address set to Ethernet shield:");
      Serial.println(Ethernet.localIP());
      delay(2000);
      Serial.println("Ready");
    }
    
    void send_datas() {
      String my_datas = String(number);
      String data = "number=" + my_datas;
      if (client.connect(serverName, serverPort)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)serverName);
        client.println("User-Agent: ArduinoEthernetWiznet");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        while (client.connected()) {
          //HTTP HEADER
          String line = client.readStringUntil('\n'); //HTTP header
          if (line == "\r") {
            break; //blank line between HTTP header and payload
          }
        }
        String line = client.readStringUntil('\n'); //Payload first line
        if (line == "Access") {
          Serial.println("Access gained!");
          digitalWrite(relay, LOW); //unlock door to next level
        } else {
          Serial.println("Access denied!");
          digitalWrite(relay, HIGH); //lock door
        }
      } else {
        Serial.println("Error connecting to webserver!");
      }
      client.stop();
    }
    
    void loop() {
      int reading1 = digitalRead(buttonPin1);
      int reading2 = digitalRead(buttonPin2);
      int reading3 = digitalRead(buttonPin3);
      int reading4 = digitalRead(buttonPin4);
      int reading5 = digitalRead(buttonPin5);
    
      if (reading1 != lastButtonState1) {
        lastDebounceTime1 = millis();
      }
    
      if (reading2 != lastButtonState2) {
        lastDebounceTime2 = millis();
      }
    
      if (reading3 != lastButtonState3) {
        lastDebounceTime3 = millis();
      }
    
      if (reading4 != lastButtonState4) {
        lastDebounceTime4 = millis();
      }
    
      if (reading5 != lastButtonState5) {
        lastDebounceTime5 = millis();
      }
      if ((millis() - lastDebounceTime1) > debounceInterval) {
        if (reading1 != buttonState1) {
          buttonState1 = reading1;
          if (buttonState1 == HIGH) {
            number = 1;
            send_datas();
          }
        }
      }
    
      if ((millis() - lastDebounceTime2) > debounceInterval) {
        if (reading2 != buttonState2) {
          buttonState2 = reading2;
          if (buttonState2 == HIGH) {
            number = 2;
            send_datas();
          }
        }
      }
    
      if ((millis() - lastDebounceTime3) > debounceInterval) {
        if (reading3 != buttonState3) {
          buttonState3 = reading3;
          if (buttonState3 == HIGH) {
            number = 3;
            send_datas();
          }
        }
      }
    
      if ((millis() - lastDebounceTime4) > debounceInterval) {
        if (reading4 != buttonState4) {
          buttonState4 = reading4;
          if (buttonState4 == HIGH) {
            number = 4;
            send_datas();
          }
        }
      }
      if ((millis() - lastDebounceTime5) > debounceInterval) {
        if (reading5 != buttonState5) {
          buttonState5 = reading5;
          if (buttonState5 == HIGH) {
            number = 5;
            send_datas();
          }
        }
      }
      lastButtonState1 = reading1;
      lastButtonState2 = reading2;
      lastButtonState3 = reading3;
      lastButtonState4 = reading4;
      lastButtonState5 = reading5;
    
    }
    

    Arduino + Ethernet W5500 program:

    /*|----------------------------------------------------------|*/
    /*|SKETCH FOR ESCAPE ROOM - Arduino + Ethernet W5500         |*/
    /*|Author: Bc. MARTIN CHLEBOVEC                              |*/
    /*|FB: https://www.facebook.com/martin.s.chlebovec           |*/
    /*|EMAIL: martinius96@gmail.com                              |*/
    /*|WEB: https://arduino.php5.sk?lang=en                      |*/
    /*|----------------------------------------------------------|*/
    #include <SPI.h>
    #include <Ethernet2.h>
    
    byte mac[] = { 0xAA, 0xBB, 0xCC, 0xAA, 0xBB, 0xCC };
    IPAddress ip(192, 168, 1, 101);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress subnet(255, 255, 255, 0);
    char serverName[] = "192.168.1.254"; //or hostname
    int serverPort = 80;
    
    const int buttonPin1 = 9;
    const int buttonPin2 = 8;
    const int buttonPin3 = 7;
    const int buttonPin4 = 6;
    const int buttonPin5 = 5;
    const int relay = 3;
    
    int buttonState1 = HIGH;
    int buttonState2 = HIGH;
    int buttonState3 = HIGH;
    int buttonState4 = HIGH;
    int buttonState5 = HIGH;
    
    int lastButtonState1 = HIGH;
    int lastButtonState2 = HIGH;
    int lastButtonState3 = HIGH;
    int lastButtonState4 = HIGH;
    int lastButtonState5 = HIGH;
    
    unsigned long lastDebounceTime1 = 0;
    unsigned long lastDebounceTime2 = 0;
    unsigned long lastDebounceTime3 = 0;
    unsigned long lastDebounceTime4 = 0;
    unsigned long lastDebounceTime5 = 0;
    unsigned long debounceInterval = 50;
    
    
    
    EthernetClient client;
    int number = 0;
    String url = "/sendnumber.php";
    void setup() {
      Serial.begin(115200);
      pinMode(relay, OUTPUT);
      digitalWrite(relay, HIGH); //lock door
      pinMode(buttonPin1, INPUT_PULLUP);
      pinMode(buttonPin2, INPUT_PULLUP);
      pinMode(buttonPin3, INPUT_PULLUP);
      pinMode(buttonPin4, INPUT_PULLUP);
      pinMode(buttonPin5, INPUT_PULLUP);
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      Serial.println("IP address set to Ethernet shield:");
      Serial.println(Ethernet.localIP());
      delay(2000);
      Serial.println("Ready");
    }
    
    void send_datas() {
      String my_datas = String(number);
      String data = "number=" + my_datas;
      if (client.connect(serverName, serverPort)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)serverName);
        client.println("User-Agent: ArduinoEthernetWiznet");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        while (client.connected()) {
          //HTTP HEADER
          String line = client.readStringUntil('\n'); //HTTP header
          if (line == "\r") {
            break; //blank line between HTTP header and payload
          }
        }
        String line = client.readStringUntil('\n'); //Payload first line
        if (line == "Access") {
          Serial.println("Access gained!");
          digitalWrite(relay, LOW); //unlock door to next level
        } else {
          Serial.println("Access denied!");
          digitalWrite(relay, HIGH); //lock door
        }
      } else {
        Serial.println("Error connecting to webserver!");
      }
      client.stop();
    }
    
    void loop() {
      int reading1 = digitalRead(buttonPin1);
      int reading2 = digitalRead(buttonPin2);
      int reading3 = digitalRead(buttonPin3);
      int reading4 = digitalRead(buttonPin4);
      int reading5 = digitalRead(buttonPin5);
    
      if (reading1 != lastButtonState1) {
        lastDebounceTime1 = millis();
      }
    
      if (reading2 != lastButtonState2) {
        lastDebounceTime2 = millis();
      }
    
      if (reading3 != lastButtonState3) {
        lastDebounceTime3 = millis();
      }
    
      if (reading4 != lastButtonState4) {
        lastDebounceTime4 = millis();
      }
    
      if (reading5 != lastButtonState5) {
        lastDebounceTime5 = millis();
      }
      if ((millis() - lastDebounceTime1) > debounceInterval) {
        if (reading1 != buttonState1) {
          buttonState1 = reading1;
          if (buttonState1 == HIGH) {
            number = 1;
            send_datas();
          }
        }
      }
    
      if ((millis() - lastDebounceTime2) > debounceInterval) {
        if (reading2 != buttonState2) {
          buttonState2 = reading2;
          if (buttonState2 == HIGH) {
            number = 2;
            send_datas();
          }
        }
      }
    
      if ((millis() - lastDebounceTime3) > debounceInterval) {
        if (reading3 != buttonState3) {
          buttonState3 = reading3;
          if (buttonState3 == HIGH) {
            number = 3;
            send_datas();
          }
        }
      }
    
      if ((millis() - lastDebounceTime4) > debounceInterval) {
        if (reading4 != buttonState4) {
          buttonState4 = reading4;
          if (buttonState4 == HIGH) {
            number = 4;
            send_datas();
          }
        }
      }
      if ((millis() - lastDebounceTime5) > debounceInterval) {
        if (reading5 != buttonState5) {
          buttonState5 = reading5;
          if (buttonState5 == HIGH) {
            number = 5;
            send_datas();
          }
        }
      }
      lastButtonState1 = reading1;
      lastButtonState2 = reading2;
      lastButtonState3 = reading3;
      lastButtonState4 = reading4;
      lastButtonState5 = reading5;
    
    }
    

    Webserver .php program (sendnumber.php):

    <?php 
    $secret_number = 3;
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
      $number = $_POST['number'];
      $number = trim( $number );
      if (is_numeric($number)){
        if($number==$secret_number){
          echo "Access";
        }else{
          echo "Problem";
        }    
      }
    }else{
      echo "Unsupported METHOD! Use POST instead of GET/PUT/PATCH!";
    }   
    ?>