Project tutorial

Telegram Bot with ESP8266 © GPL3+

Divine control of ESP8266 with telegram bot.

  • 11,458 views
  • 35 comments
  • 35 respects

Components and supplies

Apps and online services

About this project

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 to the great world of IoT.

Check the whole project 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

#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");   
}   
}   

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

Code

ESP8266_Telegram.inoC/C++
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <TelegramBot.h>


#define LED 1
// Initialize Wifi connection to the router
const char* ssid     = "xxxx";
const char* password = "yyyy";


// Initialize Telegram BOT
const char BotToken[] = "xxxxxxxxxxx";

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");  
 }  
}  

Schematics

schema
Wifitoarduino jz26ak1qwk

Comments

Similar projects you might like

Smart Energy Saver for Your Home

Project tutorial by Dhairya Parikh

  • 1,594 views
  • 8 comments
  • 11 respects

Simple Water Quality Analysis

Project showcase by Wen-Liang Lin

  • 6,094 views
  • 5 comments
  • 9 respects

Secure Your Logins with Biometrics

Project tutorial by Amal Mathew

  • 1,371 views
  • 0 comments
  • 7 respects

Chicken Coop Automation

Project in progress by BMic

  • 5,296 views
  • 9 comments
  • 15 respects

First Project - Arduino+Blynk

Project tutorial by Vijay Shreenivos

  • 667 views
  • 1 comment
  • 5 respects

Little Rover

Project tutorial by Jeremie

  • 804 views
  • 0 comments
  • 8 respects
Add projectSign up / Login