資料介紹
描述
嘿極客,希望你做得很好。在本文中,我們將制作一個非常有趣的項目,即使用電報機器人進行自動化。在這個項目中,我們將在電報機器人的幫助下控制三個 LED。除了 LED,您還可以根據需要連接其他設備。您可以在我們的網站上閱讀全文。

什么是電報機器人
在開始之前,請在您的智能手機上下載電報應用程序并在其上注冊一個帳戶。然后去搜索欄搜索botfather并打開帶有藍色勾號的帳戶。

現在單擊開始啟動機器人,您會找到一個菜單。

然后單擊新機器人以創(chuàng)建一個新項目。

現在它會要求您提供一個合適的用戶名,然后為您想要制作的機器人提供一個唯一的名稱。對于用戶名,最后使用 _bot,如下所示。在此之后,您將獲得一個必須復制的唯一令牌 ID。然后將此ID粘貼到代碼中。然后打開你的機器人。

打開類型 start 后,它會回復你的消息,如下圖所示。現在根據您的需要在應用程序上發(fā)送命令,例如開/關燈,LED 根據您的操作打開和關閉。請參閱下面給出的屏幕截圖。

當您鍵入RED LIGHT ON時,紅色 LED 將亮起,如下所示。

當您鍵入GREEN LIGHT ON時,綠色 LED 將亮起。

如果您鍵入WHITE LIGHT ON ,白色 LED 將亮起。

所需組件
電報機器人自動化電路圖

電報機器人代碼
注意:請將下面給出的代碼上傳到 NodeMCU。
//Techatronic.com
#include "CTBot.h"
CTBot myBot;
String ssid = "xxxxxxxxxxxx"; // REPLACE SSID WITH YOUR WIFI SSID
String pass = "xxxxxxxxxxxx"; // REPLACE Password YOUR WIFI PASSWORD, IF ANY
String token = "---------------------------------------------------"; // REPLACE Token WITH YOUR TELEGRAM BOT TOKEN
uint8_t greenled = 5;
uint8_t redled = 4;
uint8_t whiteled = 12;
void setup() {
// initialize the Serial
Serial.begin(115200);
Serial.println("Starting TelegramBot...");
// connect the ESP8266 to the desired access point
myBot.wifiConnect(ssid, pass);
// set the telegram bot token
myBot.setTelegramToken(token);
// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
else
Serial.println("\ntestConnection NOK");
// set the pin connected to the LED to act as output pin
pinMode(redled, OUTPUT);
digitalWrite(redled, LOW);
pinMode(greenled, OUTPUT);
digitalWrite(greenled, LOW);
pinMode(whiteled, OUTPUT);
digitalWrite(whiteled, LOW);
}
void loop() {
// a variable to store telegram message data
TBMessage msg;
// if there is an incoming message...
if (myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("RED LIGHT ON")) { // if the received message is "LIGHT ON"...
digitalWrite(redled, HIGH); // turn on the LED
myBot.sendMessage(msg.sender.id, "RED Light is now ON"); // notify the sender
}
else if (msg.text.equalsIgnoreCase("RED LIGHT OFF")) { // if the received message is "LIGHT OFF"...
digitalWrite(redled, LOW); // turn off the led
myBot.sendMessage(msg.sender.id, "RED Light is now OFF"); // notify the sender
}
else if (msg.text.equalsIgnoreCase("GREEN LIGHT ON")){
digitalWrite(greenled, HIGH); // turn on the LED
myBot.sendMessage(msg.sender.id, "GREEN Light is now ON"); // notify the sender
}
else if (msg.text.equalsIgnoreCase("GREEN LIGHT OFF")){
digitalWrite(greenled, LOW); // turn off the led
myBot.sendMessage(msg.sender.id, "GREEN Light is now OFF"); // notify the sender
}
else if (msg.text.equalsIgnoreCase("White LIGHT ON")){
digitalWrite(whiteled, HIGH); // turn on the LED
myBot.sendMessage(msg.sender.id, "WHITE Light is now ON"); // notify the sender
}
else if (msg.text.equalsIgnoreCase("WHITE LIGHT OFF")){
digitalWrite(whiteled, LOW); // turn off the led
myBot.sendMessage(msg.sender.id, "WHITE Light is now OFF"); // notify the sender
}
else { // otherwise...
// generate the message for the sender
String reply;
reply = (String)"Welcome " + msg.sender.username + (String)". Try LIGHT ON or LIGHT OFF.";
myBot.sendMessage(msg.sender.id, reply); // and send it
}
}
// wait 500 milliseconds
delay(500);
}
我們希望您喜歡這個項目。此外,請查看我們網站上有關 Arduino和Raspberry Pi的教程。
學習愉快!
- 節(jié)日花環(huán)自動化開源項目
- 樹莓派家庭自動化開源
- Arduino迷你電報機
- 溫室自動化開源硬件
- 基于ESP8266的電報機器人 0次下載
- 家庭自動化開源案例
- 照明自動化開源分享
- 濾光輪自動化開源項目
- 帶有ESP8266的電報機器人
- 植物澆水自動化開源分享
- 自動刷牙機器人開源分享
- ESP32家庭自動化開源分享
- 家庭自動化開源分享
- PCB家庭自動化開源分享
- 機器人自動化開展應用資料包 0次下載
- 自動化焊接機器人:引領制造業(yè)未來的高效工具 1227次閱讀
- 工業(yè)機器人、PLC與自動化之間的關系 1460次閱讀
- PLC與機器人之間如何通訊 4480次閱讀
- 如何使用PLC控制機器人 1883次閱讀
- 運動控制和機器人系統(tǒng)有什么區(qū)別 603次閱讀
- 聯網自動駕駛機器人的網絡安全 406次閱讀
- 面對疫情 醫(yī)療機器人能幫上什么忙? 2236次閱讀
- 真空潔凈機器人 6354次閱讀
- 四軸機器人和六軸機器人有什么區(qū)別? 2.9w次閱讀
- 工業(yè)機器人、PLC與自動化三者之間有什么關系? 1.7w次閱讀
- 大族Star機器人用于工業(yè)自動化的特點及優(yōu)勢介紹 3000次閱讀
- 如何制作一個簡易有線電報機? 5.2w次閱讀
- 機器人自動噴涂系統(tǒng)淺談 1.7w次閱讀
- 機器人自動化工程項目方案設計包括的6個步驟解析 1.3w次閱讀
- 智能救援機器人的設計解析 3403次閱讀
下載排行
本周
- 1DD3118電路圖紙資料
- 0.08 MB | 1次下載 | 免費
- 2AD庫封裝庫安裝教程
- 0.49 MB | 1次下載 | 免費
- 3PC6206 300mA低功耗低壓差線性穩(wěn)壓器中文資料
- 1.12 MB | 1次下載 | 免費
- 4網絡安全從業(yè)者入門指南
- 2.91 MB | 1次下載 | 免費
- 5DS-CS3A P00-CN-V3
- 618.05 KB | 1次下載 | 免費
- 6海川SM5701規(guī)格書
- 1.48 MB | 次下載 | 免費
- 7H20PR5電磁爐IGBT功率管規(guī)格書
- 1.68 MB | 次下載 | 1 積分
- 8IP防護等級說明
- 0.08 MB | 次下載 | 免費
本月
- 1貼片三極管上的印字與真實名稱的對照表詳細說明
- 0.50 MB | 103次下載 | 1 積分
- 2涂鴉各WiFi模塊原理圖加PCB封裝
- 11.75 MB | 89次下載 | 1 積分
- 3錦銳科技CA51F2 SDK開發(fā)包
- 24.06 MB | 43次下載 | 1 積分
- 4錦銳CA51F005 SDK開發(fā)包
- 19.47 MB | 19次下載 | 1 積分
- 5PCB的EMC設計指南
- 2.47 MB | 16次下載 | 1 積分
- 6HC05藍牙原理圖加PCB
- 15.76 MB | 13次下載 | 1 積分
- 7802.11_Wireless_Networks
- 4.17 MB | 12次下載 | 免費
- 8蘋果iphone 11電路原理圖
- 4.98 MB | 6次下載 | 2 積分
總榜
- 1matlab軟件下載入口
- 未知 | 935127次下載 | 10 積分
- 2開源硬件-PMP21529.1-4 開關降壓/升壓雙向直流/直流轉換器 PCB layout 設計
- 1.48MB | 420064次下載 | 10 積分
- 3Altium DXP2002下載入口
- 未知 | 233089次下載 | 10 積分
- 4電路仿真軟件multisim 10.0免費下載
- 340992 | 191390次下載 | 10 積分
- 5十天學會AVR單片機與C語言視頻教程 下載
- 158M | 183342次下載 | 10 積分
- 6labview8.5下載
- 未知 | 81588次下載 | 10 積分
- 7Keil工具MDK-Arm免費下載
- 0.02 MB | 73815次下載 | 10 積分
- 8LabVIEW 8.6下載
- 未知 | 65989次下載 | 10 積分
評論