PANZOKA
Published © GPL3+

Easy LED with Telegram

Easy ways to make LED with Telegram

BeginnerShowcase (no instructions)1 hour395
Easy LED with Telegram

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
LED (generic)
LED (generic)
×1
LED (generic)
LED (generic)
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

Actions on Google
Actions on Google
you can use telegram or google assistant

Story

Read more

Code

Code LED with telegram

C/C++
#include "CTBot.h"
CTBot myBot;
String ssid = "NA";
String pass = "234567ER";
String token = "1334762804:AAHEfNE2BTWyDhzxWKF3sX72X_P_Utm8Z2k";
uint8_t redLed = D1;
uint8_t greenLed = D2;

void setup() {
Serial.begin(115200);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
else
Serial.println("\ntestConnection NOK");
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
}
void loop() {
TBMessage msg;
if (myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("Red Light on")) {
digitalWrite(redLed, HIGH);
myBot.sendMessage(msg.sender.id, "Red Light is now ON");
}
else if (msg.text.equalsIgnoreCase("Red Light off")) {
digitalWrite(redLed, LOW);

myBot.sendMessage(msg.sender.id, "Red Light is now OFF");
}

if (msg.text.equalsIgnoreCase("Green Light on")) {
digitalWrite(greenLed, HIGH);
myBot.sendMessage(msg.sender.id, "Green Light is now ON");
}
else if (msg.text.equalsIgnoreCase("Green Light off")) {
digitalWrite(greenLed, LOW);
myBot.sendMessage(msg.sender.id, "Green Light is now OFF");
}

else {
String reply;
reply = (String)"Welcome " + msg.sender.username + (String)".Try LIGHT ON or LIGHT OFF.";

myBot.sendMessage(msg.sender.id, reply);
}
}
delay(50);
}

Credits

PANZOKA
5 projects • 2 followers
i make projects
Contact

Comments

Please log in or sign up to comment.