Digi-Key IoT Studio Web and Mobile Applications have been discontinued by Digi-Key. The links and instructions in this guide may be outdated or invalid. For support and more information about the future of the Digi-Key IoT Studio application, please visit https://forum.digikey.com/t/dk-iot-studio-has-migrated/8463

While monitoring your home's temperature is useful, your home will not be able to respond to changes in temperature. While you could open a window (or remove the roof) to air it out, it'd be useful to control the fan inside your home to regulate temperature.

You'll be building code to self-regulate the temperature inside the home to your preferred temperature. 

Step-by-Step: Embedded Workspace

This section builds on the previous section, Monitoring your Home. You'll be adding a comparison element to evaluate the temperature and a GPIO element to control the relay's state.

The ADI FeatherWing reads the temperature as a floating point value. At the time of writing, Digi-Key IoT Studio is unable to use floating point values with comparison elements. To resolve this, convert the floating point value into an integer value.

  • From the Embedded Workspace's Element Toolbox, click the Type Conversion element.
  • Click the DataTypeConvert Element to open its properties.
  • In the Type Conversion Element's properties, change the output type to Integer

 

Add a new connector between the ADT7410FeatherWing Element and the DataTypeConvert element. 

With the temperature reading converted to an integer, it's time to add some logito our embedded firmware.

  • From the Embedded Workspace's Element Toolbox, click the Comparison element.
  • Change the Comparison Element's condition to Greater Than
  • Change the Target Value to the maximum temperature value.
    • If the temperature sensor reads a value greater than the Target Value, the relay will switch and turn on the motor.

Add a new connector between the DataTypeConvert Element and the EmbeddedComparison Element.

Next, you need to add a GPIO element to control the relay. The relay is connected to GPIO Pin 33 on the ESP32 Huzzah.

  • From the Embedded Workspace's Element Toolbox, click the GPIO Pin element.
  • From the GPIOPin Element's properties, change the Name to GPIOPin33
  • Change the GPIO Pin to IO33

You'll turn on the relay when the Comparison Element evaluates that the expression is True.

  • Click the EmbeddedComparsion Element to open its properties
  • Under Triggers, ensure the trigger is set to Condition True.
  • Add a connector between the EmbeddedComparison Element and GPIOPin33

To turn on the relay if the Target Value is reached,

  • Click the connector between the comparison element and the GPIO pin.
  • Change the GPIO Pin's Ability to Set Pin High

Our IoT Home turns on the fan when the temperature increases past a target value, but what if it the home cooled off? You'll need to turn off the relay.

  • Click the EmbeddedComparsion element to open its properties.
  • Switch Condition True to Condition False
  • Add a connector between the EmbeddedComparison Element and the GPIO Pin Element.
  • Change the GPIO Pin's ability to Set Pin Low

 

Your "code" for the ADT7410 temperature sensor should look like the following...

Code Usage

Compile the project. Then, upload the project to the Feather HUZZAH32.

  • Open the DK IoT Studio Mobile App on your device.
  • Tap the Devices tab on the sidebar
  • Add a new device to the devices page by tapping the + icon
  • Your IoT Home should appear as a device in range. Tap the IoT Home Project.
  • On the Configure WiFi Settings screen, tap CANCEL

Once connected, the application view will display the temperature sensor's value. Try holding your finger over the ADT7410 (or use a hair-dryer outside to the IoT Home) turn on the fan. 

The fan will turn off after the temperature decreases below its target value.

This guide was first published on Dec 11, 2019. It was last updated on Dec 11, 2019.
This page (Keeping it Cool) was last updated on Oct 21, 2020.