Introduction: ESP8266 to IFTTT Using Arduino IDE

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)

LED

~ 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

GPIO15 -> GND

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 )

ESP -> USB ADAPTER

TX -> RX

RX -> TX

GND -> GND

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.