Introduction: Telegram Bot With ESP8266
Hi fellow coders,
It's amazing to start my Instructables career with telegram bot API and ESP8266. Through this project I try to depict how to control ESP8266 with telegram bot which opens to the great world of IoT.
Step 1: Installing Telegram Bot Library
First of all download Telegram Bot library (download) and add it to Arduino IDE.
Step 2:
Install Telegram on your Laptop or Phone and search for Botfather. Through Botfather create your new bot.From Botfather you can take the token which is the interaction key between device and Telegram bot API .
Step 3:
Connect ESP8266 to Arduino as shown. Connect GPIO0 to ground and press reset button of Arduino and upload the code.
Step 4:
Put your wifi credentials as well as bot token and upload the code.
#include <ESP8266WiFi.h>#include <WiFiClientSecure.h> #include <TelegramBot.h> #define LED 1 //led pin number // Initialize Wifi connection to the router const char* ssid = "xxxxx"; const char* password = "yyyyy"; // Initialize Telegram BOT const char BotToken[] = "xxxxxxxxx"; WiFiClientSecure net_ssl; TelegramBot bot (BotToken, net_ssl); // the number of the LED pin void setup() { Serial.begin(115200); while (!Serial) {} //Start running when the serial is open delay(3000); // attempt to connect to Wifi network: Serial.print("Connecting Wifi: "); Serial.println(ssid); while (WiFi.begin(ssid, password) != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(""); Serial.println("WiFi connected"); bot.begin(); pinMode(LED, OUTPUT); } void loop() { message m = bot.getUpdates(); // Read new messages if (m.text.equals("on")) { digitalWrite(LED, 1); bot.sendMessage(m.chat_id, "The Led is now ON"); } else if (m.text.equals("off")) { digitalWrite(LED, 0); bot.sendMessage(m.chat_id, "The Led is now OFF"); } }
Step 5:
I here include the working of my project .

Participated in the
First Time Author Contest 2018

Participated in the
Epilog Challenge 9
5 Comments
3 years ago
This is a very cool project, thanks a lot for sharing.
I'm trying to implement it on an ESP8266, however, I get a fatal error which restarts the ESP when the getUpdates is executed.
Has anyone had any similar issue? any suggestion?
Bests,
Sergio
Question 3 years ago
hello jonathan..i have a problem with the wificlientsecure.h and esp8266.h library. cannot find the right one that work with your code.can u help me provide the link to download the library.thank u.
Question 4 years ago on Step 5
Hello Jonathan,
i try to build the project.
In Arduino IDE do you have to set "Arduino Uno" or "Generic ESP8266 module" as board?
I guess the ESP8266 module...
So the UNO is just used as put-through? and after successfully programming, the ESP8266 module will work stand-alone and can be cut from the UNO (power needed, of course)?
br,
Reinhard
Answer 4 years ago
I have used Arduino Uno instead of USB-TTL device. If I haven't used Arduino Uno, there is no way to program ESP8266 by plugging it to PC. So I have used Arduino as a put through. When using Arduino you should set board to Generic ESP8266. Of course after successful programming you can use ESP8266 as standalone. Thanks for getting in touch
Reply 4 years ago
Thanks for you answer - I could already manage to program ESP8266, There are some points one has to know...
Best regards,