본문 바로가기

IOT(Arduino+Inventor)

esp-01 DHT11 Sensor[4]

온도와 습도를 측정하여 , 스마트폰에서  ESP-1아 주어지는 IP애 접속하여 확인 할 수 있습니다. 

전원은 솔라 전원을 이용하면 편리 합니다.

 

ESP01 WiFi 8266

  • DHT11 : 온도, 습도
  • 구동전원  DC 3.7V-5V 
  • 측정범위 습도 20-90% RH  온도 0-50 ℃,
  • 실제 측정 오차 온도 ± 2 ℃, 습도   ± 5% RH.
  •  

시중에 판매되는 모듈

준비물 : 아두이노 우노, 브래드 보드, ESP-01, ESP 어덥터, 점프선

Arduino Uno ESP01
TX TX
RX RX
5V Vcc
GND GND
RES--GND  
  GPIO0--GND
  CHPD--Vcc
  RST--Vcc

아래 소스를 업로드 합니다. 그리고 센서를 연결합니다.

시리얼 모니터 실행을 위해서는 

아두이노 RES-- GND,

ESP-01에서 RST-Vcc, GPIO0--GND를 제거  합니다.

그리고 시리얼 모니터에서 IP확인을 할 때는 

ESP=01를 제거 후 다시 끼웁니다.

#include <ESP8266WiFi.h>
#include <DHT.h>

#define DHTPIN 2        // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);

const char* ssid     = "IOT999"; // Your ssid
const char* password = "kbs48752"; // Your Password
WiFiServer server(80);

void setup() {
  
// Start DHT11  
dht.begin();  
Serial.begin(115200);
delay(10);
Serial.println();

// Connect to WiFi network
WiFi.mode(WIFI_STA);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());
}

void loop() {

 float h = dht.readHumidity();
 float t = dht.readTemperature(); // Read temperature as Celsius (the default)
 //float f = dht.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true)

// Check if any reads failed and exit early (to try again).
 if (isnan(h) || isnan(t)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
 }
   
 Serial.print("Humidity % : ");
 Serial.println(h);
 Serial.print("Temperature *C: ");
 Serial.println(t);
 //Serial.print("Temperature *F: ");
 //Serial.println(f);

WiFiClient client = server.available();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");  // the connection will be closed after completion of the response
client.println("Refresh: 5");  // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE html>");
client.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
client.println("<head>\n<meta charset='UTF-8'>");
client.println("<title>ESP8266 Temperature & Humidity DHT11 Sensor</title>");
client.println("</head>\n<body>");
client.println("<H2>ESP8266 & DHT11 Sensor</H2>");
client.println("<H3>Humidity / Temperature</H3>");
client.println("<pre>");
client.print("Humidity (%)         : ");
client.println((float)h, 2);
client.print("Temperature (°C)  : ");
//client.println((float)t, 2);
//client.print("Temperature (°F)  : ");
//client.println((float)f, 2);
//client.print("Temperature (°K)  : ");
//client.println(Kelvin(temp), 2);
client.println("</pre>");
client.println("<H3>www.Circuits-DIY.com</H3>");
client.print("</body>\n</html>");
delay(2000);
}

 

 

 

 

'IOT(Arduino+Inventor)' 카테고리의 다른 글

esp-01S Relay[5]  (0) 2023.04.12
ESP-01, DHT11, ThingSpeak [5]  (0) 2023.04.11
ESP-01 LED Control[3]  (0) 2023.03.25
ESP-01 AT Commands[2]  (0) 2023.03.24
ESP-01 Firmware[01]  (0) 2023.03.23