alranel
Published © CC BY

How to open a door from your smartphone

In this project you'll learn how to use a Shelly relay and the Arduino IoT Remote mobile app to open a door from a smartphone

BeginnerFull instructions provided6,440
How to open a door from your smartphone

Things used in this project

Hardware components

Shelly 1
×1
USB-TTL serial adapter
I used the one by DSD-TECH, easily available. Any other option will work but make sure it works at 3.3V and it's advertised to be compatible with esp8266 or esp32 devices.
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin
Not strictly necessary, but it simplifies wiring a bit while programming the board.
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long
Make sure you have a few jumper wires to program the board.

Story

Read more

Schematics

Wiring (only for programming)

Code

Arduino sketch for Shelly 1

Arduino
Copy and paste this code in the web interface of the IoT Cloud.
#include "thingProperties.h"
#include <TOTP.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

// OTP configuration
uint8_t hmacKey[] = {0x2, 0x63};
constexpr int keySize = 2;

TOTP totp = TOTP(hmacKey, keySize);
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "time.ien.it");

constexpr int SHELLY_RELAY = 4;

void setup() {
  // Connect to Arduino IoT Cloud
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  // Initialize variables and pins
  access_code = "";
  pinMode(SHELLY_RELAY, OUTPUT);
  digitalWrite(SHELLY_RELAY, LOW);
}

void loop() {
  ArduinoCloud.update();
}

// Handle incoming messages
void onAccessCodeChange()  {
  if (access_code == "") return;
  
  timeClient.update();
  unsigned long now = timeClient.getEpochTime();
  String correct_code = totp.getCode(now);

  if (access_code == correct_code) {
    digitalWrite(SHELLY_RELAY, HIGH);
    delay(700);
    digitalWrite(SHELLY_RELAY, LOW);
    access_code = "Door open!";
  } else {
    access_code = "Invalid code";
  }
}

Credits

alranel

alranel

1 project • 12 followers

Comments