Trigger multiple IFTTT events based on Moisture level.

IOT with nature, this is one of my favorite subject. Connect the Internet of things with nature. In this project, we are making moisture sensor integrated with IFTTT with multiple events triggers.
As I said multiple triggers mean, it sends a moisture level at every 30 minutes (editable mode) to google spreadsheet (Trigger 1) and if a moisture level goes below a critical level then sends me an Email (Trigger 2).
At any time, you can log in to your Google spreadsheet and check current moisture level and if you miss, then your plant will send you an email at critical condition (below certain Moisture level). In Arduino Code, you can change the email notification counter to make an email notification per day (editable mode).

Basic Feature,
1) Active Power sleep mode to reduce battery consumption.
2) Multiple IFTTT events trigger.
3) EPROM enable counter to send Email notification at 12 hours.
         A Moisture sensor updated google spreadsheet at every 30 minutes but you don’t want an email at every 30 minutes until you water back your plant. It will start filling up your Inbox. So, to avoid such issues, we have EEPROM enable counter to send an email at every 24 counts.

Moisture level at every 30-minute X 24 counters = 12 Hours,
e.g first email I will get in the morning 9AM when I’m at home and send another email at 9PM when again I’m back to home from work.  

Basics you need to know,
1) NodeMCU with Arduino IDE
2) Hardware
a.       Moisture sensor
b.       2N2222 transistor with 100E resistor.
c.       Battery  
d.       Breadboard 
 3)  IFTTT with Google drive.

To start with IFTTT,
Create a free IFTTT account.
Go the official site: and click the “Sign Up” button in top of the page.

Once you sign up…

In the top raw, select the My applets or create one.

Click on "this" to make trigger activity.
In our case we want to use a ESP-8266 with Moisture sensor.

Select maker webhooks, it will allow you to make the IOT hardware integration.
I created an event name "Moisture_sensor" written in the box. 

Do remember this name you will need this in future for the testing.
So once you read moisture data (On NodeMCU) then what…!!!

It has multiple action services, which will allow you to connect through possible services with simple selection. In our-case 
1) send Moisture_sensor on the Google spread sheet. (You need to download an app for notification service)
2) send an Email at time of critical water level condition.

In this Notification dialog, please add a message you want to see. 
Also please add ingredient call "value1", "value2",

"Value 1" stands for Moisture_sensor data  – it will come in level from 0-1024
below 100 means critical level... (defined in Code) 

It will save data on the spread sheet name of IFTTT_maker_webhooks_Event 
Compete with the action by a click "create action".

Please follow same process for Mail Trigger.

Hardware design:
Basic connection with NodeMCU.
1) Connect reset pin with D0, It will reset NodMCU after deepsleep timer.
2) Connect Moisture sensor with 2N2222 to make a transistor as switch function.  
It will disable moisture sensor when device is in sleep mode, connect base pin to D5 ( Arduino Pin number 14)
3) Analog reading connection with A0 pin, In Arduino it is A0 number.

Do not forget to add SSID, Password, Apikey and EEPROM library.

#include <ESP8266WiFi.h>
#include <EEPROM.h>

const char* ssid = "WIFI network"
const char* password = "WIFI password"
const char* host = "";
const char* apiKey = "IFTTT Key";

const int sleepTimeS = 1800; 
// If timer is set for 30 minutes (60*30), than you need to change counter number - i for Mail notification. 

volatile int flag = false;
int address = 120; // EEPROM storage address, It can be anything in-between 0-511

float Final;
int sensorPin = A0; // Your moisture sensor connection
int pin = 14;  // Enable your moisture sensor at time of requirement to reduce power consumption
int sensorValue; 
int i;

void setup() 

    Serial.println("Moisture sensor interface with IFTTT");
    i =; // Store counter to send a notification at 12 hours
    pinMode(pin, OUTPUT); 
    Serial.print("Connecting to ");
    digitalWrite(pin, HIGH); // Enable sensor with 2N2222 transistor 
    sensorValue = analogRead(sensorPin);
    Final= 1024 - sensorValue;
    flag = true;
void loop() {  


    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi connected"); 
          Serial.print("connecting to ");
          WiFiClient client;
          const int httpPort = 80;
          if (!client.connect(host, httpPort)) {
            Serial.println("connection failed");

          String url1 = "/trigger/Moisture_sensor/with/key/"; // Send a data to google spread sheet.
          url1 += apiKey;
          Serial.print("Requesting URL: "); 
          client.print(String("POST ") + url1 + " HTTP/1.1\r\n" +
                       "Host: " + host + "\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + 
                       "Content-Length: 13\r\n\r\n" + "value1=" + Final + "\r\n" );

        if (Final <= 150 && i>=24)  
//24 number is to get an Email at every 12 hours + Moisture level is below desired condition,
// if you sleep timer sends you an notification at 30mins x 24 = 12 hours. 
          String url = "/trigger/Moisture_mail/with/key/"; // to trigger Email notification at 12 hours.
          url += apiKey;
          Serial.print("Requesting URL: ");
          client.print(String("POST ") + url + " HTTP/1.1\r\n" +
                       "Host: " + host + "\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + 
                       "Content-Length: 13\r\n\r\n" + "value1=" + Final + "\r\n" );
         i = 0;
          flag = false;
          digitalWrite(pin, LOW);
        //Serial.println("New strored I");
        //  Serial.println(i);
          EEPROM.write(address, i);
    ESP.deepSleep(sleepTimeS * 1000000);  //deepsleep defination 


Tested PCBs with Code:

Google spread sheet logs,


Popular Posts