AO I
Published © CC BY-ND

Led + telegram

Not yet

BeginnerFull instructions provided-60 minutes291
Led + telegram

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Premium Female/Female Jumper Wires, 40 x 3" (75mm)
Premium Female/Female Jumper Wires, 40 x 3" (75mm)

Story

Read more

Code

led + telegram

Arduino
#include "CTBot.h"
 CTBot myBot;
String ssid = "xxxxxxxx";
String pass = "xxxxxxxxxxxx";
String token = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
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

AO I
13 projects • 1 follower

Comments