BASIC4MCU | 질문게시판 | 답변 : 아두이노 블루투스 온습도 휴대폰 출력
페이지 정보
작성자 master 작성일2018-10-01 11:35 조회11,168회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=3290
본문
//#include <SoftwareSerial.h>#define BT_RXD 10#define BT_TXD 11SoftwareSerial bluetooth(BT_RXD,BT_TXD);//#include "DHT.h"#define DHTPIN 2#define DHTTYPE DHT11DHT dht(DHTPIN,DHTTYPE);//int h=0,t=0;int cnt=0,r;//void setup(){Serial.begin(9600);bluetooth.begin(9600);}//void loop(){delay(10);if(++cnt>300){ cnt=0; // 3초마다 온습도를 읽음h=dht.readHumidity();t=dht.readTemperature();}//if(bluetooth.available()){r=bluetooth.read();Serial.write(r);if(r=='H'){Serial.print("Humidity: "); Serial.print(h); Serial.print("%\t");bluetooth.print("Humidity: "); bluetooth.print(h); bluetooth.print("%\t");}if(r=='T'){Serial.print("Temperature: "); Serial.print(t); Serial.println(" C");bluetooth.print("Temperature: "); bluetooth.print(t); bluetooth.println(" C");}}}
휴대폰에서 'H'를 전송하면 습도를 출력하고
'T'를 전송하면 온도를 출력합니다.
댓글 0
조회수 11,168등록된 댓글이 없습니다.