The Azure Powered AI Freezer Monitor is a maker hardware based IoT monitor that uses machine learning, or ML, to provide early warnings of potential equipment failure. This guide covers building the device, collecting training data, setting up email alerts, training a custom auto encoder machine learning model, and deploying the model to an ESP32 development board.
The project is designed to be functional for low temperature scientific freezers (-60 C), with the goal of reducing catastrophic failure and the need to keep backup freezers running full-time. However, please note that this project is primarily for demonstrative and educational purposes and has not gone through extensive testing.
This project takes about one hour to fully complete.
- An active Azure account. If you don't have one, you can sign up for a free account.
- VS Code with the Arduino extension installed
- Hardware specified below (if you'd like to use a different device refer to the message specifications)
Materials | Description | Vendor |
---|---|---|
Adafruit Feather Huzzah32 (a) | WiFi enabled ESP32 based prototyping board | Adafruit |
Adafruit MCP9600 (b) | I2C Thermocouple amplifier | Adafruit |
Adafruit Type K Thermocouple (c) | 2 wire thermocouple effective temperature ranger -200c to 800c +/-2c | Adafruit |
Jumper Wires (d) | Adafruit | |
Breadboard (e) | Adafruit | |
Micro USB cable | Used to power the ESP32 board | Adafruit |
USB Power Supply | Adafruit | |
Tools | ||
00 Philips Head Screw Driver | ||
Soldering Iron |
There are details below about the cost and architecture of this sample, but if you just want to get it running right away here are the steps to get started.
- Log in to your Azure account
- Click the Deploy to Azure button above to provision all the resources for this project
As an alternative you can deploy the template by using the Deploy Custom Template service in the Azure portal, and selecting Build your own template in the editor and uploading the azuredeploy.json file from this repo.
- Create a new resource group for the project
- Select a region for the your resources, choose one that near you for the best performance
Note: Some resources aren't available in all regions.
- Provide names for all the resources
-
Once your deployment is complete use the left navigation to open you new functions app
-
Select Functions from the left navigation
-
Select Add in the top left
-
Select the following options in the window:
Development environment: Develop in portal
Template: Timer trigger
New Function: dataSaver
you can leave any other settings as they are
-
Once the function is created select Code + Test from the left navigation.
-
In run.csx, replace all the existing code with the code from here
-
Navigate to function.json and replace all the existing code there with the code form here
-
Repeat these steps for the anomaly detector function using the options below:
Development environment: Develop in portal
Template: IoT Hub (Event Hub)
New Function: anomalyDetector
you can leave any other settings as they are
- Once the deployment is complete use the left navigation to open the newly created Logic App
- Select Logic app designer from the left navigation
- Select + New step
- Search for the email client you'd like to use (Office 365 Outlook, Gmail, and Outlook.com)
- Select the Send an email action
Note: This will be a little different depending on which email client you use
- Log in with your email account
- Customize your message, this email will be sent any time an anomaly is detected.
- Next you'll need to get the connection string for you device, navigate to the IoT Hub you created earlier
- In the left navigation select IoT devices
- At the top left of the page select + New
- Give the device an ID
- Press Save at the bottom of the screen
- Select the device you created
- Copy the Primary Connection String you'll use this string in the next section
-
Solder the pins to the bottom side of the MCP9600.
Tip: Put the pins in the breadboard to hold them in place when soldering.
-
Insert the ESP32 and thermocouple amplifier into the breadboard.
-
Follow the wiring diagram below to connect the thermocouple amplifier to the ESP32 using your jumper wires.
-
Connect the Thermocouple to the screw terminals on the MCP9600
The picture below use a generic ESP32 Dev board, new picture with the Adafruit Huzzah32 coming soon!
-
If you haven't already, clone this repo to your computer
-
Open the AiFreezer folder with VS Code
-
Create a new file in this folder and name it config.h
-
Paste the code below in config.h
const char* ssid = "<YOUR-NETWORK-NAME>"; const char* password = "<YOUR-WIFI-PASSWORD>"; static const char* connectionString = "<YOUR-CONNECTION-STRING>";
-
Fill in your network credentials
-
Paste the connection string from IoT Hub
-
Follow the first section of this guide to add the ESP32 extension to the Arduino IDE.
-
Install the library listed below using Arduino's Library manager. If you have used the library manager before here is a helpful guide.
- Adafruit MCP9600
Note: If you're prompted to install other dependencies for these libraries, select Install All
-
With FreezerTempAlert.ino open in the VS Code open the command palette (CTL+SHIFT+P) and type in Arduino: Change Board Type then search Adafruit ESP32 Feather
-
Next select the the active serial port, open the command palette and type in Arduino: Select Serial Port
-
Finally upload your code to your Feather board, open the command palette and type in Arduino: Upload
While an Azure account is free, using resources will incur a cost. Some of the resources offer a free version, we've compiled an estimate costs to run this project per month. If your account is new you should receive a $200 credit which should cover about five and a half years of these services.
Resource | Free Tier | Cost |
---|---|---|
IoT Hub | Yes | $0 |
Azure Functions | Yes | $0 |
Azure Table Storage | No | $1 |
Anomaly detection cognitive service | Yes | $0 |
Logic Apps | No | $1 |
Total | ~$2 |
It's a good idea to also set up a budget for resource group (don't worry if you don't know what all these terms mean yet, we'll explain everything as we go). An Azure budget will send you email warning you that you've reached the amount specified. It won't turn off your services, so you will still have to log in and turn off any service you no longer want to be charged for. We've included a budget set at $5/mo as part of the Azure template, but if you want to learn more about costs on Azure, here is a good starting place.
Resources are what tools and services on Azure are called. You'll use a variety of resources for this project. Some of them for compute, some for storage, others are hubs that act as connectors. Below is a list of the resources used in this project and links to where you can learn more about them.
Resource | Description |
---|---|
IoT Hub | Managed service for bidirectional communication between IoT devices and Azure |
Azure Functions | Event-driven serverless compute platform |
Azure Table Storage | NoSQL key-value store |
Anomaly detection cognitive service | An AI service that helps you foresee problems before they occur |
Logic Apps | No code platform for integration solutions |
The message sent from your device should be a JSON formatted string and needs to include a device id as a string and the temperature reading as a float. You should send exactly 1 data point per minute.
{"deviceId":"ESP32_device", "temperature": 25.235}
The anomaly detection service expected message to be evenly timed. Using a delay or an internal counter on the device is not sufficient, we recommend using an NTP server to synchronize the time the messages are sent.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.