스마트폰으로 온도를 모니터링 합니다.
Components connection
ESP8266 | Sensor | |
3.3v | ![]() |
VDD |
SDA | ![]() |
D2 |
GND | ![]() |
GND |
CLA | ![]() |
D1 |
다음 소스를 Arduino IDE에서 upload 합니다.
#include <Arduino.h> #include <ESP8266WiFi.h> #include <Hash.h> #include <ESPAsyncTCP.h> #include <ESPAsyncWebServer.h> #include <Adafruit_Sensor.h> #include <Adafruit_AM2320.h> Adafruit_AM2320 am2320 = Adafruit_AM2320(); const char* ssid = "IOT999"; const char* password = "kbs48752"; float t = 0.0; float h = 0.0; AsyncWebServer server(80); unsigned long previousMillis = 0; const long interval = 10000; const char index_html[] PROGMEM = R"rawliteral( <!DOCTYPE HTML><html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <h2>ESP8266 AM2320 Server</h2> <p> Temperature <span id="temperature">%TEMPERATURE%</span> </p> </body> <script> setInterval(function ( ) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("temperature").innerHTML = this.responseText; } }; xhttp.open("GET", "/temperature", true); xhttp.send(); }, 10000 ) ; </script> </html>)rawliteral"; String processor(const String& var){ if(var == "TEMPERATURE"){ return String(t); } return String(); } void setup() { Serial.begin(115200); while (!Serial) { delay(10); } Serial.println("Adafruit AM2320 Basic Test"); am2320.begin(); WiFi.begin(ssid, password); Serial.println("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("."); } Serial.println(WiFi.localIP()); // web page server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor); }); server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/plain", String(t).c_str()); }); // Start server server.begin(); } void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { // save the last time you updated the AM20320values previousMillis = currentMillis; // Read temperature as Celsius (the default) float newT = am2320.readTemperature(); if (isnan(newT)) { Serial.println("Failed to read from AM2320 sensor!"); } else { //t = newT; //orror=-2; //temperature_offset=-2 t = newT-2; Serial.println(t); } } delay(2000); } |
ESP 8266 Board RTS 버튼 실행
Serial Monitor
PC moniter
deviation adjustment
온도게이지 1+2+3
16.3+16.3+16=48.6
48.6/3=16.2
16.50+16.60+16.70=49.80
49.8/3=16.6
16.6-16.2=0.4
오차 조정
const float temperature_offset =-0.4;
'IOT(Arduino+Inventor)' 카테고리의 다른 글
온도센서_AM2320_ESP8266_CSS_C (0) | 2023.03.06 |
---|---|
온도센서_AM2320_ESP8266_B (0) | 2023.03.06 |
WebServer Esp8266 (0) | 2022.11.06 |
서보 모터 제어[6] (0) | 2022.04.05 |
수은 기울기 센서[5] (0) | 2022.04.03 |