Blockchain Door Lock access with a Cryptnox Card
Use Cryptnox NFT smartcard for blockchain IOT projects
Crytpnox is developing and producing hardware wallets (cold storage) in smart card format
In this article, we will explain how to use a specific version (B-NFT-1)of the card as a blockchain door lock opener. This card type was specifically designed for NFT. The principle is to provide door access to the owner of an NFT assigned to the door lock. Upon on-chain confirmation of NFT ownership of the NFT by the key on the card, the device unlocks. This project can deployed either on a Rapsberry Pi or an ESP32. Libraries are available for both.
We are using an Ethereum Virtual Machine compatible blockchain with ERC1155 smart contract. A door lock checks token balance of wallet address in cryptnox card for access.
The code of the project is published on the following repository:
GitHub - Cryptnox-IOT-Projects/Blockchain-Door-Lock-Access: Using a Cryptnox Card for door access…
Using a Cryptnox Card for door access linked to the temporary ownership of an NFT in a smart contract. The device will…
Base hardware requirements:
- A Cryptnox NFT SmartCard (Type B-NFT-1). You can purchase a Cryptnox SmartCard or on the Cryptnox Shop
- A smart card reader
- A solenoid door lock
- A 12V power supply
- A relay module
- Jumper wires
Raspberry Pi setup hardware requirements:
- A Raspberry Pi Model 4
ESP32 setup hardware requirements:
- Adafruit PN532 Breakout Board
- Logic level converter
- Buck converter ( XL6009E1 or LM2596 )
- 10uf capacitor
- Cryptnox NFT Card Manager. Can be downloaded here:
Core functionality of the use case is as follows:
- A Cryptnox NFT card is initialized and seeded.
- The user uses the card with wallet connect via Cryptnox NFT Manager and rents token from the smart contract via a website: there is an example of such a Web3 website based on the code of our repository HERE.
- Use the card to open door lock
Functionality of the door lock setup is as follows:
- Reader picks up card inserted/tapped
- Checks wallet address on card if corresponding token exists
- If Yes, door lock opens. Otherwise, door lock stays closed.
Part 1: Preparing the door lock setup with:
Jumper wires connect as follows:
Rasp Pi to Relay
- Power (red) from PIN(2) of Rasp Pi to “IN” of relay.
- Communication (blue) from PIN(12) of Rasp Pi to “VCC” of relay.
- Ground (black) from PIN(6) of Rasp Pi to “GND” of relay.
Relay to 12V power supply and solenoid door lock
- Power (red) from 12V power supply to Solenoid door lock.
- Communication (blue) from relay(COM) to solenoid door lock.
- Ground (GND) from relay(NO) to 12V power supply.
ESP 32 & Arduino Mega 2560
Esp32 to PN532 breakout board ( SPI interface )
- Esp32 ( g16 ) connects to PN532 ( SCL )
- Esp32 ( g23 ) connects to PN532 ( SDA , MOSI )
- Esp32 ( g19 ) connects to PN532 ( MISO )
- Esp32 ( g18 ) connects to PN532 ( SCK )
- 3.3V connects to 3.3V
- GND connects to GND
Connection of Esp32 , Logic Level Converter and 12V Relay
- Esp32 ( GND ) connects to Relay ( GND )
- Esp32 ( 3.3V ) connects to Logic Level Converter ( LV )
- Esp32 ( g32 ) connects to Logic Level Converter ( TX1 )
- Logic Level Converter ( TX0 ) connects to Relay ( IN )
Connection of 12V power adapter, 12V Relay and Solenoid Door lock
- Power adapter ( VCC ) connects to Relay ( COM )
- Power adapter ( VCC ) connects to 12V Relay ( VCC )
- Power adapter ( GND ) connects to Solenoid door lock ( GND )
- Relay ( NO ) connects to Solenoid door lock ( VCC )
Connection of 12V power adapter, XL6009E1 buck converter and Esp32
- Power adapter ( VCC ) connects to XL6009E1 ( IN ( + ) )
- Power adapter ( GND ) connects to XL6009E1 ( IN ( — ) )
- XL6009E1 ( OUT ( + ) ) connects to Esp32 ( 5V, Vin )
- XL6009E1 ( OUT ( — ) ) connects to Esp32 ( GND )
This one is to step down the 12V to 5V dc for Esp32 because it’s not recommended to power the Esp32 with 12V. Adjust the knob on the buck converter to reduce dc 12V to 5V. Now the whole project can run with 12V. You can also use other buck converters like LM2596.
Connection of 10uF Capacitor to Esp32 ( Optional )
- Capacitor positive pin ( anode ) to Esp32 ( EN )
- Capacitor negative pin ( cathode ) to Esp32 ( GND )
This connection is optional for auto boot. If you set up this connection, you don’t need to press the boot when uploading the program on Esp32.
And you can solder the capacitor directly to Esp32 like this if you don’t want to connect it with jumper wire.
Part 2: Initialize and seed a Cryptnox B-NFT-1 Card
Use Cryptnox NFT Card Manager.
Start application -> Scan card -> Initialize card and follow instructions.
Part 3: Rent door lock token from ERC1155 smart contract via frontend
You must setup a Web3 website such as THIS (look in repo for corresponding code).
In the “Connect wallet” options, choose “Wallet Connect”.
Click on “copy link”.
In the Cryptnox NFT Manager, choose the wallet connect tab,
paste the previously copied link then connect. Confirm signing to connect successfully.
Once the wallet is connected to the site, rent your desired token. The rent fee will be 0.001 Geth and the token has an expiry timer of 30 mins.
Part 4: Access door lock
With the setup completed, tap/insert your card on/into the reader, and observe as the door lock opens as it confirms the corresponding token exists in your wallet address.
If in case the token has expired (rented over 30 mins) , the door lock will stay closed and the token will be burnt from your address.
Demo Videos below:
Raspberry Pi Setup