Telegram Bot With ESP8266

About: Hardware hack enthusiast

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

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

First Time Author Contest 2018

Participated in the
First Time Author Contest 2018

Epilog Challenge 9

Participated in the
Epilog Challenge 9

Share

    Recommendations

    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    3 Discussions

    0
    None
    ReinhardD5

    Question 11 months 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

    2 answers
    0
    None
    Jonathan_WickReinhardD5

    Answer 11 months 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

    0
    None
    ReinhardD5Jonathan_Wick

    Reply 11 months ago

    Thanks for you answer - I could already manage to program ESP8266, There are some points one has to know...

    Best regards,