Notifications
Clear all

Implementing a safe unlock application

60 Posts
6 Users
6 Likes
2,787 Views
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

Hi everybody,

I have a safe which has been secured in a concrete wall 22 years ago, so nearly impossible to replace. The safe normally opens after the correct password gets entered on a small keypad.

Recently the little electronic circuit went bust and the safe is completely unsupported by the manufacturer.

I told myself that it should not be difficult to implement with an Arduino. I just started learning about the hardware and software two days ago. My programming skills are somehow limited but I hope to learn fast.

I wrote some code which does exactly what I want but the Arduino Nano is too power hungry for the small battery I wished to use, I  would like it to last for years like it was with the original circuit.

So the project should be defined as follows.

Code to accept key presses from a matrix keypad and when the correct code is entered it should activate a relay which in turn will activate a solenoid to allow the opening of the safe.

I have done some code which does about everything I wanted but when I try to bring the Arduino Nano into deep sleep and wake it up when a key is pressed the behavior is erratic.

I see that I can't post my code, so how can we proceed if someone can help me ?


   
Inq reacted
Quote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Welcome to the forum.  Between this and your first post, it sounds like you have a lot of interests that can be addressed with these microprocessors.  It seems like I recall that there is a grace period (a day or two) and/or some restrictions until a certain number of posts.  Try making a few more posts to your thread here and eventually (I think less than 10) you'll be able to add images and post code snippets using the editor button.

image

I've not used any of the sleep modes on Arduino or other MPU's.  I had this bookmarked for the day I might need it.  It might be useful to you.

https://hackaday.com/2020/01/15/one-esp8266-one-battery-one-year-and-counting/

Here is what code looks like once your allowed to add it:

#include <user_interface.h>
/*
  Stepper Motor Demonstration 4
  Stepper-Demo4.ino
  Demonstrates NEMA 17 Bipolar Stepper with A4988 Driver
 
  DroneBot Workshop 2018
   https://dronebotworkshop.com 
*/
 
// Define Constants
 
// Connections to A4988
const int dirPin = D8;  
const int stepPin = D7; 
const int enablePin = D6;
 
// Motor steps per rotation
const int STEPS_PER_REV = 2048;
const int STEP_DELAY = 1500; // uSec

void setup() 
{
  Serial.begin(115200);
  delay(1000);
  
  // Setup the pins as Outputs
  pinMode(stepPin, OUTPUT); 
  pinMode(dirPin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW); // Enabled
}

void loop() 
{  
  // Set motor direction clockwise
  digitalWrite(dirPin,HIGH); 
  Serial.print("CW Slow ");

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Alex reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@inq Strange I use the {;} for adding code. I wonder why two?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@papymouzot Hi, interesting project. I just finished a little project using timers and ISR's. The information is confusing, same company, different docs, different code. I mention this because I think you will run into some of the same hardware to implement a sleep.

Once you can post code it will be easier to figure out.

Did you consider some other tiny lower power boards like the new Pico and Rasberry Pi Zero2?

I will be paying close attention as I want to build a bunch of game cameras and have them go to sleep until an animal breaks some sort of sensor(s).

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 
Posted by: @zander

@papymouzot Hi, interesting project. I just finished a little project using timers and ISR's. The information is confusing, same company, different docs, different code. I mention this because I think you will run into some of the same hardware to implement a sleep.

Once you can post code it will be easier to figure out.

Did you consider some other tiny lower power boards like the new Pico and Rasberry Pi Zero2?

I will be paying close attention as I want to build a bunch of game cameras and have them go to sleep until an animal breaks some sort of sensor(s).

Hmmm... I never noticed the {;} version.  I just tried it and it didn't do anything really different like color coding.  It has a white background versus the blue of the other.

I don't know anything about the low power states of the Pico... but no way is Linux on a Pi Zero 2 going to be as energy efficient as an Arduino or ESP8266.

VBR,

Inq

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6970
 

@inq Some day I will have to measure them, I do have at least one of each. I suspect the PICO will be the least power hungry.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@papymouzot

I see that I can't post my code, so how can we proceed if someone can help me ?

I use the Arduino IDE. To copy code to a post I first right click and choose Select All on the sketch in the Arduino IDE and then right click and choose Copy as HTML
I then go to my post and hit the Enter a few times where I want to post my code. Then I click on the {;} icon in the menu bar and a Source code window appears. I click between the P's where I want to paste the code and then right click then choose Paste. Then click the OK button.

To enlarge an image, right click the image and choose Open link in new window.

postLayout
postCodeLayout

 

 


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1681
 

Hi @papymouzot,

Re: I wrote some code which does exactly what I want but the Arduino Nano is too power hungry for the small battery I wished to use, I would like it to last for years like it was with the original circuit.

I haven't tried this personally, but your requirement of lasting for years is quite steep for a 'standard' circuit. Boards like Arduinos are not generally designed for micro- (or maybe nano- in in your case) power applications, and hence will generally draw far too much power.

----------

As a background, please note:

It is common for microcontrollers to include low power modes. There are many applications in which reducing the power consumption to a 'low', but not 'ultra-low' level is 'good enough' and very beneficial.

For example, if the demand is 200mW for 50% of the time when it is actively working at full speed, then reducing to say 1mW, for the other 50% of the time, would still reduce the average heat dissipation, etc, by almost 50%, which in many cases may be very helpful in the achieving the overall system design.

However, it is of no benefit to applications like yours, as even 1mW would quickly exhaust your battery.

So, your application, although far from unique, needs a more specialised approach.

---------------------

It is not just a case of putting the microprocessor into a sleep mode, but also looking at every other component on the board to see if it is contributing to the power consumption. Indeed, even the PCB itself, if it has any surface contamination such as from handling, etc. can result in a power leakage, which under normal conditions is 'invisible' but can increase the drain on a tiny battery over a long period of time.

By the way, don't forget a solenoid may demand a relatively high current when it is activated, which may also determine the battery size.

------------

One approach might be to look for a means of completely depowering the microcontroller board, except for the short periods of time that the keypad is being operated.

Simplistically, one button could be dedicated to firing a monostable with a period of say 1 minute, whose output is the power input to the microcontroller .. so the user would first press that button and wait a second or two ... during which time,  the monostable would power up and boot the microprocessor board ... then the other buttons used to enter the code, etc.

Obviously the monostable circuit would need to be carefully chosen to only draw current during the minute of active operation, but this is likely to be easier than redesigning the microcontroller board.

This suggestion may look 'excessive' in terms of component count, etc.  compared to the specialised board it is replacing, and would not be suitable for a commercial project to make a large number of systems, but maybe a pragmatic approach for a 'one-off' case, like yours.

Just a suggestion ... good luck with your project. Dave

 


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

Hello, good morning to all, (well, at least, it is the morning for me 🙂 )

 

Thank you for your replies.  From what I read yesterday on the net, if I stay with Arduino hardware I will have to use another board than the Nano, probably the Mini Pro, which draws less current; and the best choice could be a bare board with the minimum required hardware on it.  I already ordered a Mini Pro and the usb interface from Ali yesterday.... a 8€ investment, I'll survive...

I watched also a very interesting video where the author made some current draw measurements on a Nano board after making some changes like removing the PWR Led, removing the voltage regulator, changing clock speed, changing input voltage .... Very interesting video.

One interesting path option could be to follow the recommendations from the YouTube video and measure current draw as I make the changes. The guy ended up with 0,3mA current draw if I remember well. it could be perfect for what I wish to do. Could be.... You tube - Arduino Nano current draw tweaks

The original circuitry of the safe based on a ST62T15C6 was powered from 4 Alcaline batteries of 1.5V. The battery pack used to last many years.

I have lots of Lithium rechargeable batteries available to run some tests with, I could use a single lipo with 5500mA capacity (IS1P) or double the cell with a 1S2P pack, which should give 11000mA worth of current backup under 3.2-4.2V depending on the charge (If such capacity is needed), and no need for a voltage regulator.... . The issue with LiPos however is self discharge, it may be more important than the board consumption itself. I believe I also have in my drawers some 26650 format LiFePO4, but these are 2500mA in capacity I think, they have very very low self discharge rates.... We'll see... Four 123 26650 cells in a 1S4P pack could also be considered.... if needed.... I read somewhere that if I reduce the 

But all that isn't my issue at the moment, it is more stage three of my "safe" project.

Stage one was to write code to do the job... What I have done works so far, as soon as I can post it I will. Maybe I'll add later the use of ADC to check battery voltage and report low battery somehow...

Stage two is today's task, implement a sleep mode... I have not found yet very clear guidelines on how to make it happen... So it will probably be trial and error.

Stage three: Test different hardware boards, circuitry change and battery options and check solenoid current draw also... 

Maybe, Arduino won't be the best option, this project will tell me, the positive thing is that it will make me learn something totally new for me 😜 😜  Three days ago I knew Arduino boards existed and that was all. Today I can do basic programming on it, I can this progress 😀 😀 😀 😉 😉 😉 😋 😋 😋  

 


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

I forgot, if some of you could post links to sites or videos where sleep mode options are described and coded I will greatly appreciate it...  Internet is a fantastic tool, but at times one spends more time looking for a solution than solving it... :p

 

Charles


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Giving more thought to your very specific use case just now... I realized one way you could very easily make a battery last for many years and you don't even have to mess with sleep modes.

  • Most of the sleep mode examples you'll find on the Internet are handling a very periodic situation.  Say... firing up, reading a sensor, firing up WiFi and logging it to some remote database, then sleeping... and doing this every minute.  The example I gave above claims it is successfully doing this for over a year.
  • I don't believe you have mentioned your user interface.  Since you're using a plain Arduino, you're not considering a wireless standard and say a phone as the UI.  I think this is wise for security reasons.  So I'm assuming you will use a keypad like the original unit had.

I'm not a hardware guy, but I'm assuming the following suggestion can be done.

  1. Pressing the first button on the keypad actually makes the connection to supply power to the MPU.  It would have to be a "long" press as the power has to keep flowing to boot the MPU, but I think Arduino's boot rather quickly.  
  2. First thing is for the MPU to activate a relay that takes over "holding" the power on.  The user will hear the click, knowing they can release the first button.  Or... if a solid state relay is used, an LED could be turned on for this notification.
  3. The user continues the safe's combination sequence and wa-la... open safe.
  4. Depower the relay and it turns itself off.
  5. Many software features can be added for free after that...
    1. Some timer releases the relay after a certain amount of time in case you change your mind about opening the safe.
    2. An attempt counter can be saved to the EEPROM and after say... 3 attempts, do some set of commands... 

Anyway... I imagine you're not opening this safe all that periodically... at least not on a minute-by-minute period.  With the power only used during an opening, this solution should make a battery last for nearly forever.  Really... the only limiting factor now becomes the battery's self-discharge rate.  

Just a thought!

VBR,

Inq

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

Hello Inq, this is exactly what I wished to do.  I wrote the code to do all I wanted, it is very simple and works fine. BUT, it consumes too much power in idle mode.... over 40mA. So even with a battery with 5500mA the battery will last less than 6 days...

I am trying now to implement a sleep mode before messing with the hardware. However, when I try to implement the sleep mode, behavior is erratic. When I try to use code I found on the net it is even worse...

I have a few hours free this afternoon, so I will try again from start.

 

Charles

 


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 
Posted by: @papymouzot

Hello Inq, this is exactly what I wished to do.  I wrote the code to do all I wanted, it is very simple and works fine. BUT, it consumes too much power in idle mode.... over 40mA. So even with a battery with 5500mA the battery will last less than 6 days...

In my suggestion above (if it can be done... some hardware guy needs to chime in) there is NO idle mode... NO sleep mode.  The Arduino is simply NOT powered on at all.  There is no battery usage!  It should last many years on an AA battery... even if you're opening the safe every day.

Posted by: @papymouzot

I am trying now to implement a sleep mode before messing with the hardware.

If you don't want a hardware solution... that is a choice.  I think the academic learning of sleep modes is very powerful, I've just not gotten to it myself yet. 😆  I'm sure you can find a sleep mode that will get you to far longer than 6 days.  According to the Arduino UNO, the sleep mode is only 30 uA.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

... but remember, the power converter itself supplying that 30 uA at 5.0 volts for the Uno is using power all the time and may be the 40 mA you quoted.  That article I posted above said he had to resort to using a better voltage converter than the on-board one.  Again... outside my expertise.  I'm just regurgitating his statements.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Papymouzot
(@papymouzot)
Member
Joined: 2 years ago
Posts: 24
Topic starter  

I have to admit that I am a bit lost after reading your statement. If the board isn't powered, how can it reply to keypresses and activate the safe solenoid to enable the opening ???

I don't really fancy adding an on/off switch on the doors' safe...  I am trying to have a solution to my faulty original safe board to be completely transparent.

If I manage to have my code working with deep sleep mode I will try using a different board like the mini pro 3.3v 8MHz with no power led and no voltage regulator, the board powered with a 3.3V LIFePO4 battery and see how much it can last on a single charge...

 


   
ReplyQuote
Page 1 / 4