에듀이노-코딩교육 전문 쇼핑몰 에듀이노-코딩교육 전문 쇼핑몰

학교, 공공기관이라면 후불결제하세요!

 
현재 위치
  1. 게시판
  2. 묻고답하기

묻고답하기

상품 게시판 상세
제목 예제 실행문제
작성자 임강현 (ip:)
  • 작성일 2021-02-23
  • 추천 추천하기
  • 조회수 139

온습도센서 dht22를 사용해 예제를 실행해 보았습니다.

dht22센서는 따로 온습도 측정이 작동되는걸 확인했습니다.


#include <DHT.h>

#define DHTPIN A2

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

 

#include <Wire.h>

#include <SPI.h>

#include <Ethernet.h>

 

byte mac[] = {  0x74, 0x69, 0x69, 0x2D, 0x30, 0x5};

IPAddress ip;

// IP 주소는 " XXX,XXX,XXX,XXX " ',' 주의해주세요.

// 이더넷 라이브러리 초기화

// 사용할 IP 주소 와 포트 입력

// ('port 80' 은 HTTP 의 기본 값 입니다.):

EthernetServer server(80);

 

void client();

 

void setup() {

 

 

  // Open serial communications and wait for port to open:

  Serial.begin(9600);

  while (!Serial) {

    ; // 포트 연결까지 기다리기. 레오나르도에만 필요합니다.

  }

 

  // 이더넷 서버 연결 시작:

  Ethernet.begin(mac, ip);

  server.begin();

 

  Serial.print("server is at ");

  Serial.println(Ethernet.localIP());

}

 

 

void loop() {

 

  EthernetClient client = server.available();

  if (client) {

    Serial.println("new client");

    // an http request ends with a blank line

    boolean currentLineIsBlank = true;

    while (client.connected()) {

      if (client.available()) {

        char c = client.read();

        Serial.write(c);

        // if you've gotten to the end of the line (received a newline

        // character) and the line is blank, the http request has ended,

        // so you can send a reply

        if (c == '\n' && currentLineIsBlank) {

          // send a standard http response header

          client.println("HTTP/1.1 200 OK");

          client.println("Content-Type: text/html");

          client.println("Connnection: close");

          client.println();

          client.println("<!DOCTYPE HTML>");

          client.println("<html>");

          // 브라우저 5초마다 새로고침

          client.print("<meta http-equiv=\"refresh\" content=/\"5\"/>");

          client.println("<title>");

          client.print("Welcome EDUINO");

          client.println("</title>");

 

          int h = dht.readHumidity();

          int t = dht. readTemperature();

 

          // 온습도센서(DHT-22)로부터 값 출력

          client.println("<center>");

          client.println("<h1>");

          client.print("EDUINO Office");

          client.println("</h1>");

          client.println("<h2>");

          client.print("Office Temperature and Humidity");

          client.println("</h2>");

          client.println("<h4>");

          client.print("Temperature : ");

          client.print(t);

          client.print("<sup>0</sup>");

          client.print("C");

          client.println("<br />");

          client.print("Humidity : ");

          client.print(h);

          client.print("%");

          client.println("</h4>");

          client.println("</center>");

 

          client.println("</html>");

          break;

        }

        if (c == '\n') {

          currentLineIsBlank = true;

        }

        else if (c != '\r') {

          currentLineIsBlank = false;

        }

      }

    }

    //브라우저 데이터 받는 시간

    delay(1);

    //연결 종료:

    client.stop();

    Serial.println("client disonnected");

  }

}

dht11 적힌부븐은 dht22fh 바꿔진행했고 

아래 질문 답변 참고하여 

  1. 온습도 출력하는 이더넷 쉴드 코드 61번째 줄 client.print("<meta http-equiv="refresh" content="5">"); 를 client.print("<meta http-equiv=\"refresh\" content=\"5\">"); 로 변경하여 확인였는데
  2.  온습도값이 계속 0으로 표시되는 현상이 발생하여 문의 남깁니다.
평점 0점
첨부파일
비밀번호 삭제하려면 비밀번호를 입력하세요.
댓글 수정

비밀번호 :

수정 취소

/ byte

비밀번호 : 확인 취소

댓글 입력

댓글달기이름 :비밀번호 : 관리자답변보기

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

에게만 댓글 작성 권한이 있습니다.

댓글 입력

댓글달기이름 :비밀번호 :

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

에게만 댓글 작성 권한이 있습니다.

«
»