A Crypto-Powered Alarm You Can’t Snooze!

If this looks like your typical alarm app screen, then you need some help waking up!

reactions

The maker community never ran out of alternative hardware solutions for our daily struggles that are fun, tweakable and of a challenging nature.

reactions

Some tried to wake up like this:

reactions

However, research in the dynamics of sleep and the science behind “how to wake up to your alarm” can be dedicated to replicating the crypto-powered alarm clock that will force you to wake up or you will end up losing a fortune :D. It can also be a good intro to tinker with Ethereum and get your hands dirty with some hardware and blockchain concepts.

reactions

The alarm uses the Elk blockchain development board and a sound sensor. It’s sound activated, which means you can use it right away with any of your personal alarms, without too much hassle or a lot of tweaks. When the sound sensor detects the ringing of your alarm, it starts counting within a trial of time (That you set in your code), in this trial you have to get up and shut it down by a hardware action of your choice or simply pressing a button.

reactions

What happens is, initially an amount of Ether is locked in a smart contract every time the alarm fires. the smart contract is controlled only depending on the state of your hardware. Whether you’ve managed to fulfill the hardware action within the trial’s time frame or failed to; the board keeps counting down. If you did it before the trial ends, then you don’t lose the designated Ether you locked from your account and it’s withdrawn back to your account. If not, then you lose it entirely and it’s sent to any charity address of your choice.

reactions

The smart contract functions used are :

reactions

Link to code snippet: https://pastebin.com/R585FCsp

reactions

Typical Arduino C was used for the rest of the logic for the alarm on Platform.io IDE which supports the Elk SDK. The sound sensor is associated with an interrupt pin, and once it signals for sound detection (LOW signal from the sensor ), the interrupt occurs and starts the millis() counter for the trial and locks your money in the smart contract using

reactions

function lockMyMoney(address _alarmAddress) public payable{

userComittedMoney[msg.sender] = msg.value;

alarmAddress[msg.sender] = _alarmAddress;

If you push the button to silence the alarm, another interrupt occurs and sets the Win flag to true and withdraws your money back

reactions

function withdrawMoney(address _alarmAddress) public {

require(alarmAddress[msg.sender] == _alarmAddress && userComittedMoney[msg.sender]>0);

msg.sender.transfer(userComittedMoney[msg.sender]);

If you lose, the money goes to the predefined charity address

reactions

function spend(address _alarmAddress, uint _amount) public{

require(userComittedMoney[msg.sender] >= _amount && alarmAddress[msg.sender]== _alarmAddress);

charityAddress.transfer(_amount);

userComittedMoney[msg.sender]-=_amount;

The code where the actions are handled would be as follows.

reactions

ContractMethodParam param1("AlarmAddress"); ContractMethodParam param2(AMOUNT_OF_MONEY_IN_GWEI);

void loop(){

if(win) //winning condition

{

win = false;

Ethereum.sendContractMethodCallTransaction("m/44'/60'/0'/0/0",CONTRACT_ADDRESS,AMOUNT_OF_MONEY_IN_GWEI,50000,20,"withdrawMoney(address)",¶m1);

display.clearDisplay();

display.fillScreen(BLACK);

display.setCursor(37,7);

display.println(“WINNER!”);

display.setCursor(20,30);

display.println(“You’ve Earned”);

display.setCursor(20,40);

display.println(“0.016 ETH”);

display.display();

for(int i = 0; i<=3 ; i++)

analogWrite(LedPin, 90);

delay(500);

analogWrite(LedPin, 0);

delay(500);

}

if (!win && millis()-timer >= trial ) //losing condition

{

//You LOSING money!

Ethereum.sendContractMethodCallTransaction("m/44'/60'/0'/0/0",CONTRACT_ADDRESS,AMOUNT_OF_MONEY_IN_GWEI,50000,20,"spend(address,uint)",¶m1,¶m2);

display.clearDisplay();

display.fillScreen(BLACK);

display.setCursor(35,7);

display.println(“SLEEPY HEAD!”);

display.setCursor(33,30);

display.println(“You’ve lost”);

display.setCursor(33,40);

display.println(“0.016 ETH”);

delay(3000);

display.clearDisplay();

display.fillScreen(BLACK);

display.display();

}

And finally, a simple and sleek enclosure was made on Fusion 360 to encompass all the components in a presentable form.

reactions

This alarm leaves you no option but to either wake up on time or be a generous person, and in both cases, you’ve done something good whether for yourself or for the world.

reactions

Building blockchain-connected devices is made simple with Elk. Elk will be on Kickstarter soon, to get your hands on one once it’s out, sign up here.

reactions

Tags