那曲檬骨新材料有限公司

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
電子發燒友網>電子資料下載>電子資料>智能恒溫器開源分享

智能恒溫器開源分享

2022-11-16 | zip | 0.32 MB | 次下載 | 2積分

資料介紹

描述

只需發短信即可連接到這個智能恒溫器,無需額外的儀表板或平臺。

了解電報機器人

Telegram 提供了一組超級有用的 API ?,您可以在項目中使用。

您可以在 Arduino 板上托管一個機器人,并使用一個名為?Telegram Bot的簡單庫與它聊天您可以通過 Arduino 桌面 IDE 中的庫管理器安裝此庫,或者通過在Arduino Web 編輯器上導入 .Zip 文件來安裝此庫

您可以在此處了解有關如何在 MKR1000 上管理 Telegram Bot 的所有?信息在本教程?中,我們將跳過這一步,但您將看到如何在最終代碼中實現 Telegram 機器人。

時間管理

這個恒溫器允許你編程一整周并循環它。

為此,恒溫器發出 UDP 調用并使用接收到的數據來設置實時時鐘 (RTC)。

安裝?RTCZero?和WiFi101?并上傳此草圖以測試此功能。


#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();
}

保存設置

當然你不希望你的恒溫器在每次關閉時都忘記它的設置:)

為避免此問題,您可以使用FlashStorage庫將數據存儲在電路板的閃存中。

在這種特殊情況下,我們使用此功能來存儲 7 天 7*24 小時的結構,以及所需溫度的值。

上傳此示例以測試此功能。


/*
  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...
}

傳感器讀取值

在這個項目中,我們使用可以檢測濕度和溫度的 DHT 傳感器。這個傳感器有自己的庫,你可以?在這里下載

由于草圖實現了許多功能,我們將其組織在不同的選項卡中,以下這些代碼片段指的是傳感器。

在 Config 選項卡中,我們聲明傳感器的類:

//#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;

?

在另一個選項卡中,我們定義了傳感器類:

#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;
}

硬件組件和庫

現在您可以開始連接恒溫器了。考慮到 LCD 顯示器需要GFX和?ST7735庫,而 DHT 傳感器需要 ?DHT-sensor-library。?


評論

查看更多

下載排行

本周

  1. 1A7159和A7139射頻芯片的資料免費下載
  2. 0.20 MB   |  55次下載  |  5 積分
  3. 2PIC12F629/675 數據手冊免費下載
  4. 2.38 MB   |  36次下載  |  5 積分
  5. 3PIC16F716 數據手冊免費下載
  6. 2.35 MB   |  18次下載  |  5 積分
  7. 4dsPIC33EDV64MC205電機控制開發板用戶指南
  8. 5.78MB   |  8次下載  |  免費
  9. 5STC15系列常用寄存器匯總免費下載
  10. 1.60 MB   |  7次下載  |  5 積分
  11. 6模擬電路仿真實現
  12. 2.94MB   |  4次下載  |  免費
  13. 7PCB圖繪制實例操作
  14. 2.92MB   |  2次下載  |  免費
  15. 8零死角玩轉STM32F103—指南者
  16. 26.78 MB   |  1次下載  |  1 積分

本月

  1. 1ADI高性能電源管理解決方案
  2. 2.43 MB   |  452次下載  |  免費
  3. 2免費開源CC3D飛控資料(電路圖&PCB源文件、BOM、
  4. 5.67 MB   |  141次下載  |  1 積分
  5. 3基于STM32單片機智能手環心率計步器體溫顯示設計
  6. 0.10 MB   |  137次下載  |  免費
  7. 4A7159和A7139射頻芯片的資料免費下載
  8. 0.20 MB   |  55次下載  |  5 積分
  9. 5PIC12F629/675 數據手冊免費下載
  10. 2.38 MB   |  36次下載  |  5 積分
  11. 6如何正確測試電源的紋波
  12. 0.36 MB   |  19次下載  |  免費
  13. 7PIC16F716 數據手冊免費下載
  14. 2.35 MB   |  18次下載  |  5 積分
  15. 8Q/SQR E8-4-2024乘用車電子電器零部件及子系統EMC試驗方法及要求
  16. 1.97 MB   |  8次下載  |  10 積分

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935121次下載  |  10 積分
  3. 2開源硬件-PMP21529.1-4 開關降壓/升壓雙向直流/直流轉換器 PCB layout 設計
  4. 1.48MB  |  420062次下載  |  10 積分
  5. 3Altium DXP2002下載入口
  6. 未知  |  233088次下載  |  10 積分
  7. 4電路仿真軟件multisim 10.0免費下載
  8. 340992  |  191367次下載  |  10 積分
  9. 5十天學會AVR單片機與C語言視頻教程 下載
  10. 158M  |  183335次下載  |  10 積分
  11. 6labview8.5下載
  12. 未知  |  81581次下載  |  10 積分
  13. 7Keil工具MDK-Arm免費下載
  14. 0.02 MB  |  73810次下載  |  10 積分
  15. 8LabVIEW 8.6下載
  16. 未知  |  65988次下載  |  10 積分
威尼斯人娱乐城首选大丰收| 百家乐的庄闲概率| 红树林百家乐的玩法技巧和规则 | 名人百家乐的玩法技巧和规则 | 棋牌游戏平台开发| 同花顺百家乐官网的玩法技巧和规则| 百家乐娱乐网备用网址| 百家乐官网网上投注代理商| 自贡百家乐官网娱乐场开户注册| 大发888娱乐城 手机版| 聚龍社百家乐官网的玩法技巧和规则 | 易胜博百家乐输| 皇冠网赌球安全吗| 怎样看百家乐路纸| 赌博百家乐官网经验网| 大发888娱乐场下载sampling id112| 自贡百家乐官网赌场娱乐网规则| 池州市| 大发888下载 17| 大发888真人关键词| 真人百家乐免费开户送钱| 百家乐官网视频游戏帐号| 大发888玩的人多吗| 易学24山3d罗盘App| 百家乐官网翻天腾讯视频| 博彩e族777| 唐人街百家乐的玩法技巧和规则| 百家乐数据程序| 百家乐官网赌博是否违法| 缙云县| 彩票预测| 二八杠怎么赢钱| 富二代百家乐的玩法技巧和规则| 百家乐视频官网| 菲律宾百家乐官网赌场娱乐网规则| 百家乐官网赌场策略大全| 南充市| 盈禾| 星空棋牌官方下载| 赌场| 天天百家乐官网游戏|