Introduction: Satline SmartSafe

Satline or we called it “Satpam Online” is a smart safe that is built in with a 2-MP camera that can capture anyone who opens it. This smart safe is also integrated with mobile apps so you can open the file or identify the person wherever you are with your smartphone.

The purpose of making this device is that we want to dive deep into security device. We feel that security device nowadays is a mandatory for company or even for regular user. We see safe that in the market can be transform into electronic device that integrated with Internet of things technology in order to improve its safety. In satline we try to improve security by adding camera that capture the person that opened it and adding solenoid door lock to control the safe lock automatically using mobile application

By the end of the project, there are few problems we need to evaluate. The first one is to change the solenoid door lock we used in this project into generic type to add more security to our project. The second one is to add additional antenna for esp32 cam and esp 32 to wider the network range because sometimes network problem occur in our project. The last problem is the speed reaction, Esp32 cam took a long time to capture image and upload it to firebase, For this problem we need to consider changing microcontroller like raspberry pi.

In the end for the conclusion. The esp 32 cam and esp 32 can be transform into a powerful system for smartsafe. however there are a few problems that we need to evaluate for future project such as the security aspect, the reaction time, and the network range. Despite the problem we encounter our project seems to have success in terms of standard measure that we set and success in terms of the main purpose of building this devices and all the features we all want to make.



This project created by : 

  • Andrew Arvianto (2501988560)
  • Kenneth Satyadharma (2502002223)
  • Jonathan Kartawiguna (2501999141)


Link demo video : https://youtu.be/h35TkZKIzNU



Supplies

Hardware for cam system : 

1x ESP32-CAM AI THINKER + Camera OV2640 2MP + Micro USB Cable + Dev Board    ESP32Cam to TTL CH340

1x Passive Buzzer Module 5V Pasif Module

1x MC-38 Magnetic Door Sensor

1x LED Red

1x Resistor 1K Ohm 0.25 W 5%

1x Double Layer Through Hole 3x7cm PCB

1x Plain PCB

1x Rocker Switch 2-pin

2x Terminal Block 2-pin

2x Long Stackable Header 8 Pin 2.54mm Pitch

Sufficient Jumper Cable Male-to-Male

1x 


Hardware for door lock system :

1x Esp32 

1x Relay module

1x Solenoid door lock


Software Supplies:

Visual Studio Code (Platform.io, C++ & Flutter/Dart extension included)

MinGW C++ Compiler

Google Firebase RTDB & Storage


Step 1: Designing PCB and Making the PCB

Designing pcb for esp cam that has 5v input and output for 1 buzzer, door magnet sensor, 1 Red LED. 

Designing PCB for esp 32 that used to make doorlock system. This PCB needed 12 V input for relay module and 5v input for esp 32. 

After that in easy eda convert the design into pcb



Step 2: Code the Esp 32

Code the esp 32 cam and doorlock to meet exactly what the requirement is to make the system we want. 

In ESP 32 cam we need the esp to send data in jpg files to firebase and also receive data in boolean from firebase. The data from firebase (0/1) needed to make the state in firebase. It compares the data obtained from the magnet sensor and from the data from firebase. The comparison tells the esp when to send data or when to stop sending data.


Github link : https://github.com/arvian75/SATLINE_ESP32.git


In the ESP32 board for the door lock we only use a relay module , solenoid, and power supply. This ESP code below is designed to create a WiFi-connected door lock system using a solenoid, controlled through Firebase, a cloud-based platform. The code initializes a connection to a WiFi network and sets up Firebase for real-time data streaming. It listens for changes in lock state ("LockState") from Firebase, using the onFirebaseStream function to update the lockState variable. When lockState is 1 (indicating the door should be unlocked), the solenoid is activated (door unlocked) for 5 seconds, and then deactivated (door locked), with lockdone ensuring the action happens only once per state change. The system continuously checks the lock state in the main loop and updates the physical lock status accordingly, providing feedback via the serial console.




Doorlocking system 


#include <Arduino.h>

#include <WiFi.h>

#include <Firebase_ESP_Client.h>

#include <addons/TokenHelper.h>


#define SOLENOID_PIN 15

#define FIREBASE_HOST ""

#define FIREBASE_AUTH ""

#define WIFI_SSID ""

#define WIFI_PASSWORD ""

// put function declarations here:

FirebaseData fbdo;

FirebaseAuth auth;

FirebaseConfig fbConfig;

FirebaseAuth fbAuth;

FirebaseData fbdoStream;

int lockState = 0, lockdone = 0;


void onFirebaseStream(FirebaseStream data) {

  Serial.printf("onFirebaseStream: %s %s %s %s\n", data.streamPath().c_str(),

                data.dataPath().c_str(), data.dataType().c_str(),

                data.stringData().c_str());

  if (data.dataType() == "json") {

    if(data.stringData() == "{\"LockState\":1}") {

      lockState = 1;

    } else {

      lockState = 0;

    }

  }

}


void Firebase_BeginStream(const String& streamPath) {

  String path = streamPath;

  if (Firebase.RTDB.beginStream(&fbdoStream, path.c_str()))

  {

    Serial.println("Firebase stream on "+ path);

    Firebase.RTDB.setStreamCallback(&fbdoStream, onFirebaseStream, 0);

  }

  else

    Serial.println("Firebase stream failed: "+fbdoStream.errorReason());

}


void Firebase_EndStream(const String& streamPath) {

  if(Firebase.RTDB.endStream(&fbdoStream))

    Serial.println("Firebase stream end");

  else {

    Serial.println("Firebase stream end failed: "+fbdoStream.errorReason());

    Serial.println("Trying to end stream again");

    Firebase_EndStream(streamPath);

  }

}


void Firebase_Init(const String& streamPath) {

  fbConfig.host = FIREBASE_HOST;

  fbConfig.signer.tokens.legacy_token = FIREBASE_AUTH;

  fbConfig.token_status_callback = tokenStatusCallback;

  Firebase.begin(&fbConfig, &fbAuth);

  Firebase.reconnectWiFi(true);


  while (!Firebase.ready())

  {

    Serial.println("Connecting to firebase...");

    delay(1000);

  }

  Serial.println("Connected to firebase");

  Firebase_BeginStream(streamPath);

}


void setup()

{

  Serial.begin(9600);

  pinMode(SOLENOID_PIN, OUTPUT);    // Set the solenoid pin as an output

  digitalWrite (SOLENOID_PIN, HIGH); // Ensure the solenoid is initially off

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  Serial.print("Connecting to WiFi");

  while (WiFi.status() != WL_CONNECTED)

  {

    Serial.print(".");

    delay(300);

  }

  Serial.print("Connected with IP: ");

  Serial.println(WiFi.localIP());


  Firebase_Init("Receive");

  delay(1000);

}


void loop() {

  // put your main code here, to run repeatedly:

  if (lockState == 1 && lockdone == 0) {

      Serial.println("Door Opened");

      digitalWrite(SOLENOID_PIN, LOW); // Activate the solenoid

      delay(5000);

      digitalWrite(SOLENOID_PIN, HIGH);// Deactivate the solenoid

      lockdone = 1;

    }

    vTaskDelay(1000 / portTICK_PERIOD_MS);

  if (lockState == 0 && lockdone == 1) {

    Serial.println("Door Locked");

    lockdone = 0;

  }

  delay(2000);

}



This Door Locking system functions based on values from a Firebase RTDB Cloud.

Block diagram = 


RTDB firebase → Callback function Firebase → Get value of Lockstate → If lockstate =1 activate solenoid for 5 seconds, if lockstate = 0 don't activate solenoid → loop every 2 second.



Step 3: Making 3D Print

We use 3D printing with PLA material for the case. The 3D print is customized to fit and contain the ESP which is used for the door lock or solenoid system. The 3D print has a dimension of 12mm x 12mm x 8mm followed by 11mm x 6mm x 11mm with a thickness of 5mm to contain the ESP32 as mentioned before. The 3D print case also has 2 holes in the back side, each hole having a dimension of 15mm in diameter. The holes are used to arrange the wire in which the upper hole is used to power the ESP32 cam through the ESP and the lower hole is used to configure as well as to power the solenoid system using the ESP32.


Below is the link to the STL of our PCB case:

https://drive.google.com/drive/folders/17gcsyzSXlkddiuxwrJ8kx99U1vDqbdej?usp=sharing


Step 4: Making Satline Mobile Apps

Github Link : https://github.com/arvian75/SATLINE_APP.git

We make a mobile apps using flutter language. The apps can send boolean 0/1 to verify state in esp 32 cam and receive jpg data from firebase. We make 3 pages. The first one is to view updated image and to open or close the doorlock. The second pages apps is to view history that devided in terms of days-months-year. The third pages is

to view the list of photo that taken in the date that selected.