{{ toaster.text }}

Wifi Locked Box

A box with a self-locking mechanism; it can only be opened by entering a password on its website.

Albert van der Meer 2016-02-07 00:00:00

Wifi Locked Box, Internet of Things, Electronics,

Wifi Locked Box


A little box that locks itself from the inside; can be opened via a website, using an ESP-8266 v12 module. It is used as a box containing a letter, which can only be opened by solving a puzzle on a webpage.



locking mechanism

The locking system is a pin attached to a servo in such a way that the pin can be pushed for- and backwards. This makes it possible to hold two rings (one for the box, one for the cover) together. To make sure the servo does not suffer from tensile force, the attachment of the pin is flexible.



The core is an ESP-8266 v12 module; In order to use it with a 9v battery, a conversion to both 5v (for servo) and 3.3v (for ESP) is required. Therefore, two voltage regulaters are used: one for 5v, which output is used for both the servo and the ESP. The ESP breakout board has an build-in 3.3v voltage regulator; to use it, the second resistor (out of three) has to be desoldered. To prevent a battery draw when the box is unused, a power switch is attached. Furthermore, when the box is unlocked, a little led lights up.




For the webpage, I designed a drag and drop puzzle. When the puzzle is solved, the webpage requested by the ESP gets updated, so the page shows the command to open the box. On the other hand, the script updates the page in order to lock the box when the puzzle is solved incorrectly. Furthermore, I added some methods for checking whether the device is turned on by logging the requests by the ESP. This is used to give an alert on the puzzle-webpage, saying the connection with the device is lost/not established.


The ESP is programmed using the arduino IDE; There are a few tasks:

  • connecting to the right network
  • requesting a certain webpage with a 5 sec. interval
  • act on the response: opening/closing the lock by turning the servo


#include <ESP8266WiFi.h>
#define servopin 14
#define ledpin 5
#include <Ticker.h>
#include "myServo.h"

Servo servo;

const char* ssid     = "NetworkName";
const char* password = "NetworkPassword";

const char* host = "avdm.nl";

void setup() {
 // pinMode(A0, INPUT); //analog pin is input
  pinMode(ledpin, OUTPUT); 
  servo.attach(servopin); //start servo

  // We start by connecting to a WiFi network

  Serial.print("Connecting to ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

  Serial.println("WiFi connected");
  Serial.println("IP address: ");

int value = 0;
int pos;
String response;
bool closed = true;
int j = 7;
int maxLoop = 8;

void loop() {
 /* Serial.println(analogRead(A0));  if(analogRead(A0)>600){    digitalWrite(ledpin, HIGH);  }  else{    digitalWrite(ledpin, LOW);  }*/

  if (j == maxLoop) {
    Serial.print("connecting to ");

    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");

    // We now create a URI for the request
    String url = "/my/check/url";
    Serial.print("Requesting URL: ");

    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "User-Agent: ArduinoWiFi/1.1\r\n" +
                 "Connection: close\r\n\r\n");

    // Read all the lines of the reply from server and print them to Serial
    response = "";
    while (client.available()) {
      // String line = client.readStringUntil('\r');
      // Serial.print(line);
      char c = client.read();
      response += c;
    // Serial.println(response+"|");
    response = response.substring(response.length() - 10, response.length() - 7);

    if (response == "000") {
      closed = true;
      digitalWrite(ledpin, LOW);
    if (response == "360") {
      closed = false;
      digitalWrite(ledpin, HIGH);

    if (closed) {
    else {
    Serial.println("closing connection");
    j = 0;


the Facts

built for Albert
owner Albert
state finished (january 2016)
method wifi