Thursday, November 30, 2023
HomeElectronicsARDULOCK: a keyboard with RFID module - Open Electronics

ARDULOCK: a keyboard with RFID module – Open Electronics


With Arduino Mega, we create, a keyboard with RFID module, a configurable entry management system, to handle electrical locks.


Available in the market there are various kinds of controls for electrical locks: from the easy insertion of codes to biometric readers, passing by way of transponder readers (RFID) or magnetic strips.

The mission that we current on this article lets you management an electrical lock through a relay or, extra typically, any electrical load that’s handed by the relay, by checking six-digit codes and studying RFID transponders.

The person-machine interface of our entry management consists, for the output half, of a 16×2 backlight LCD show and a buzzer, whereas for the enter half we discover a 16-key membrane keyboard and an RFID reader.

The administrator person of the system can have a grasp key that enables entry to the system settings, which particularly concern the likelihood to insert or take away as much as ten numeric codes enabled for entry, to affiliate or disassociate as much as ten RFID transponders, to set the time vary through which the system shall be lively and entry shall be allowed, the variety of incorrect makes an attempt after which the system will go into safety lockout and the seconds of lockout of the system ensuing from such an eventuality.

An extra configuration component permits us to set for what number of seconds the relay (which, as proposed within the wiring diagram, is situated onboard the protect) will stay lively upon the insertion of an accurate code or upon the passage of an enabled RFID transponder: this function makes attainable not solely the management of an electrical lock but in addition the management of a generic electrical load that we need to make obtainable solely to those that have the credentials to activate it (for instance a time-based lighting system, an actuator or an electrical pump).




To make the mission we want the next elements, all obtainable from Open Electronics (additionally on-line at


So to create the system we are going to merely should get the boards indicated above, which will be bought already assembled and examined, interconnect them in response to the diagram on the subsequent web page, discover them an acceptable container and program the Arduino board with the sketch that we’ll describe shortly.

Widespread male/feminine jumpers are sufficient to attach the boards collectively.

We selected to make use of an Arduino Mega 2560 board because the computing centre of our entry management as a result of, with a Flash reminiscence of 256 kB and an SRAM of 8 kB, it permits us to host the ArduLock RFID sketch (which is kind of massive) and ensures the likelihood to implement this mission sooner or later because of its 54 pins.

The lock protect integrates an RTC DS1307 that we’ll use to learn and set the date and time; this RTC has additionally a management circuit that may confirm the shortage or insufficiency of the primary energy provide (Vcc) and ensure that the voltage wanted for its operation is taken from the backup battery, in our case a CR2032 3 Volt button cell, which ensures an autonomy of about 6 months within the absence of energy provide.

At all times on the protect, we’ve a buzzer that shall be used to speak with the person by way of acoustic alerts and a relay that can management the electrical lock; subsequent to the relay, we discover the LED signalling coil excitation: very helpful within the growth section of the mission to confirm the operation of the relay (along with the basic “ticking”) with out connecting the electrical lock.

We additionally discover the eight-pin connector that can enable us to attach the membrane keyboard with 16 keys, greater than sufficient to make sure excessive safety.

The NFC/RFID module we’ve chosen is extraordinarily versatile: in truth, it measures solely 43x41x4 millimeters and is ready to talk in three modes (I²C, SPI and HSU) by setting the DIP swap on board; not solely does it help RFID studying and writing but it surely is ready to talk NFC with one other module of the identical sort or with an Android smartphone as much as a distance of about 6 centimeters.

Now let’s transfer on to the sensible implementation: after soldering all elements on the PCB of the lockshield following the directions included within the package, we place the protect on Arduino Mega by matching the pins under; now we insert the connector of the membrane keyboard on the eight pins on the protect known as “keyboard” preserving the keys going through the USB port of Arduino and insert the buffer battery for the RTC.

Utilizing jumpers and a breadboard, or with wires and a Stripboard, we derive from the protect pins 4 traces that we’ll want later to energy and join the LCD and the RFID module: 5V, GND, SDA and SCL.

Now we transfer on to the RFID module and set the DIP swap to 1-0 to allow the I²C communication; lastly, if we determined to proceed with the jumpers, we solder the four-pin headers on GND, VCC, SDA and SCL, in any other case, we go away the holes free to solder cables.




Obtain the mission code and open it with Arduino IDE: as we will see from the primary traces we want a number of libraries.

The EEPROMEx library extends the basic EEPROM administration library current by default permitting you to learn and write not solely bytes but in addition lengthy, int, float, double, array and even information buildings: it’s exactly on this approach that we’ll save and recall in reminiscence all of the settings of our mission, additionally incorporates precious controls to protect the lifetime of the reminiscence cells that’s round 100,000 write operations.

The Keypad library permits us to learn the keys pressed on the membrane keyboard whereas the RTClib library is used to handle the RTC onboard the protect.

The PN532_I2C, PN532 and NfcAdapter libraries handle the RFID module and LiquidCrystal_I2C controls the I²C communication with the LCD show.

After having downloaded and appropriately put in all of the libraries we will reopen the sketch of our mission and proceed to the configuration section of some elementary parameters earlier than importing them to Arduino:

  • MASTER_KEY: six-digit administrator code that lets you enter system settings, we advocate that you simply select it fastidiously and put it aside with out sharing it or writing it down someplace;
  • DEBUG_ON: if uncommented, this outline prompts the debug serial output (throughout regular operation we recommend leaving it commented);
  • BUZZER_ON: if unmuted, this outline prompts the buzzer sounds (usually unmuted);
  • RESET_TIME: when this worth expires in seconds with none enter (keystrokes) from the person, if we’re within the settings, the system routinely returns to the primary menu;
  • CONFIRM_KEY: setting of the affirmation key on the membrane keyboard, often this worth should not be modified.


As soon as completed configuring the sketch, join the Arduino Mega to the PC through USB cable, choose the board and the right port from the Instruments menu and proceed to load the sketch: as soon as loaded we will disconnect the Arduino from the PC.

Earlier than testing our mission, let’s analyze the primary components of the code: within the setup operate, we discover the initialization of the pins, the RTC, the RFID module and the show, lastly, we discover the initialization of the configuration (settings).

The configuration is a knowledge construction saved on EEPROM containing ten codes and ten RFIDs enabled for entry, the beginning and finish occasions of the enter, the variety of flawed makes an attempt after which the lock will lock, the seconds the lock shall be locked, and the seconds the relay should stay lively for the electrical lock to open.

Beneath we will see the struct of the configuration:

typedef struct {

lengthy Code[10];

uint32_t RFIDCode[10];

byte HHStartActive;

byte HHEndActive;

byte LockBlockAttempts;

byte LockBlockSeconds;

byte RelayActiveSeconds;

} Configuration;


Every time the system is turned on, the EEPROM cell in place 1 is checked: if this cell incorporates the worth 255 it implies that it has not been initialized, then a default configuration is created and written in EEPROM; if as a substitute the cell has a price completely different from 255 it means that there’s a configuration to be loaded in RAM and on this case the configuration construction is populated with the pre-existing information.

The loop operate incorporates two crucial capabilities: ReadKeys and ReadRFID: the primary one checks each key that has been pressed and permits, for instance, the insertion of an entry code or the configuration of some parameters (by way of ManageActions); the second checks if a transponder has been approached to the RFID module and, in response to the standing of the system, it permits to verify if the RFID is enabled (by activating the relay) or it permits to affiliate the RFID. The logic that governs the operation of the sketch is that of the state machine: usually the system is within the state 0 which is the one in every of code reception or RFID detection (through which the show reveals the present date and time), if a code is entered or an RFID is detected and the fitting situations are met (right code or RFID enabled) it goes to a subsequent state such because the activation of the relay or entry to the system configuration menu (within the case of insertion of the grasp key).


Find out how to use Ardulock

Now it’s time to check our mission: we energy the Arduino through the onboard DC jack with a voltage between 7 and 12 V DC; if the whole lot went properly, after a number of seconds the show will present the present date and time.

We advocate, no less than for the primary few occasions, to activate the debug and use the Arduino serial monitor (pace 115200) preserving the USB cable related to verify for any issues. On the first energy up the configuration in EEPROM shall be initialized with default values: which means that we is not going to have any entry code and no RFID related, the lock shall be lively from 00 to 23 (so all day), the makes an attempt to enter the code shall be three, then the lock will lock for ten seconds earlier than permitting new entry (both by code or RFID), lastly the relay will keep on for one second permitting the electrical lock to open.

We insert now the grasp key that we’ve invented earlier than loading the sketch and we press the important thing of affirmation (by default it’s #): if we’ve typed appropriately this code on the LCD show will seem the writing “SETTINGS Digit 1-11”, so we sort a quantity from 1 to 11 and we press the # key to substantiate: we repeat this operation each time we need to set one of many eleven parameters as a result of at each configuration occurred the system will exit from the settings exhibiting us once more the preliminary display screen; let’s see intimately the settings:

  • 1: lets you enter an entry code (at all times six digits), affirm with the # key, after validating the code, this shall be inserted on the backside of the listing of ten enabled codes, watch out as a result of if the listing is full, the code shall be inserted within the final obtainable place, scaling all of the codes by one place and deleting the code within the first place;
  • 2: lets you find and take away the entry code simply entered from the listing of enabled codes by coming into the place (1-11);
  • 3: the system enters in RFID affiliation mode, after having pressed a key from 1 to 10 (with out urgent #) we go an RFID transponder close to the module and this shall be inserted within the listing of the ten enabled RFID, additionally for this listing is legitimate the identical speech of the listing of the enabled codes and within the case through which it’s all full, that’s on the addition of an eleventh RFID, the primary RFID within the listing shall be eradicated;
  • 4: lets you find and take away an RFID from the listing of enabled RFIDs by coming into its location (1-11);
  • 5: lets you set the lock activation begin time (0-23);
  • 6: lets you set the lock activation finish time (0-23);
  • 7: lets you manually set the date of the RTC by inserting it within the format DDMMYYYY;
  • 8: lets you manually set the RTC time by coming into it within the HHMMSS format;
  • 9: lets you set the utmost variety of flawed makes an attempt earlier than lockout (0-20, 0 means lockout management is off);
  • 10: lets you set the lock seconds if the lock is lively (1-120);
  • 11: lets you set the activation seconds of the relay.



After customizing the system by coming into some codes and associating the RFID transponders included within the package deal of the NFC/RFID reader, we will take a look at the activation of the relay: we insert one of many enabled codes and confirm that the relay is activated for the preset seconds and that the LCD show reveals “CODE OK Lock open”; we additionally attempt to insert some flawed codes to check the lock mechanism and the ensuing unlocking after a number of seconds of ready (through the lock an X will seem on the show subsequent to the time). Let’s set a lock activation time vary that doesn’t embrace our present time: even when we insert enabled codes or related RFID, the system will forestall entry.


A little bit of hacking

We now implement the system by including a MicroSD module: it will serve to pour all debug messages, which we see in serial, right into a textual content file that we will learn sometimes to regulate all of the actions carried out by customers of ArduLock RFID. Let’s get the MicroSD storage board (obtainable on this board, 37x23x6mm in dimension and powered at 3.3 volts DC, has SDIO and SPI connectivity (we’ll use SPI); let’s join the three.3V and GND pins to their respective pins on the Arduino, then, since we’re working with Arduino Mega, we should join the MISO pin to Arduino pin 50, the MOSI pin to 51, the SCLK pin to 52 and the CS pin to 53.

As soon as completed with the connections we get a MicroSD card and insert it into the module able to obtain the log file.

Now open the sketch with Arduino IDE and make adjustments to implement this function, as the very first thing we embrace is the SPI and SD libraries, create a outline PIN_SD_CS that we set to 53, declare a bool variable SDInitialized that we might want to perceive later if we even have an SD module with MicroSD inserted, then we transfer to the start of the setup operate and insert the next traces of code to initialize the module:



digitalWrite(PIN_SD_CS, HIGH);

if (!SD.start(PIN_SD_CS)) {

SDInitialized = false;

WriteLog(“Error: no SD card”);

} else {

SDInitialized = true;

WriteLog(“SD card initialized.”);




After coming into the initialization of the SD module let’s transfer to the WriteLog operate that we’ll discover on the backside of the code and insert the next if that enables us to jot down the log line on a file named “log.txt”:


if(SDInitialized) {

File LogFile =“log.txt”, FILE_WRITE);

if(LogFile) {






We compile and cargo the code on Arduino, attempt to perform some operations, then extract the MicroSD card from the module and browse the log.txt file by inserting it right into a PC.



We entered the code 112233 (already current within the enabled code listing) and the lock opened, then we approached a non-enabled transponder to the RFID reader: in truth, it returned the error “Invalid RFID”; after that, we entered the settings by typing the grasp key and we chosen choice 3 that corresponds to the affiliation of a brand new RFID.

After urgent the two keys (with out urgent #) we approached the transponder to the reader and the system confirmed the affiliation in place 2 of the listing; lastly, we tried to strategy the transponder once more and this time the lock opened as a result of the RFID was acknowledged as enabled.



At this level, we go away to your creativeness attainable expansions of the mission, however offering some concepts: since we’ve an RTC, the log file might be created firstly of every day with a reputation like “YYYYY-MM-DD_log. txt” to permit a quicker session of the logs as a substitute of getting to scroll a single log file that data the actions of all days; you might then implement a further management that scrolls and counts all of the free clusters of the SD reminiscence and warns, through the LCD show, that the MicroSD deputed to the recording of the system log is working out of area.

One other implementation is to maneuver the storage of the configuration construction from the EEPROM to the information on the MicroSD; on this approach, will probably be attainable to develop the lists of enabled codes and RFIDs by making a file for every information to be saved or a single JSON file that incorporates the entire configuration construction (on this regard, a really attention-grabbing library is ArduinoJson).




Defend code activator OTP – to mount

Show LCD 16×2 with I²C interface

Membrane Keypad 4×4

NFC / RFID reader

Micro SD Storage Board



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments