Hey People,

Although there are plenty of Instructables out there on using the ESP8266 module, I couldn't find one specific to loading data to the free IFTTT (If This Then That) platform so I thought i'd share my project in case it helps anyone out there.

The project basically demonstrates sending a message to my phone if a change is detected in a couple of door sensors. At present the project is only in the testing phase but it should give you an understanding on connecting it up ready for installation. The project is designed for my shed so i didn't want any wires between the house and the location of the sensors. The ESP handles the interaction between wireless communications and up to 3 sensors attached directly to it. You will need to create a free account on IFTT.com and also connect to the maker channel from within IFTTT. You can download the IFTTT app onto an Iphone or an android device.

You will also need Arduino installed on your computer and we will be using the ESP8266 libraries.

This project will use the ESP-12-E module bought for around 2 Euros.

Other parts needed for this project:

USB -> Serial adapter Any adapter should do (Mine is an FDTI 230X chip)

LM1117 3.3v LDO Regulator or similar

2 x 10uF capacitors (for the regulator)

A tactile switch (not essential but makes resetting the module easier)


~ 300 ohm resistor

Breadboard and jumpers

Step 1: Setting Up the Components

I started by soldering short wires to the IO's on the ESP module, although they are not all needed for this project, it is useful to connect them all for testing and further development.

Once the wires are soldered, position them into the breadboard as shown.

I also sketched the IO pins onto a scrap of paper to make wiring easier once positioned as the GPIO's are all labeled on the underside of the board.

For this demonstration you will need to make the following connections:

GND -> Common GND

VCC -> 3.3v output of the regulator

EN -> 3.3v

RESET -> Tactile Switch pos1

GND -> Tactile Switch pos2


GPIO 4, 5 Will be used as inputs for the sensors

GPIO 0 Will need to be tied to GND during firmware uploading

3.3v -> Regulator Vout

10uF cap between GND and Regulator Vin (5v)

10uF cap between GND and Regulator Vout(3.3v)

GPIO 13 -> the resistor

LED between GND and the resistor

For anyone not too familiar with these components - make sure the short legs of the capacitors and the LED are placed into the GND slots ( the legs represent the 'flow' of current - the short leg represents GND and the longer leg is +ve )


TX -> RX

RX -> TX


5v -> Regulator Vin

The 2 dangling blue wires on the sketch are the inputs for the 2 sensors

The dangling yellow wire is connected to GPIO0 , This should be connected to GND when uploading the firmware to the device.

Step 2: Getting Your Personal Key and Create Recipe

Maker Key

As stated in the introduction, you will need an IFTTT profile with the Maker channel connected to it. Once you have set that up you will need to get your unique top secret maker key. This can be accessed as soon as the channel is created.

Record this key as it will be needed in the Arduino sketch

Create The Recipe

From IFTTT.com create a new recipe

  • Click on 'This'
  • Select the Maker channel
  • Click on 'Receive a web request'
  • In the event name text box type: ESP
  • Click 'Create Trigger'
  • Click on 'That' and select IF Notification
  • Click 'Send a notification'
  • In the notification text box, type: Your Front door is: {{Value1}} Your Garage door is: {{Value2}}
  • Click 'Create Action' then 'Create Recipe'

That's it, the recipe is now ready for action. Any device with an internet connection and the IF app installed should show a notification when the recipe is run.

Next we have to setup the firmware for the ESP

Step 3: Setting Up the Firmware

Installing ESP8266 Community Files

You will need to have installed the ESP8266 commulity library in order to upload anything to the ESP from Arduino. If you haven't already done so.

To do this open Arduino, Goto File -> preferences and enter: http://arduino.esp8266.com/stable/package_esp8266... into the 'additional boards manager URL's' text box.

Then return to the main screen and goto Tool -> Board -> Boards Manager Scroll down to the ESP community files and install the package.

The clever thing about these libraries is that they turn your ESP into a virtual Arduino as well as keeping the wifi capability, pretty amazing really!

Change Sketch To Match Your Details

Now download the ESP8266_To_IFTTT.ino sketch and DataToMaker.h files from here and open in the Arduino IDE.

You will need to change 3 constants in order to get the sketch working correctly:

  • const char* myKey = This will be the Maker key you got from the previous step
  • const char* ssid = This will be your router ssid
  • const char* password = This will be your router password

Step 4: Uploading the Sketch for Testing

Once the firmware has been setup you should be ready to upload the sketch to the ESP.

To get the firmware uploading there are only a couple of settings to change from standard Arduino boards.

From the tools menu select:

  • Board -> NodeMCU 1.0
  • Frequency -> 80 MHz
  • Upload Speed -> I seem to get away with 115200 but it's best to start at 9600 and work up
  • Port -> This will be your FTDI board port
  • Programmer -> USBasp

Ok thats all good to go, All you need to do now is pull GPIO 0 low and reset the ESP, this will force it into flash boot mode which will enable us to upload the sketch. It's best to hold the reset button for a couple of seconds just to make sure it really is reset!

Now you can upload your sketch to the ESP - you should see the progress in orange at the bottom of the sketch window, at 9600 baud this will take a couple of minutes - at 115200 baud it should only take 20 seconds or so.

Step 5: Testing It All Works!

Once the sketch has uploaded, if all has gone to plan the LED you wired in should start flashing after a few seconds. If it does this indicates the board is connected to your wifi and is reading the sensor data (every second).

To see what's going on, open the serial port monitor from the Arduino IDE, make sure the baud rate is set to 115200 and 'line ending' is set to carriage return. (The baud rate is fixed at 115200 and is not related to the firmware upload speed set in the previous step!) If the firmware upload was successful you should see the current status of the ESP print out on the screen. If it looks anything like my screenshot then congrats, all the settings are good!

Once you are happy that the settings are correct and the sketch is successfully uploaded to the board you can disconnect GPIO 0 from GND and either pull it high or just leave it unplugged! This way, when the board is reset it will run your firmware instead of booting into flash mode.

Now when you toggle GPIO's 4 & 5 between GND and 3.3V you should receive a notification on your IFTTT app with the updated status of the 'test' doors!

Step 6: Taking It Further

You can now hack the sketch to death, changing GPIO's and descriptions to your hearts content! At present the Maker channel only supports up to 3 values so bear that in mind when adding to the sensor array. However there is no reason that you can't create another instance of the MakerToData class in the sketch and post to a different event name with more sensors. As far as i know all GPIO's on the ESP should be usable and directly relate to the pin numbers in the sketch.

I have ordered a couple of magnetic door sensors for 1 Euro each so that i can install the project in the shed. Then i will transfer the project to some strip board and solder a USB lead straight into the Vin on the regulator, this way i can use an old USB charger to power the project. (This will eliminate the need for the FTDI chip once the firmware is on the ESP) One improvement that I probably should make to the sketch is the use of ISR's and software debouncing, This would eliminate having to poll the IO's in the loop and would also react immediately to any sensor changes.

All in all this project provides a very cheap standalone way for your home sensors to communicate with you wherever you are (as long as you have internet available!)

If anyone has any ideas or improvements i'd be happy to hear them, The ESP is relatively new to me so I am still finding out it's true potential, so far I've been impressed at it's capabilities as both a WiFi device and a standalone micro.

<p>just a heads up for recent users: it seems that the screens in IFTTT have changed abit. The &quot;M&quot; doesnt appear anymore. It is now called &quot;Maker Webhooks&quot;</p>
<p>A little late to this tutorial, but is there a way to have multiple webhooks on one device? I tried this but can't get it to work:</p><p>DataToMaker event(myKey, &quot;RELAY0ON&quot;);</p><p>DataToMaker event1(myKey, &quot;RELAY10N&quot;);</p><p>DataToMaker event2(myKey, &quot;RELAY0OFF&quot;);</p><p>DataToMaker event3(myKey, &quot;RELAY1OFF&quot;);</p><p>and then call the various events by using </p><p>eventX.connect()</p><p>eventX.post()</p>
<p>I am looking to make a Wi-Fi remote of sorts and would like to have as many individual events as possible. I'm not very good at programming from scratch but I'm pretty good at adapting stuff to fit my needs.</p><p>Here is my entire code:</p><p>#include &lt;ESP8266WiFi.h&gt;</p><p>#include &lt;arduino.h&gt;</p><p>#include &quot;DataToMaker.h&quot;</p><p>#define SERIAL_DEBUG // Uncomment this to dissable serial debugging</p><p>// define gpio pins here:</p><p>#define RELAY_1_ON 5 // GPIO5</p><p>#define RELAY_1_OFF 4 // GPIO4</p><p>#define RELAY_0_ON 14 //GPIO13</p><p>#define RELAY_0_OFF 13</p><p>// Define program constants</p><p>*REMOVED*</p><p>// define program values</p><p>// declare new maker event with the name &quot;ESP&quot;</p><p>DataToMaker event(myKey, &quot;RELAY0ON&quot;);</p><p>DataToMaker event1(myKey, &quot;RELAY10N&quot;);</p><p>DataToMaker event2(myKey, &quot;RELAY0OFF&quot;);</p><p>DataToMaker event3(myKey, &quot;RELAY1OFF&quot;);</p><p>// LEAVE SET</p><p>bool connectedToWiFI = false;</p><p>void setup()</p><p>{</p><p>#ifdef SERIAL_DEBUG</p><p> Serial.begin(115200);</p><p> delay(200);</p><p> Serial.println();</p><p>#endif</p><p> delay(10); // short delay</p><p> pinMode(RELAY_1_ON, INPUT);</p><p> pinMode(RELAY_0_ON, INPUT);</p><p> pinMode(RELAY_1_OFF, INPUT);</p><p> pinMode(RELAY_0_OFF, INPUT);</p><p> WiFi.mode(WIFI_STA);</p><p> ConnectWifi();</p><p>}</p><p>void loop() {</p><p> if (wifiConnected)</p><p> {</p><p> if (digitalRead(RELAY_0_ON) == HIGH)</p><p> {</p><p> debugln(&quot;connecting...&quot;);</p><p> if (event.connect())</p><p> {</p><p> debugln(&quot;Connected To Maker&quot;);</p><p> event.post(); // </p><p> debugln(&quot;Relay 0 is on&quot;);</p><p> delay(2000);</p><p> }</p><p> else debugln(&quot;Failed To Connect To Maker!&quot;);</p><p> }</p><p> delay(1000); // pause for 1 second</p><p> if (digitalRead(RELAY_1_ON) == HIGH)</p><p> {</p><p> debugln(&quot;connecting...&quot;);</p><p> if (event1.connect())</p><p> {</p><p> debugln(&quot;Connected To Maker&quot;);</p><p> event1.post(); </p><p> debugln(&quot;Relay 1 is on&quot;);</p><p> delay(2000);</p><p> }</p><p> else debugln(&quot;Failed To Connect To Maker!&quot;);</p><p> }</p><p> delay(1000); // pause for 1 second</p><p> if (digitalRead(RELAY_0_OFF) == HIGH)</p><p> {</p><p> debugln(&quot;connecting...&quot;);</p><p> if (event2.connect())</p><p> {</p><p> debugln(&quot;Connected To Maker&quot;);</p><p> event2.post(); </p><p> debugln(&quot;Relay 0 is off&quot;);</p><p> delay(2000);</p><p> }</p><p> else debugln(&quot;Failed To Connect To Maker!&quot;);</p><p> }</p><p> delay(1000); // pause for 1 second</p><p> if (digitalRead(RELAY_1_OFF) == HIGH)</p><p> {</p><p> debugln(&quot;connecting...&quot;);</p><p> if (event3.connect())</p><p> {</p><p> debugln(&quot;Connected To Maker&quot;);</p><p> event3.post(); </p><p> debugln(&quot;Relay 1 is off&quot;);</p><p> delay(2000);</p><p> }</p><p> else debugln(&quot;Failed To Connect To Maker!&quot;);</p><p> }</p><p> delay(1000); // pause for 1 second</p><p> }</p><p> else</p><p> {</p><p> delay(60 * 1000); // 1 minute delay before trying to re connect</p><p> ConnectWifi();</p><p> }</p><p>}</p><p>bool ConnectWifi()</p><p>{</p><p> // Connect to WiFi network</p><p> debugln();</p><p> debugln();</p><p> debug(&quot;Connecting to &quot;);</p><p> debugln(ssid);</p><p> unsigned long startTime = millis();</p><p> WiFi.begin(ssid, password);</p><p> while (WiFi.status() != WL_CONNECTED &amp;&amp; startTime + 30 * 1000 &gt;= millis()) {</p><p> delay(500);</p><p> debug(&quot;.&quot;);</p><p> }</p><p> if (WiFi.status() == WL_CONNECTED)</p><p> {</p><p> debugln(&quot;&quot;);</p><p> debugln(&quot;WiFi connected&quot;);</p><p> }</p><p> else</p><p> {</p><p> WiFi.disconnect();</p><p> debugln(&quot;&quot;);</p><p> debugln(&quot;WiFi Timed Out!&quot;);</p><p> }</p><p>}</p><p>bool wifiConnected()</p><p>{</p><p> return WiFi.status() == WL_CONNECTED;</p><p>}</p><p>void debug(String message)</p><p>{</p><p>#ifdef SERIAL_DEBUG</p><p> Serial.print(message);</p><p>#endif</p><p>}</p><p>void debugln(String message)</p><p>{</p><p>#ifdef SERIAL_DEBUG</p><p> Serial.println(message);</p><p>#endif</p><p>}</p><p>void debugln()</p><p>{</p><p>#ifdef SERIAL_DEBUG</p><p> Serial.println();</p><p>#endif</p><p>}</p><p>Any suggestions on how to do this better?</p>
<p>Nice approach. Much more robust then the way I was doing it. Thank you.</p>
<p>The .h file I meant btw. </p>
<p>I'm wondering what the reason is for needing to reset the pin each time. I would think a simple open\close comparison would be better. Currently I need to close the wire to 3.3v to cause a change, then back to ground to cause another change. Most door switches will only have open\close. I am use to door sensors that don't need to be reset, ie, open the sensor and an even is triggered, close the sensor and an event is triggered. Thoughts?</p>
<p>Hi Jason,</p><p>If I understand your question correctly, what you probably need to do is use a pullup / pulldown resistor when connecting the door sensor. </p><p>For example, if the door switch is connected to GND then you'd tie a 10k resistor between the IO port and +3.3v. Then when the door switch is open the resistor will pullup the voltage to 3.3 and when it's closed the switch will pull it to GND. If you don't use the resistor then the connection will float when the switch is open and will cause unpredictable results.</p><p>If the switch is connected to +3.3v then you'd just do the opposite of the previous example!</p><p>I hope that helps, let me know if you need any more info.</p>
<p>That's exactly what I ending up doing. Thanks for the reply and very nice project by the way. </p>
<p>Great stuff. Thanks for the feedback :) </p>
<p>Hi</p><p>Very nice job.</p><p>I tried to &quot;grab&quot; the DataToMaker.h and use it in another sketch.</p><p>I haven't modified the .h but I used the calls.</p><p>I'm not able to make the event.post work.</p><p>I made the IFTTT recipe with ESP in the event name, same as in your sketch.</p><p>This is the part where I call the post function:</p><p>Serial.println(&quot;connecting to Maker...&quot;);</p><p> if (event.connect())</p><p> {</p><p> Serial.println(&quot;Connected To Maker&quot;);</p><p> event.post();</p><p> }</p><p> else Serial.println(&quot;Failed To Connect To Maker!&quot;);</p><p>and I get the Connected to Maker message.</p><p>I have set up the </p><p>DataToMaker event(&quot;mykey&quot;, &quot;ESP&quot;);</p><p>and of course included the </p><p>#include &quot;DataToMaker.h&quot;</p><p>But I don't get the notification.</p><p>Any suggestions?</p><p>Thanks</p><p>Vittorio</p>
<p>HI Vittorio,</p><p>Thanks, I'm glad you have got some useful info out of it :) </p><p>Have you set the event values before posting the data?</p><p>You need to use the event.setValue(int valueNumber, string message) method</p><p>If none of the 3 values are set then they will not post out to the maker site.</p><p>In the ESP8266_To_IFTTT sketch this is done in the DetectChange() method:</p><p>'event.setValue(i + 1, doorStates[val]);'</p><p>Maybe just try this before event.post() and see if it fires: event.setValue(1, &quot;Test&quot;);</p><p>Let me know how you get on! </p>
<p>Thanks</p><p>It's working perfectly. I thought that parameters were optional, I haven't seen than in your code was required.</p><p>All solved.</p><p>I also found that it's possible to send notification via Pushbullet that might be interesting to test beside IFTTT.</p>
<p>You're dead right, it is supposed to be optional. I hadn't fully tested the code, I have updated the DataToMaker.h file and uploaded to github, you should now be able to omit the values and it will just post the event name to Maker. </p><p>Thanks for the tip on Pushbullet, I'll be giving that a go when i get a spare 5 mins!</p>
<p>Here is where i find the pushbullet sketch.</p><p>http://www.esp8266.com/viewtopic.php?f=29&amp;t=7116</p>
<p>Thank's for sharing the link, it looks like a great way to sync your notifications with the devices.</p><p>I guess the benefit of IFTTT is that you are not just limited to communication with your computers and phones, you could for instance turn on a light (Philips Hue) when a trigger is set or add a row to a spreadsheet in Dropbox.</p><p>Just for info, another great platform for DIYers is the Adafruit IO, this gives you a few nice features like graphs and post history, this way you could get the data as well as posting it.. could be worth checking out:</p><p><a href="https://io.adafruit.com/" rel="nofollow">https://io.adafruit.com/</a></p>
<p>Great info, and very well put together. Thank you for sharing this!</p>
<p>Thanks seamster :~) , it was a bit rushed but hopefully there is enough information there to point folks in the right direction!</p>

About This Instructable




More by Mysol:ESP8266 To IFTTT Using Arduino IDE 
Add instructable to: