element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet & Tria Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Blog Make Basement Smart and Secured Again!
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vasekj
  • Date Created: 19 Apr 2020 5:59 PM Date Created
  • Views 1544 views
  • Likes 6 likes
  • Comments 5 comments
  • telegram
  • azure
  • basement
  • azurespherehomehacks
  • bot
  • sphere
  • homewhackdch
Related
Recommended

Make Basement Smart and Secured Again!

vasekj
vasekj
19 Apr 2020

Story

 

Introduction

This project is supposed to make my basement smarter and secured - because somebody stole my stuff in the past. So main feature will be when somebody will intrude my basement, I recieve a notification. Also I need to arm alarm (if I forget to do it during leaving the basement) and disarm remotely (to prevent false-alarm notifications when I enter the basement).

Idea how this security-alarm should work it's pretty simple - on device are a lot of sensors capable to detect somebody's presence: ambient light (when thief use flashlight or turn on the light), microphone (nobody is so silent to be not-detected). And when I mount the device on door, it can also detect movement of doors (thanks to angular rate+acceleration sensor on board).

So if at least one sensor detects important change (higher than some threshold), device starts alarm - it sends notification to my phone via Telegram Bot.

 

Remote control + alarm notifications via Telegram

Fullscreen 6560.contentimage_138209.html Download
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
image

 

Solution Design

Architecture

Sphere SDK provides simple APIs to Microsoft Azure services. Device communicates with IoT Hub (which cares about device management) and message routing (bi-directional - cloud-to-device & device-to-cloud).

 

SmartBasement architecture overview

 

SmartBasement project architecture

 

Azure Bot Services is kind of WebApp - which provides all needed integrations and webhooks needed by Telegram's API. This part allows to communicate from phone to device (via IoT Hub), but not the other way.

That's why I have in solution also Azure Function service, which provides native IoTHubTrigger (when is new message in IoT Hub detected, it will call your code) - this will cover also a scenario "send notification when breach".

Important advantage of this solution (with my current needs) is cost - it costs $0 per month, because all used services run on Free tier.

 

BoM

 

  • Avnet Azure Sphere MT3620 Starter Kit
  • Mikroe Mic Click (link)
  • 300KΩ resistor

 

 

  • 3D printer (for case)

 

SW:

  • Azure IoT Hub
  • Azure Functions
  • Azure Bot Services
  • Telegram API

My Start With Azure Sphere MT3620


I usually work with high-level programming languages, so I had little cold start, with this project - and for rest of developers like me, I would like to mention really important fact, there are more variants of this board. If you will search for help or read some documentation, make sure, than you have same board as author - because there is a big difference between Development Kit and Starter Kit (totally different adresses of GPIOs,...) - thats why I included also the folder device-app/Hardware with boards definitions in source code of this project.

My whole project is prepared for Starter Kit, but with few changes you can launch it also on Development Kit.


Peripherals (Sensors, Button, LED)

 

Azure Sphere MT3620 Starter Kit board

Azure Sphere MT3620 Starter Kit board


On-board Ambient light sensor - is connected via ADC, and on Starter Kit is directly connected to ADC0 (diagram).

Microphone - I used MikroE's Mic Click module for MikroBUS. MikroBUS allows you to connect module without wiring anything, you just click module into socket on board. Starter Kit has two sockets, Click #1 (socket #1) is connected to ADC1, Click #2 to ADC2. To protect your board, you have to do small wiring - because of Mic Click module has reference output voltage up to 3.3V, board is designed for maximum input voltage only 2.5V. You need to add 300KΩ resistor between module and board.

 

Mic click (MikroBUS socket)

Mic click (MikroBUS socket)

On-board accelerometer+ gyroscope sensors - are connected via digital I2C interface, on ISU2 port.

UserLED - is connected via GPIO ports. For every color (RGB) there is GPIO port - ports GPIO8, GPIO9 and GPIO10, so you can mix them.

In this project I am using user LED for indicate device status:

- permanent blue=armed- blinking blue=waiting 10 seconds to arm- permanent red=something went wrong

In the code you can easily control user LED via method:

void setNewLEDStateRGB(bool isRedOn, bool isGreenOn, bool isBlueOn);

 

image

 

Button A - is also connected via GPIO port, on port GPIO12. In this project is used for arming alarm manually (when you click this button, device will wait 10 seconds and arm alarm - to give you time to leave the basement).

Source Code

 

All project source codes (+3D model for case) are available on my GitHub.

 

Please read README file in repository root folder, it will guide you step by step, how to deploy whole project.

In repository are two main folders:

device-app - application for Sphere device (Visual Studio solution)cloud-backend - two separated Visual Studio solutions (Azure Functions app + Bot Service Web App)

 

Device app description

The app needs to be deployed into device. For debugging and deployment you need to have installed Azure Sphere SDK (I recommend at least version 19.09, because older doesn't fully support ADC controller).

As first you need to set up app_manifest.json, which defines application settings&permissions:

{
"SchemaVersion": 1,
"Name": "AzureSphereSecuredBasement",
"ComponentId": "685f13af-25a5-40b2-8dd8-8cbc253ecbd8",
"EntryPoint": "/bin/app",
"CmdArgs": [ "--SCOPE-ID--" ],
"Capabilities": {
    "Adc": [ "$AVNET_MT3620_SK_ADC_CONTROLLER0" ],
    "AllowedConnections": [
       "--YOUR-IOT-HUB-URL--",
       "global.azure-devices-provisioning.net"
    ],
    "DeviceAuthentication": "--DEVICE-AUTHENTICATION--",
    "Gpio": [ "$AVNET_MT3620_SK_USER_LED_RED", "$AVNET_MT3620_SK_USER_LED_GREEN", "$AVNET_MT3620_SK_USER_LED_BLUE", "$AVNET_MT3620_SK_USER_BUTTON_A", "$AVNET_MT3620_SK_GPIO34" ],
    "I2cMaster": [ "$AVNET_MT3620_SK_ISU2_I2C" ],
    "SpiMaster": [],
    "WifiConfig": true
    }
}

In project is located file app_manifest.json.template, which you can rename to app_manifest.json and fill missing variables only.

For every peripheral type is in project separated helper file f.ex. i2c_helper.c,button_helper.c,adc_helper.c etc. and main.c file, which contains functions init peripherals, infinity loop and the core function GetAndProcessDataFromSensors, which reads and evaluate data from sensors.

 

Synchronization between IoT Hub and device is solved by Azure IoT Hub SDK - so you have to initializate the SDK, register you callback functions and give command to IoT Hub SDK to start sync by:

// register callback function - call function ReceiveMessageCallback, when is a new message for this device (in IoT Hub) detected
IoTHubDeviceClient_LL_SetMessageCallback(iothubClientHandle, ReceiveMessageCallback, NULL);

// start IoT Hub to sync
IoTHubDeviceClient_LL_DoWork(iothubClientHandle);

 

Breach detect algorithm is simple - it stores previous values (in variable g_previous_state), and if difference between previous value and new value is greater than defined threshold (in build_options.h), breach is detected.

For combined-value calculation from multiple axis (X, Y, Z) from accelerometer and gyroscope, is there used Pythagorean theorem.

 

Cloud backend

This part of project is really easy and straightforward - liitle bit complicated is only to set up resources in Azure (IoT Hub with DPS), but Microsoft has nice manual for that to follow step-by-step.

Please keep in mind, that threshold values are defined on side of device, but also in Azure Function ReactToMessageInIoTHub. So if you want to change them, please do it in both files.

Mounting To Doors (3D Printed Case)

I prepared mount case to be printed on 3D printer - it has space for microUSB connector + powerbank can be put on the top. Because the doors are moving, I also added top piece to secure device from falling-down from case (there is space from top, because we don't want cover the microphone chip).

image

 

 

Instruction for assembly - glue middle component with right one (biggest one) together - on the middle component use the stronger edge and on the right component use back top edge (hole for USB should be on right bottom). After inserting the board inside, glue with smallest part on the top (be sure you not cover sensors on MikroE board).

 

 

Testing

I mounted device on doors with powerbank (powerbank is secured against falling down by 3M sticker).

 

Smart Basement deployed with powerbank (secured by 3M)

 

Smart Basement deployed with powerbank (secured by 3M)

Demo (Video)

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

demo - alarm is armed (permanent blue LED) and door opening is detected and notification sent

 

Conclusion

 

Thanks to this project, you can secure your basement for no monthly fee, just thanks to basic Start Kit board + one Mic Click module.

For future, I would like to extend project by other important thing in house basement: humidity. I am planning to use other click slot for humidity sensor and report humidity status in basement to IoT Hub periodically and notify, if there is needed air exchange in basement.

  • Sign in to reply

Top Comments

  • vasekj
    vasekj over 5 years ago in reply to kevinkeryk +1
    Hello Kevin, thanks for questions! My basic idea was "I don't want to pay to subscribe securing as service" for home", so I liked the way to spend more time at the beginning of DIY project with advantage…
  • dubbie
    dubbie over 5 years ago +1
    A nice project. I liked the 3D printed case - it looks very smart. You should add a camera so it sends a picture of who is entering the basement. Maybe also put a big lock on the door as well. Dubbie
  • bwilless
    bwilless over 5 years ago +1
    Nice project, I would love to see some details on the cloud side. I keep looking for a good excuse to learn about Azure Functions, but have not had time to make it happen yet!
  • vasekj
    vasekj over 5 years ago in reply to bwilless

    Thanks!

    If you are interested about Azure Functions, on github you can find guide how to set up whole backend:

    https://github.com/vjirovsky/azure-sphere-smart-basement

     

    and here you can find backend in Azure Functions - it's really easy!

    https://github.com/vjirovsky/azure-sphere-smart-basement/tree/master/cloud-backend

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bwilless
    bwilless over 5 years ago

    Nice project,

     

    I would love to see some details on the cloud side.  I keep looking for a good excuse to learn about Azure Functions, but have not had time to make it happen yet!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 5 years ago

    A nice project. I liked the 3D printed case - it looks very smart. You should add a camera so it sends a picture of who is entering the basement.  Maybe also put a big lock on the door as well.

     

    Dubbie

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vasekj
    vasekj over 5 years ago in reply to kevinkeryk

    Hello Kevin,

    thanks for questions! My basic idea was "I don't want to pay to subscribe securing as service" for home", so I liked the way to spend more time at the beginning of DIY project with advantage there will be no monthly fee - I think it was worth it (resources was only board, microphone module) + I achieved a experience with 3D modelling software.

     

    About turning it into real product for others, few of my friends asked me to deploy the solution also for them - there is only limitation I need to solve before - extend battery life/power supply (because powerbank is not best fit for this purpose).

     

    Best,

    Vaclav

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kevinkeryk
    kevinkeryk over 5 years ago

    Nice writeup vasekj, I like that you used a secured MCU to secure your room!

     

    Was it worth your investment in terms of time and resources to achieve this $0 per month security solution?  Any plans to turn this into a real product for others to use?

     

    Best Regards,

     

    -Kevin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube