Telegram Bot With ESP8266

228

3

Posted

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.

Check the whole project here

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 .

Check It Here

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Microcontroller Contest

      Microcontroller Contest
    • Spotless Contest

      Spotless Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments