Introduction: Send Notifications to Your Phone From an ESP8266

Hello Everyone!

In this instructable I'm going to show you how to send notifications to your phone from your ESP8266 when programing with Arduino IDE.

This can be very useful if you want the device to notify when a sensor is triggered (PIR motion sensor) or certain criteria for a sensor is met ( e.g. dropped below a certain temperature).

I'm going to show you two ways to do this, using Telegram messenger and IFTTT. Both of these methods are completely free to use.

Check out the video to see it in action and for a quick run through of what I'll go through in this instructable. The code and circuitry from the demo is on my github.

Step 1: Setting Up Telegram

Picture of Setting Up Telegram

Telegram is an instant messenger very like whatsapp.

One advantage it has over whatsapp is it allows you to create bots, which are programs that you can interact with in the chat application.

We'll be using the Universal Arduino Telegram Library which is available on the Arduino Library manager to send us a Telegram message. This library supports ESP8266 and Wifi-101 boards. (Telegram requires SSL so ethernet shields and older wifi shields will not work.)

To use the library the first thing you need to get is a Bot Token, to get this inside telegram search for "botfather" and type the "/newbot" command. Then follow the onscreen instructions for naming the bot. Botfather will return you a bot token that you will use with the library.

Bots can only message you if you've first started a conversation with the bot first, so click on the link to your bot in the message that botfather sent and click the "Start" button

So the bot knows where to send the message you are going to need to add your chat id to the sketch, this is your unique identifier on Telegram. The easiest way to get this is search for a bot called "myIdBot", press the start button and send the "/getid" command.

You should now have everything you need to use Telegram for notifications.

Step 2: Setting Up IFTTT

Picture of Setting Up IFTTT

IFTTT (If This Then That) is a service that lets you perform actions based on triggers, for example send a tweet if you get an email with a certain title.

Luckily for us fans of the ESP8266, it's pretty simple to trigger an event directly from the ESP8266. We'll be using the Arduino IFTTT Maker Library which is also available on the Arduino Library manager. It supports the same boards as the Telegram library (ESP8266 and Wifi-101) and also requires SSL (so no ethernet shield).

To use this library, the first thing we will need to do is create a "recipe" on IFTTT.

The "this" part, or the trigger, should be configured to be the "Maker" service. Give the trigger a name (I used "button_pressed" in the video), you will need this when using the library.

You then need to configure the "that" part of the IFTTT. In the video I use the "Notification" event (which requires the IFTTT app on your phone), but you can choose anything you want (email, twitter, even your Phillips Hue lightbulb!). You'll see in library that you can pass up 3 parameters, these can be used when creating the message that recipe sends you.

Finally you need to get for the library is the Maker key from your account. Click on your account up the top right of the IFTTT website and click on "Services". Click on "Maker" and then "Settings". The Maker Key is the characters at the end of the URL (In the red box in the photo).

Step 3: Testing It Out

Picture of Testing It Out

You should now be able run the example from this github page. The circuitry and parts list are in the ReadMe.

In the sketch, just fill in the:

  • Telegram Bot Token
  • Telegram Chat ID
  • IFTTT Maker Key
  • IFTTT Event Name

Both of these libraries require the ArduinoJson library to be installed, so make sure you grab that from the library manager too.

Hopefully you find this useful! If you have any questions please let me know.



dfiddle (author)2017-05-14

This is great work. I've used this as the core for multiple projects. Thank you!!

robomaniac (author)2017-02-16

dude so sweet!!! I had this running within minutes!! Darn easy!

Using IFTTT, I send emails, notification and send data to google spreadsheet!

I am in the process to add this to machine in my workshop so I can send usage data to spreadsheet and I will do some graphs and understand when I need to do maintenance!

thanks a lot!!

witnessmenow (author)robomaniac2017-02-16

Hey, that sounds great!

Really good idea logging it to Google sheets, I was thinking before about seeing could I use the Google api to do it before but I haven't looked into yet.

Thanks a lot for your comment, really appreciate it. It's a Great feeling to see people using stuff that I've made!

robomaniac (author)witnessmenow2017-02-16

You could look into pushsafer.

It's a service that let you customize notification, you can tell how many motor virbration you want, what sound to play, what icon, etc. It has lot of potential. It's free for a X amount of push per month.

it's basically PHP request, I tried and tried to make it work for the ESP8266 but no luck. It had to do with HTTPS no possible on arduino but Kevin (the guy behind pushsafer) change his side to do both HTTP and HTTPS.

my thread is here

I you make it work, I will check your instructable :P

witnessmenow (author)robomaniac2017-02-17


I took a look at this last night. I didn't look through your link too much, but just went direct to pushsafers website

ESP8266 can do https, both of the libraries in this instructable talk https to their endpoints.

I spent some time making a library to talk with pushsafer, but I haven't got it working yet, but it should be close! (It was late and I needed to go to bed!)

I'll spend a few minutes on it tonight and see can I get it working. It needs to be tidied up a bit, but the example attempts to make a request to pushsafer with the configured inputs

They have examples for arduino on their website, but it doesn't even compile (trying to call length() on an int for example) so I didn't think there was much value in basing the code on their example.

robomaniac (author)witnessmenow2017-02-17


I tried your code did not work. I made an issue on github.

Regarding the code not compiling (trying to call length()) is what I posted in the forum. I will keep checking github.

witnessmenow (author)robomaniac2017-02-17

Hey, I took a look into this for you.

Esp8266 can do https, both these libraries use it.

Here is a library I created to work with pushsafer

It does work, It can send notifications ok, but for some reason the response is not received back on the ESP8266, not too sure what is wrong (maybe I'm not waiting long enough for it, pushsafer doesn't seem as fast to respond as Telegram when I was testing with curl).

Pushsafers Arduino example on their website is trying to use length() methods on ints so I dont think they tested it very well :)

berndu86 (author)2017-07-23

I had the same problem as ElioM2 with the error with the string message: String message = "SSID: " + ssid + "\n"

I resolved this problem with:

String message1 = "SSID: ";

String message2 = ssid;

String message = message1 + message2 + "\n";

The problem that I am having is the following "if" statement is not executing:

if(bot.sendMessage(CHAT_ID, message, "Markdown")){

Serial.println("TELEGRAM Successfully sent");


telegramButtonPressedFlag = false;


I am not getting the "TELEGRAM Successfully sent message nor am I receiving a notification from Telegram. My guess is that it has something to do with the UniversalTelegramBot.h library. When the code compiles, the message states: UniversalTelegramBot (legacy). I am trying to use the ESP8266-01 with GP02 to monitor a push button for Telegram only.

witnessmenow (author)berndu862017-07-24

Yeah there seems to be a missing semi colon in my example :/ , I will update it later

I was using Telegram on an ESP8266-01 yesterday so it does work on the board.

A couple of things to check.

Did you populate the CHAT_ID with your ID? Is your bot token set?

Another thing to check is make sure you open your bot and click start before you can send it a message

berndu86 (author)witnessmenow2017-07-24

The ID is the 9 digit number obtained by using /getid and the bot token is the alpha numeric token for the HTTP API: nnnnnnnnn:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

(9 numeric digits:35 alphanumeric digits)?

If so, then yes, my CHAT_ID is populated with my ID and my bot token is set. I am using a Serial.print statements to to follow the execution of the sketch in the serial monitor. I have placed a Serial.print the line before the "IF" statement and the next line after it. I know that SendTelegramMessage function is being called. For some reason, the "IF" statement is not executing. My bot is started, but before I would be sent a message, I should get something printed via the serial monitor to illustrate that the if statement is executing. I am at a loss on what to do next?

witnessmenow (author)berndu862017-07-26

The best way to see whats going on would be to enable debugging.

If you search in your arduino folder for this file: "UniversalTelegramBot.h" and change the _debug flag to be true and build your sketch again, the library should print more to the serial then, including responses.

Sorry, I need to make it easier to enable debugging! Please post back here if that reveals anything.

berndu86 (author)witnessmenow2017-08-20

Turns out the ESP8266-01 that I was using, was operating erratically. A new ESP8266-01 and all is well!

One question on your example circuit. Why did you choose to have the inputs to trigger the interrupt(s) pulled down and sense on RISING? The device will not boot up without moving the GPIO2 input from LOW to HIGH and back again. In other words, why not pull GPIO2 UP and sense on FALLING? The ESP8266 would then boot up without operator intervention.

Thanks for the tip above. I am going to try that. Thanks again all of your help.

witnessmenow (author)berndu862017-08-20

Hi Berndu86,

Good to hear!

Honestly I can't remember why I did it that way, I wrote that code for a project over a year ago and I just brought it into this example. I also don't use the ESP8266-01 too often so I'm not too familiar with it. It's a good tip that some people might run into issues with it.

ElioM2 (author)2017-05-03

Very ineresting, but I had this error in compilation. Can you help me?

Thank you.


Arduino:1.8.1 (Windows 7), Scheda:"WeMos D1 R2 & mini, 80 MHz, 921600, 4M (3M SPIFFS)"

C:\Users\Elio\Desktop\push-notifications-arduino-esp8266-master\push-notifications-arduino-esp8266-master\PushNotificaitonDemo\PushNotificaitonDemo.ino: In function 'void sendTelegramMessage()':

PushNotificaitonDemo:116: error: invalid operands of types 'const char [7]' and 'char [9]' to binary 'operator+'

String message = "SSID: " + ssid + "\n"


PushNotificaitonDemo:121: error: expected ',' or ';' before 'telegramButtonPressedFlag'

telegramButtonPressedFlag = false;


exit status 1

invalid operands of types 'const char [7]' and 'char [9]' to binary 'operator+'

Questo report potrebbe essere più ricco di informazioni abilitando l'opzione

"Mostra un output dettagliato durante la compilazione"

in "File -> Impostazioni"

witnessmenow (author)ElioM22017-07-24

Sorry i am only seeing this now, but there is a missing semi colon at the end of that line:

String message = "SSID: " + ssid + "\n";

hemanth kumar reddy (author)2017-03-14

Can you plz look at this

small help thanks

CarterKoopa (author)2017-02-17

I'm getting an error whenever I try to compile the code. The error is: invalid operands of types const char to binary 'operator+'. Any ideas? I have only eidited the SSID, Password, and keys.

witnessmenow (author)CarterKoopa2017-02-18

Hey, which board are you using?

The error seems to relate to trying to add (+) on different types of strings.

Have yo added a new serial print that prints the tokens?

CarterKoopa (author)witnessmenow2017-02-18

I'm using a generic ESP8266 with an Arduino Uno? Do I need a specific board?

CarterKoopa (author)CarterKoopa2017-02-18

I haven't changed anything else in the project either. The line with the error is:

String message = "SSID: " + ssid + "\n"


macsito07 made it! (author)CarterKoopa2017-02-21

i'm having the same problem. please help!!!

witnessmenow (author)macsito072017-02-21

I'd say we must be using different versions of the arduino ide. Try changing it to

"ssid: " + String(ssid) + "\n"

I've a feeling you'll need to do the same on the next line with ipAdress

macsito07 (author)witnessmenow2017-02-22

now the error is on the next line

message = message + "IP: " + String(ipAddress) + "\n"

i also tried using other version of IDE but it shows the same error.

witnessmenow made it! (author)macsito072017-02-25

A commenter on youtube made this change when they were having the same issue and it works for them

witnessmenow (author)CarterKoopa2017-02-21

You will need to program the esp8266 rather than using at codes with.

This video should hopefully explain how to program the esp8266 with an uno

DanielC752 (author)2017-02-21

Worked like a charm! Do you have any code for this application with a PIR? Tried myself, but it just keeps sending notifications constantly... :)

witnessmenow (author)DanielC7522017-02-21

Hey Daniel,

Glad it worked for you!

I've ordered some PIR sensors, but they are on the slow boat from China so I haven't played around with any yet. As far as i know most PIR sensors have a couple of adjustments you can make to them to the change how often they trigger, it might be worth looking into that, here is a pretty good link describing it

You could also cool down timer in your code, that it wouldn't set the flag unless a certain amount of time had past.

Daddys_Stare (author)2017-02-19

I dont know about using Telrgram. First thing it wants to do is take over and manage calls and SMS duties of my phone. Bit of a security risk there.

Hey, I've it installed for the last couple of years or so don't really remember the setup process. If your talking about the permission to read SMS, I think that's used at verification. I'd imagine what's app has the same permissions.

The IFTTT method should allow you to raise notifications without installing anything new (if you use email for example) so hopefully that works out for you.

Pavan. (author)2017-02-13

Can anyone help me to fix range of esp8266 since I am new to this I dono how to do it

Pavan. (author)Pavan.2017-02-14

I am doing small project by using ESP8266 , project is all about displaying the messages to LCD by using android app. Project is successful completed But the Wi-Fi connectivity range is very less about 10feet , I tried by connecting attena but of no use so kindly give me an idea to fix this problem . I had seen so many videos in YouTube but I am not getting proper solution, And also by using IOT they controlled esp8266 can you pls help me to understand the concept of IOT(internet of things ) to configure of esp8266.

witnessmenow (author)Pavan.2017-02-14

oh, that's not good! What board are you using?

Any esp8266 chips I've had and decent WiFi range, not sure how long but it has never been an issue (definitely more than 10 feet). Do you have it in a metal case or near something metal (like a battery)?

If you look at my video on telegram it talks about sending commands to your device, you could use that communicate both ways with your esp8266

witnessmenow (author)Pavan.2017-02-13

Hi Pavan, I'm sorry I don't understand your question, what's the problem you are having?

JeromeCastaneda (author)2017-02-13

can I use esp32 instead of esp8266?

I've never tested as i don't have a board! The libraries work by passing in a HTTPS client in to them, just looking at the arduino core for esp32 it looks like there is some issues with WifiClientSecure.

There was a PR raised to fix it yesterday, so hopefully it's close!

If it works for you please do let me know

eermiyaev (author)2017-02-13

Спасибо. Кстати, ты палишься с закладками спидов :)

DIY Hacks and How Tos (author)2017-02-12

Good idea. This gives me a lot of ideas for projects that could use this.

Hey, thanks for your message. Glad it was useful for you!

About This Instructable




Bio: Hey everyone! My name is Brian and thanks for checking my Instructables. I'm a software developer by trade but I've recently gotten into ... More »
More by witnessmenow:Simple WiFi Controlled RC CarWiFi Controlled LED Wedding Table Pieces5 Quirks of Using the ESP8266
Add instructable to: