Telegram Bot With Esp8266

About the project

Divine control of ESP8266 with telegram bot.

Project info

Difficulty: Easy

Platforms: ArduinoEspruinoEverything ESP

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Jumper Wire Jumper Wire x 7
ESP8266 ESP8266 x 1
Arduino Uno Arduino Uno x 1

Software apps and online services

Telegram bot API Telegram bot API
Arduino IDE Arduino IDE

Story

Hi fellow coders,
It's amazing to start my Hackster career with telegram bot API and ESP8266. Through this project I try to depict how to control ESP8266 with telegram bot which opens the door to the great world of IoT.

Check the video tutorial here

1 . Installing Telegram Bot Library

First of all download Telegram Bot library (download) and add it to Arduino IDE.

2. Configure Telegram Bot

Install Telegram on your Laptop or Phone and search for Botfather. Through Botfather create your new bot.


From Botfather you can taken the token.

3. Setting up the Device

Connect ESP8266 to Arduino as shown. Connect GPIO0 to ground and reset to reset of Arduino and upload the code.

4. The Code


  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClientSecure.h>
  3. #include <TelegramBot.h>
  4. #define LED 1
  5. // Initialize Wifi connection to the router
  6. const char* ssid = "xxxx";
  7. const char* password = "yyyy";
  8. // Initialize Telegram BOT
  9. const char BotToken[] = "xxxxxxxxxxx";
  10. WiFiClientSecure net_ssl;
  11. TelegramBot bot (BotToken, net_ssl);
  12. // the number of the LED pin
  13. void setup()
  14. {
  15. Serial.begin(115200);
  16. while (!Serial) {} //Start running when the serial is open
  17. delay(3000);
  18. // attempt to connect to Wifi network:
  19. Serial.print("Connecting Wifi: ");
  20. Serial.println(ssid);
  21. while (WiFi.begin(ssid, password) != WL_CONNECTED)
  22. {
  23. Serial.print(".");
  24. delay(500);
  25. }
  26. Serial.println("");
  27. Serial.println("WiFi connected");
  28. bot.begin();
  29. pinMode(LED, OUTPUT);
  30. }
  31. void loop()
  32. {
  33. message m = bot.getUpdates(); // Read new messages
  34. if (m.text.equals("on"))
  35. {
  36. digitalWrite(LED, 1);
  37. bot.sendMessage(m.chat_id, "The Led is now ON");
  38. }
  39. else if (m.text.equals("off"))
  40. {
  41. digitalWrite(LED, 0);
  42. bot.sendMessage(m.chat_id, "The Led is now OFF");
  43. }
  44. }



Put your wifi credentials and bot token and upload the code.


5. Test The Working

I here include the making and working of my project .

Check it here





Schematics, diagrams and documents

Telegram Bot With Esp8266 - Schema

connect GPIO-0 to ground and hit reset before uploading the code and disconnect GPIO-0 after uploading and hit reset again.

Code

Telegram Bot With Esp8266

Replace Wi-Fi credentials as well as bot token and upload the code .

Credits

Photo of JohnWick

JohnWick

Hardware hack enthusiast

   

Leave your feedback...