Simone Romano
Published © Apache-2.0

A Blockchain-Powered Smart-Lock

Securely open/close your front door with a smart contract

IntermediateFull instructions provided2 hours5,778
A Blockchain-Powered Smart-Lock

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
DC 12V Solenoid Electromagnetic Mini Door Lock
12V Power Supply 24W with free wires adaptor
Micro USB Power Supply for Raspberry Pi Zero
16GB Micro SD Card
4 Channel DC 5V Relay Module for Arduino Raspberry Pi
Female to Female Breadboard Dupont Jumper Wires

Software apps and online services

IoTeX Blockchain


Read more


SimpleDoorLock Contract

A very basic smart contract to keep and toggle the state of the door lock.
pragma solidity ^0.5.0;

// Import the "Ownable" interface from OpenZeppelin, that implements
// the "onlyOwner" modifier we use to make sure only the contract
// owner can operate the smart-lock
import "";

 * @title Simple Smart-Lock
 * @dev Very simple smart contract to manage the state of a smart-lock
contract SimpleDoorLock is Ownable {

    // Keeps the status of the smart-lock: true = door is locked!
    bool public State;
     * For safety, let's initialize the state to false (lock is open)
    constructor () public { State = false;  }
     * Toggles the state of the door lock, 
     * only the contract owner account can call this function!
    function toggle() public onlyOwner() { State = !State; }

checkState Script

This script will periodically query the smart contract state and drive the lock accordingly

# Replace the address belowwith the address of your SimpleDoorLock 
# contract address you got from IoTeX Studio IDE

while :

echo "Polling the contract..."

STATE=$(ioctl contract test function $CONTRACT_ADDRESS abi.json State |tr -d ':'| awk '{print $2}')

echo "Contract state = " $STATE

if [ "$STATE" = "true" ];
 # Open the Lock
 echo 0 > /sys/class/gpio/gpio14/value
 # Close the Lock
 echo 1 > /sys/class/gpio/gpio14/value

# Cycle every 10 seconds
sleep 10


Simone Romano

Simone Romano

4 projects • 15 followers
Developers Community Growth @ IoTeX