Skip to main content

Controlling LED using ESP8266 and Telegram Bot – IoT Project

Controlling LED using ESP8266 and Telegram Bot – IoT Project

In this project we will control an LED which is connected to ESP8266 with a Telegram bot. Hope you know about Telegram, it is a messenger app similar to Whatsapp. This enables users to control their ESP8266 via simply typing and sending commands in Telegram. By adding some relays or TRIAC you can make this a home automation project.

Components Required

  • ESP8266
  • LED
  • 470Ω Resistor
  • Breadboard
  • USB Cable
  • Connecting Wires

Hardware

Circuit Diagram

Home Automation using ESP8266 and Telegram Bot - Circuit Diagram
Home Automation using ESP8266 and Telegram Bot – Circuit Diagram

Software

Telegram Bot

Bots are third-party applications that run inside Telegram. Users can interact with bots by sending messages, commands and inline requests. We can control our bots through HTTP APIs provided by Telegram.

A Telegram bot is an application hosted on a server (here it is ESP8266) that uses Telegram bot API to connect to Telegram Messenger clients. A great advantage of Telegram bots is that they have zero install requirements and run seamlessly on all computer or mobile platforms where Telegram Messenger runs.

Configure Telegram Bot

Install Telegram on your Laptop or Phone and search for BotFather. Through BotFather we can create a new bot. After creating a new bot, we have to note down the token which is the interaction key between device and Telegram bot API .


Telegram_BotFather
Telegram_BotFather

Telegram Bot Library for Arduino

  • Download the Telegram Bot library.
  • Open Arduino IDE, Go to “Sketch”, Select “Include Library” and Click on “Add .ZIP Library”.

Programming ESP8266

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <TelegramBot.h>

#define LED 5

const char* ssid = "<Your WiFi Name or SSID>";
const char* password = "<Your WiFi Password>";

const char BotToken[] = "<Token you get while creating the bot>";

WiFiClientSecure net_ssl;
TelegramBot bot (BotToken, net_ssl);

void setup()
{
  Serial.begin(115200);
  while (!Serial) {} //Start running when the serial is open
  delay(3000);
  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, "LED is ON");
    Serial.println("LED is ON");  
  }  
  else if (m.text.equals("off")) 
  {  
    digitalWrite(LED, 0);   
    bot.sendMessage(m.chat_id, "LED is OFF");  
    Serial.println("LED is OFF");
  } 
}

Working

The LED connected to ESP8266 will be controlled by Telegram Bot. In Telegram app, create a new bot and open it. Initiate the operation by sending “/start” message. Send “on” message will turn ON the LED, as a reply we will get information about LED status like “LED is OFF”. Send “off” message to turn OFF the LED, as a reply we will get information about LED status like “LED is OFF”.

Practical Implementation

Home Automation using ESP8266 and Telegram Bot - Practical Implementation
Home Automation using ESP8266 and Telegram Bot – Practical Implementation

Video

Comments

Popular posts from this blog

Interfacing L298N Motor Driver with Arduino Uno

1 May Interfacing L298N Motor Driver with Arduino Uno In this tutorial we will learn how to interface  L298N  motror driver with  Arduino Uno . You might be thinking why we need L298N for controlling a motor. The answer is very simple,  Arduino  board or a  microcontroller  IO pins don’t have enough current/voltage driving capability to drive a motor. For driving the motor in both directions (clockwise and anti-clockwise) we need to use an  H-Bridge . Please read our article  H-Bridge – DC Motor Driving  for more information. L298N is an integrated monolithic circuit with dual H-Bridge. It can be used to rotate the motor in both directions and to control the speed of the motor using  PWM  technique. Components Required Arduino Uno L298N Motor Driver 12V battery 2x DC Motors Jumper wires L298N Motor Driver Module L298N Motor Driver Connections Explained Specifications Output A, Output B – To connect two motors. Driver Power Inpu...

E-TECH SOLAR INVERTER SOLUTION

    DEEP CYCLE BATTERIES The reason many projects fail can mostly be put at the door step of batteries due to inadequate charging and low charge/discharge cycles. Our batteries are  among the very top 3 in the industry and capable of undergoing several cycle  of up to 5 years @ 20% DOD. Hence, we are confident of giving as much as 2 years warranty for some of our batteries SOLAR SYSTEM FOR DOMESTIC AND INDUSTRIAL USE  Many businesses such as hospitals, schools, shopping malls, hotels etc are beginning to embrace solar to completely eliminate unnecessary spending on diesels ……. why not come on board now and earn yourself some carbon credit apart from huge savings in millions of Naira.   SOLAR PANEL MODULES Our panels are carefully selected and tested from the very best among  the Tier one range of solar panels. We guarantee a sustainable yield for at least 25 years and 15 years warranty Inverter Our hybrid inverte...

SMPS DESIGN USING UC384X SERIES

 SMPS design is always a difficult task for most beginners even to many intermediate engineers based on the fact that the principle and the rules looks tedious. Flyback approach is always a very good concept when you needed a current not above KW but you can still use flyback approach to achieve a higher power rating if you can interconnect them together or follow some set rules. While I was getting my hands dirty, experimenting smps flyback approach I burnt a lot of IC and power transistors and other components before i was able to understand the principle revolving around it. SMPS design both buck converter, boost converter, buck-boost converter, push-pull, half-bridge and full bridge are not a difficult task but they need a very huge attention else nothing will work and debt may set in. Will be pointing out some rudiment behind SMPS design. Namely on buck converter using flyback approach: * TRANSFORMER SELECTION: Flyback uses a gapped ferrite core or gapped core, the core ca...