Security safe with ESP8266

Place your projects here
Post Reply
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Security safe with ESP8266

Post by Fernando Perez »

Currently, safes are opened using a numeric keypad.
If you long for the old models that were opened with a rotary switch, which was turned left and right until the correct numerical combination was achieved, you can always ride this circuit.
Image
When the word “turn” appears on the TMS1637, turn the KY-04 rotary encoder clockwise to the first number in the combination. Wait 2 seconds until the “Good” message appears. Wait until our number comes up again, and turn left until the next combination. Repeat the process, now to the right, then to the left.
If you have entered the 4 numbers correctly (the number can be easily expanded), the message “Open” will appear and the relay will open.
When we have stolen all the jewels :lol: , we press the central button of the KY-04, with which we will be able to close the relay.

Code: [Local Link Removed for Guests]

' Opening codes
dim safeKey(3) = 26, -11, 40, -18
key = 0 : code = 0 : pos = 0

' Messages
turn$ = "turn"
good$ = "good"
open$ = str$(0) + "pen"

' Setup
' door lock -> GPIO2 (D4)
' TM1637: CLK -> GPIO1 (TX), DIO -> GPIO3 (RX)
' KY-04:  CLK -> GPIO5 (D1), DT  -> GPIO4 (D2), SW -> GPIO0 (D3) 

pin.mode 0, input, pullup
pin.mode 1, output
pin.mode 2, output
pin.mode 3, output
pin.mode 4, input
pin.mode 5, input

DT  = 4 
CLK = 5
SW = 0 
lock = 2
lastCLK = pin(CLK)

tm1637.setup 3, 1 ' Don't forget the 10k pullup resistors
tm1637.print turn$

WHILE 1

  if pin(CLK) <> lastCLK then
    lastCLK = pin(CLK)
    if pin(CLK) <> pin(DT) then pos = pos + 0.5 else pos = pos - 0.5
    code = cInt(pos)
    if pos > 50 then pos = 50
    if pos < -50 then pos = -50
    tm1637.print str$(code, "%4.0f")
  end if  

  if code = safeKey(key) then
    pause 2000
    if code = safeKey(key) then
      tm1637.print good$
      pause 2000
      tm1637.print str$(code, "%4.0f")
      key = key +1  
    end if
  end if

  if key = 4 then
    tm1637.print open$
    pin(lock) = 1
    do
    loop until pin(SW) = 0
    pin(lock) = 0
    reboot
  end if 

WEND
Naturally, it is preferable that instead of directly acting on the relay that controls the lock, our ESP8266 sends an opening code via ESP-Now to another ESP8266 or ESP32 that is in charge of opening / closing the remote lock.

But that is already to improve the school grade. 8-) 8-)
User avatar
PeterN
Posts: 366
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 171 times
Been thanked: 203 times
Contact:

Re: Security safe with ESP8266

Post by PeterN »

I'm afraid it won't really help but only create many other problems if you would put the complete circuit in the safe
;)
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Re: Security safe with ESP8266

Post by AndyGadget »

I love that idea, but what it really needs is a 'click click click' as it passes each number :D
I would think just a quick pulse to a simple sounder should do it.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: Security safe with ESP8266

Post by Fernando Perez »

Peter, I would never put the knob and the bolt in the same box. We've seen so many thief movies bridging the connection!
That is why I suggested the idea of using ESP-NOW.

Andy, his wishes are orders:

Code: [Local Link Removed for Guests]

' Piezoelectric capsule -> GPIO13 (D7) 
pin.mode 13, output 

WHILE 1

  if pin(CLK) <> lastCLK then
    lastCLK = pin(CLK)
    if pin(CLK) <> pin(DT) then pos = pos + 0.5 else pos = pos - 0.5
    code = cInt(pos)
    if pos > 50 then pos = 50
    if pos < -50 then pos = -50
    tm1637.print str$(code, "%4.0f")
    if code = pos then pin.tone 13, 6100, 50   ' NEW line to hear a click
  end if 
Image

Video:
https://www.myrapidq.it/public/safe.mp4

But this publication is an excuse to ask everyone what is the routine that has really worked for them to control a rotary decoder, without jumps, false shots, smoothness in the route, etc.
This one that I have been adjusting works well for me, but surely you know of a more refined one.
Please tell me.
User avatar
PeterN
Posts: 366
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 171 times
Been thanked: 203 times
Contact:

Re: Security safe with ESP8266

Post by PeterN »

Good evening Fernando

A very interesting project that evokes some interesting or perhaps confused ideas here.
Could it raise the safety level somewhat if the output does not switch a simple solenoid bolt, but an analog servo. The servo would then need at least a slightly more complex PWM control signal, the external supply of which would at least not be completely trivial. Also, the necessary angle of the servo for the opening might not be exactly the end stop, which makes overcoming with an external PWM-Signal a bit more complex - but not impossible
In the end, James Bond will break it open with his LASER watch. ;)
Post Reply