Main Content

Warn Dry Soil Moisture with Notification from IFTTT Using Arduino Based Smart Watering System

This example shows how to use the WiFi® HTTP Client block from the Simulink® Support Package for Arduino® Hardware to trigger a request to IFTTT once the moisture in the soil drops below a set threshold value and send a notification to an Android device.

IFTTT (if this then that) is an external web service that lets you create applets and act in response to a trigger action. You can configure the IFTTT Webhook service to create web requests to trigger an action.

This example is an expansion to the Arduino Based Smart Watering of Plants example where, the moisture level of the soil acts as an incoming action to trigger an HTTP request to the web server. Only when the moisture level of the soil falls below the set threshold value, you will receive a notification on your Android device.

Prerequisites

Supported Arduino Hardware

  • Arduino MKR 1000

  • Arduino MKR WiFi 1010

  • Arduino Nano 33 IoT

  • Arduino Boards with WiFi shield

  • ESP32-WROOM (Arduino Compatible)

  • ESP32-WROVER (Arduino Compatible)

Required Hardware

  • This example uses the Arduino compatible ESP32-WROOM board. You can use any of Arduino boards from the list of supported boards. Refer to the Required Hardware section of the Arduino Based Smart Watering of Plants for a detailed list.

  • Android device, such as a phone or tablet

Create IFTTT Applet

1. Create an IFTTT account if you do not already have one. Log in to your account.

2. Create an applet. Select your user icon and then click Create.

3. Select the input action. Click the word this.

4. Select the Webhooks service. Enter Webhooks in the search field. Select the Webhooks card. After you select Webhooks as the trigger, click the Receive a web request card to continue.

5. Complete the trigger fields. Enter an event name. This example uses soil is dry as the event name. Click Create Trigger.

6. Select the resulting action. Click the word that. The trigger word this is now the Webhooks icon.

7. Enter notification in the search bar and click the Notifications box. Then select Send a notification from the IFTTT app.

8. Click Create action to finish the new applet. For this example, the name of the event is soil is dry. IFTTT will pass this name of the event where the variable {{EventName}} occurs in the message. You can also pass data about the event that triggered your message using ingredients. For example, including {{OccurredAt}} adds the event time to your notification.

9. Retrieve your Webhooks trigger information. Select My Applets > Services, and search for Webhooks. Select Webhooks, and then click Documentation. You see your key and the format for sending a request. Enter the event name. The event name for this example is soil is dry.

https://maker.ifttt.com/trigger/{event}/with/key/XXXXXXXXXXXXXXXXXXXXXX
https://maker.ifttt.com/trigger/people_detect/with/key/XXXXXXXXXXXXXXXXXXXXXX

You can test the service using the test button or by pasting the URL into your browser. Note that the IFTTT event trigger is not always instantaneous.

Configure Simulink Model and Calibrate Parameters

This example uses a preconfigured Simulink model from the Simulink Support Package for Arduino Hardware. To open the Simulink model, run this command in the MATLAB® Command Window.

open_system('arduino_push_notifications')

This model is an expansion to the model used in the Arduino Based Smart Watering of Plants example.

You can set the threshold for the soil moisture level using the dry soil moisture knob or double-click the Constant block to enter the threshold value. Configure a ThingSpeak Read block to read the soil moisture threshold values stored in the ThingSpeak channel. This threshold value is stored in the field 4 of the ThingSpeak channel. For more information, see the Task 3 - Create ThingSpeak Channel and Task 4 - Add and Configure ThingSpeak Blocks to Simulink Model sections in the Arduino Based Smart Watering of Plants example.

Double-click the Dry soil Warning subsystem. Configure the event name and API key from the IFTTT applet as input parameters to the Compose block. Every time a soil moisture level drops below the set threshold value in the Simulink model, the Dry soil warning subsystem is enabled. The WiFi HTTP Client triggers the HTTP request to IFTTT and sends a notification to your Android device.

In the Configuration Parameters dialog box, update the WiFi properties and ESP32 board properties.

Deploy Simulink Model on Arduino Board

On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start. You will receive a notification on your Android device once the moisture level of the soil falls below the set threshold value that you have set in the Simulink model.

See Also

Read and Write to ThingSpeak Channel Using Arduino WiFi HTTP Client Block