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...

Using the TLP250 Isolated MOSFET Driver

Using the TLP250 Isolated MOSFET Driver - Explanation and Example Circuits I’ve already shown how to drive an N-channel MOSFET (or even an IGBT) in both high-side and low-side configurations in a multitude of ways. I’ve also explained the principles of driving the MOSFETs in these configurations. The dedicated drivers I’ve shown so far are the TC427 and IR2110. Some people have requested me to write up on MOSFET drive using the very popular TLP250. And I’ll explain that here. The TLP250, like any driver, has an input stage, an output stage and a power supply connection. What’s special about the TLP250 is that the TLP250 is an optically isolated driver, meaning that the input and output are “optically isolated”. The isolation is optical – the input stage is an LED and the receiving output stage is light sensitive (think “photodetector”). Before delving any further, let’s look at the pin configuration and the truth table. Fig. 1 - TLP250 Pin Configuration Fig....