資料介紹
描述
只需發(fā)短信即可連接到這個(gè)智能恒溫器,無(wú)需額外的儀表板或平臺(tái)。
了解電報(bào)機(jī)器人
Telegram 提供了一組超級(jí)有用的 API ?,您可以在項(xiàng)目中使用。
您可以在 Arduino 板上托管一個(gè)機(jī)器人,并使用一個(gè)名為?Telegram Bot的簡(jiǎn)單庫(kù)與它聊天。您可以通過(guò) Arduino 桌面 IDE 中的庫(kù)管理器安裝此庫(kù),或者通過(guò)在Arduino Web 編輯器上導(dǎo)入 .Zip 文件來(lái)安裝此庫(kù)。
您可以在此處了解有關(guān)如何在 MKR1000 上管理 Telegram Bot 的所有?信息。在本教程?中,我們將跳過(guò)這一步,但您將看到如何在最終代碼中實(shí)現(xiàn) Telegram 機(jī)器人。
時(shí)間管理
這個(gè)恒溫器允許你編程一整周并循環(huán)它。
為此,恒溫器發(fā)出 UDP 調(diào)用并使用接收到的數(shù)據(jù)來(lái)設(shè)置實(shí)時(shí)時(shí)鐘 (RTC)。
安裝?RTCZero?和WiFi101庫(kù)?并上傳此草圖以測(cè)試此功能。
#include
#include
#include
#include
RTCZero rtc;
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
// Initialize Wifi connection to the router
char ssid[] = "xxxx"; // your network SSID (name)
char pass[] = "yyyy"; // your network key
WiFiSSLClient client;
unsigned long epoch;
unsigned int localPort = 2390; // local port to listen for UDP packets
IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
void setup() {
Serial.begin(115200);
// attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
rtc.begin();
GetCurrentTime();
}
void loop() {
Serial.print("Unix time = ");
Serial.println(rtc.getEpoch());
// Print date...
Serial.print(rtc.getDay());
Serial.print("/");
Serial.print(rtc.getMonth());
Serial.print("/");
Serial.print(rtc.getYear());
Serial.print("\t");
// ...and time
print2digits(rtc.getHours());
Serial.print(":");
print2digits(rtc.getMinutes());
Serial.print(":");
print2digits(rtc.getSeconds());
Serial.println();
delay(1000);
}
void print2digits(int number) {
if (number < 10) {
Serial.print("0");
}
Serial.print(number);
}
void GetCurrentTime() {
int numberOfTries = 0, maxTries = 6;
do {
epoch = readLinuxEpochUsingNTP();
numberOfTries++;
}
while ((epoch == 0) || (numberOfTries > maxTries));
if (numberOfTries > maxTries) {
Serial.print("NTP unreachable!!");
while (1);
}
else {
Serial.print("Epoch received: ");
Serial.println(epoch);
rtc.setEpoch(epoch);
Serial.println();
}
}
unsigned long readLinuxEpochUsingNTP()
{
Udp.begin(localPort);
sendNTPpacket(timeServer); // send an NTP packet to a time server
// wait to see if a reply is available
delay(1000);
if ( Udp.parsePacket() ) {
Serial.println("NTP time received");
// We've received a packet, read the data from it
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
// now convert NTP time into everyday time:
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
Udp.stop();
return (secsSince1900 - seventyYears);
}
else {
Udp.stop();
return 0;
}
}
// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(IPAddress & address)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
保存設(shè)置
當(dāng)然你不希望你的恒溫器在每次關(guān)閉時(shí)都忘記它的設(shè)置:)
為避免此問(wèn)題,您可以使用FlashStorage庫(kù)將數(shù)據(jù)存儲(chǔ)在電路板的閃存中。
在這種特殊情況下,我們使用此功能來(lái)存儲(chǔ) 7 天 7*24 小時(shí)的結(jié)構(gòu),以及所需溫度的值。
上傳此示例以測(cè)試此功能。
/*
Store and retrieve an integer value in Flash memory.
The value is increased each time the board is restarted.
This example code is in the public domain.
Written 30 Apr 2015 by Cristian Maglie
*/
#include
// Reserve a portion of flash memory to store an "int" variable
// and call it "my_flash_store".
FlashStorage(my_flash_store, int);
// Note: the area of flash memory reserved for the variable is
// lost every time the sketch is uploaded on the board.
void setup() {
SERIAL_PORT_MONITOR.begin(9600);
int number;
// Read the content of "my_flash_store" and assign it to "number"
number = my_flash_store.read();
// Print the current number on the serial monitor
SERIAL_PORT_MONITOR.println(number);
// Save into "my_flash_store" the number increased by 1 for the
// next run of the sketch
my_flash_store.write(number + 1);
}
void loop() {
// Do nothing...
}
從傳感器讀取值
在這個(gè)項(xiàng)目中,我們使用可以檢測(cè)濕度和溫度的 DHT 傳感器。這個(gè)傳感器有自己的庫(kù),你可以?在這里下載。
由于草圖實(shí)現(xiàn)了許多功能,我們將其組織在不同的選項(xiàng)卡中,以下這些代碼片段指的是傳感器。
在 Config 選項(xiàng)卡中,我們聲明傳感器的類:
//#define USE_fahrenheit true // Uncomment this to use Fahrenheit insted of Celsius
class Sensor {
public:
Sensor(void);
void begin();
bool ReadSensors();
float GetTemp();
float GetHumidity();
private:
float t;
float f;
float h;
};
extern Sensor DHTSensor;
?
在另一個(gè)選項(xiàng)卡中,我們定義了傳感器類:
#include "DHT.h"
#include "config.h"
DHT dht(DHTPIN, DHTTYPE);
Sensor::Sensor(void) {
}
bool Sensor::ReadSensors() {
h = dht.readHumidity();
t = dht.readTemperature(); // Read temperature as Celsius (the default)
f = dht.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true)
if (isnan(h) || isnan(t) || isnan(f)) { // Check if any reads failed and exit early (to try again).
Serial.println("Failed to read from DHT sensor!");
return false;
}
return true;
}
void Sensor::begin() {
dht.begin();
}
float Sensor::GetTemp() {
#ifdef USE_fahrenheit
return f;
#else
return t;
#endif
}
float Sensor::GetHumidity() {
return h;
}
硬件組件和庫(kù)
現(xiàn)在您可以開(kāi)始連接恒溫器了。考慮到 LCD 顯示器需要GFX和?ST7735庫(kù),而 DHT 傳感器需要 ?DHT-sensor-library。?
- 使用邏輯和轉(zhuǎn)換用例優(yōu)化智能恒溫器的設(shè)計(jì)
- 智能恒溫器開(kāi)源項(xiàng)目
- 溫差恒溫器開(kāi)源硬件
- 使用螺栓的恒溫器
- 模塊化WiFi智能恒溫器的構(gòu)建
- Arduino供電恒溫器和風(fēng)扇控制器 0次下載
- 智能恒溫器開(kāi)源案例
- 迷你恒溫器開(kāi)源分享
- 恒溫器開(kāi)源分享
- 如何使用固態(tài)繼電器驅(qū)動(dòng)恒溫器
- 恒溫器TH32開(kāi)源分享
- 恒溫器Lm358 tl494 21 clima開(kāi)源項(xiàng)目
- 烙鐵恒溫器電路圖 34次下載
- 恒溫器控制電路原理圖免費(fèi)下載 11次下載
- 2017全球WiFi恒溫器市場(chǎng)發(fā)展現(xiàn)狀及趨勢(shì)研究 4次下載
- 使用MOSFET作為恒溫加熱器 1489次閱讀
- 如何制作一個(gè)通過(guò)本地WiFi網(wǎng)絡(luò)瀏覽器進(jìn)行控制的恒溫器 2091次閱讀
- 恒溫加熱器的工作原理_恒溫加熱器保養(yǎng) 1.8w次閱讀
- 智能家居安全隱患有哪些_智能家居不為人知的恐怖一面_使用智能家居應(yīng)注意什么 4350次閱讀
- 恒溫電烙鐵及焊接知識(shí) 3211次閱讀
- 用NE555設(shè)計(jì)的恒溫控制器的方案 8012次閱讀
- 電子恒溫器 4290次閱讀
- 用于植物的土壤加熱器 3964次閱讀
- 小型恒溫控制器 2637次閱讀
- 魚(yú)缸電子恒溫器電路圖 3610次閱讀
- 雙線遙控交流電子恒溫器電路圖 2286次閱讀
- 三線電子恒溫器電路圖 6199次閱讀
- 智能恒溫控制電路 3526次閱讀
- 實(shí)用的恒溫控制器電路圖 4143次閱讀
- 家用恒溫控制器電路圖 4473次閱讀
下載排行
本周
- 1山景DSP芯片AP8248A2數(shù)據(jù)手冊(cè)
- 1.06 MB | 532次下載 | 免費(fèi)
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費(fèi)
- 3TC358743XBG評(píng)估板參考手冊(cè)
- 1.36 MB | 330次下載 | 免費(fèi)
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費(fèi)
- 5元宇宙深度解析—未來(lái)的未來(lái)-風(fēng)口還是泡沫
- 6.40 MB | 227次下載 | 免費(fèi)
- 6迪文DGUS開(kāi)發(fā)指南
- 31.67 MB | 194次下載 | 免費(fèi)
- 7元宇宙底層硬件系列報(bào)告
- 13.42 MB | 182次下載 | 免費(fèi)
- 8FP5207XR-G1中文應(yīng)用手冊(cè)
- 1.09 MB | 178次下載 | 免費(fèi)
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 2555集成電路應(yīng)用800例(新編版)
- 0.00 MB | 33566次下載 | 免費(fèi)
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費(fèi)
- 4開(kāi)關(guān)電源設(shè)計(jì)實(shí)例指南
- 未知 | 21549次下載 | 免費(fèi)
- 5電氣工程師手冊(cè)免費(fèi)下載(新編第二版pdf電子書(shū))
- 0.00 MB | 15349次下載 | 免費(fèi)
- 6數(shù)字電路基礎(chǔ)pdf(下載)
- 未知 | 13750次下載 | 免費(fèi)
- 7電子制作實(shí)例集錦 下載
- 未知 | 8113次下載 | 免費(fèi)
- 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德?tīng)栔?/a>
- 0.00 MB | 6656次下載 | 免費(fèi)
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費(fèi)
- 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
- 78.1 MB | 537798次下載 | 免費(fèi)
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費(fèi)
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費(fèi)
- 6電路仿真軟件multisim 10.0免費(fèi)下載
- 340992 | 191187次下載 | 免費(fèi)
- 7十天學(xué)會(huì)AVR單片機(jī)與C語(yǔ)言視頻教程 下載
- 158M | 183279次下載 | 免費(fèi)
- 8proe5.0野火版下載(中文版免費(fèi)下載)
- 未知 | 138040次下載 | 免費(fèi)
評(píng)論