앱인벤터로 아두이노 우노에 설치된 DHT11 온습도 센서 데이터를 HC-06 블루투스 센서 보드에 의해서 안드로이드 폰에서 수신해 보자.
Let's receive data of DHT11 temperature and humidity sensor installed in Arduino with HC-06 Bluetooth board using App on Android phone.
필요한 준비물은 아래와 같다.
안드로이드 스마트 폰; HC-06 아두이노 블루투스 센서 보드 X 1
아두이노 우노 보드 X 1; DHT11 온습도 센서X1; 점퍼선 7개
The necessary preparations are as follows.
Android smartphone
HC-06 Arduino Bluetooth sensor board X 1
Adu Uno Board X 1
DHT11 temperature and humidity sensor X1;
7 jumper wires
아두이노 우노 블루투스 배선
HC-06의 2개의 블루투스 데이터 선은 RX 와 TX 이다. 아두이노 보드의 (0,1)은 코드를 업로딩할 때 사용하기 때문에 점퍼 선을 뺏다 끼웠다 하기 대단히 불편하므로 SoftwareSerial.h 라이브러리에 의해 (2,3)을 사용하기로 한다.
Arduino Uno Bluetooth Wiring
Two Bluetooth data lines of HC-06 are RX and TX. Since #0 and #1 digital pins of the Arduino board are used when uploading the code, it is very inconvenient to frequently remove the jumper wire, so we will use #2 and #3 digital pins by the SoftwareSerial.h library.
클라스 선언을 통해 BTSerial (2,3)으로 선언한다. 블루투스 센서 보드의 TX 가 아두이노 우노에서는 RX 인 2번으로 매칭된다. 마찬가지로 블루투스 센서 보드의 RX는아두이노 우노에서 TX 인 3번으로 매칭된다. DHT11 온습도 센서는 디지털 데이터 핀 5번에 설치하기로 한다. PC와의 통신은 9600 블루투스 통신속도 또한 9600 으로 설정한다. 블루투스 센서 보드 규격에 따라 좀 더 높은 속도 설정도 가능하다.
Declare it as BTSerial (2,3) through class declaration. The TX of the Bluetooth board is matched to the RX 2 in Adunino. Likewise, the RX of the Bluetooth board is matched to TX 3 in Arduino Uno. DHT11 temperature and humidity sensor shall be installed on digital data pin #5. For communication with Desktop PC, 9600 Bluetooth communication speed is also set to 9600. Depending on the Bluetooth board specification, higher speed settings are also possible.
스마트 폰 블루투스 등록 과정은 사용가능한 디바이스를 잧는 것으로 시작된다.
Bluetooth device registration:
you have to look for HC-06 BT board. After found it, input "1234'.
만약 아두이노 C/C++ 은 익숙하지만 App Inventor 코드 작업이 어려운 분들은 구글 Paly Store에서 직접 BT_DHT11 App을 다운받아 사용하셔도 됩니다.
If you are not familiar to coding app inventor, you can download app from google play store, and may skip app inventor coding as follows. Just operate Arduino board with HC-06 bluetooth board and DHT11 sensor. Necessary Arduino code was attatched at the tail. Copy and paste it to your Arduino IDE. Compile upload it. additionally you have to do pairing with your Android smartphone.
앱인벤터 코딩 디자인 블록
App InventorII coding in Design Stage:
파레트의 User Interface에서 ListPicker 1개, 수평배열용 레이아웃 1개, 라벨 1개, Connectivity에서 BluetoothClient 1개, Clock 1개를 사용한다.
We use one ListPicker of User Interface in Palette with horizontal layout, one Label, in additino to a Bluetooth Client from Connectivity, and one Clock.
ListPicker를 Viewer Screen1 에 드래그한 후 속성 창에서 Text 입력 박스에 DHT11을 입력한다. center, bold를 포함하는 폰트 세부 정보를 입력 하고 Width 항목에서 Fill parent를 선택하면 화면에서 자동적으로 수평 한 줄을 차지하게 된다.
Layout의 HorizontalArrangement를 드래그 하고 라벨 1개를 선택해 드래그 해 넣고 텍스트 명을 Temp & Humidity 로 해 둔다.
Drag the item of ListPicker from palette to Viewer Screen1 and enter DHT11 in the Text input box in the Properties window.
Enter the font details including center and bold, and select Fill parent in the Width field to automatically take a horizontal line on the screen.
Drag the HorizontalArrangement of the Layout, select one label and drag it, and set the text name to Temp & Humidity.
앱인벤터 블록 편집
App Inventor II Block Editing
ListPicker 는 블루투스 사용 시에 터치 이전과 이후에 Address 와 명칭을 처리하는 데 사용된다.
DHT11 이라는 이름의 ListPicker1은 픽(Pick) 전에 블루투스 클라이언트로서 주소와 이름을 갖는다. Pick 후에는 그 주소와 이름으로 블루투스를 통해 외부 아두이노 우노의 HC-06과 연결(Connect) 한다. 이때 필요한 주소와 이름을 ListPicker1로부터 제공 받는다.
ListPicker is used to process addresses and names before and after we touch the smalrtphone screen when using Bluetooth.
ListPicker1 named DHT11 has the address and name as a Bluetooth client before pick. After picking, connect
to HC-06 of external Adunino Uno board via Bluetooth by its address and name. At this time, ListPicker1
receives the required address and name.
블루투스가 연결되면 ListPicker1의 DHT11 이 Connected with DHT11 로 바뀐다. 연결된 상태에서 타이머가 작동하며 아두이노 우노에서 2초에 한번씩 샘플된 온습도 데이터가 다수의 바이트 데이터를 한 묶음으로 구성하여 수신된다.
묶음 데이터 구성 방식은 “temperature”+측정된 온도 값+“ C deg” 까지를 블루투스에 출력한 후 줄 바꿈 한다. 이어서 “Humidity: ”+측정된 습도 값+“ %” 까지를 출력한다. 이 2개의 데이터를 합한 정보가 안드로이드 폰에서 다수의 바이트들로 구성된 1개 단위의 정보로 수신되어 2줄로 출력된다.
When Bluetooth is connected, DHT11 in ListPicker1 changes to Connected with DHT11. The timer operates in the connected state, and the temperature and humidity data sampled every 2 seconds in the Aduino board are received by making up a bundle of multiple bytes of data.
The bundled data configuration method is to output "temperature" + measured temperature value + "C deg" to Bluetooth and wrap. Then "Humidity:" + measured humidity value + "%" is output. The combined information of the two data is received as one unit of information composed of a plurality of bytes in the Android phone and output in two lines.
앱인벤터를 실행해 보자.
Run App Inventor Code!
appinventor_BT_LEDONOFF_DHT11_01
#include <SoftwareSerial.h>
#include <DHT11.h>
SoftwareSerial BTSerial(2,3);//(RX,TX)
int LED = 13;
int pin=5;
DHT11 dht11(pin);
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(LED,OUTPUT);
}
void loop() {
int err;
float temp, humi;
if((err=dht11.read(humi, temp))==0) {
Serial.print("temperature:");
Serial.println(temp);
BTSerial.print("Temperature:" );
BTSerial.print(temp,0);
BTSerial.println(" C deg");
Serial.print(" humidity:");
Serial.print(humi);
BTSerial.print("Humidity: " );
BTSerial.print(humi,0);
BTSerial.print(" %");
Serial.println();
}
else {
Serial.println();
Serial.print("Error No :");
Serial.print(err);
Serial.println();
}
delay(2000);
}//끝
'앱 인벤터 appinventor' 카테고리의 다른 글
Cactus Micro ESP8266WiFi 클라이언트 ThingSpeak 코딩: II (0) | 2018.06.23 |
---|---|
아날로그 시계 앱인벤터 코딩 (0) | 2018.03.21 |
앱인벤터와 아두이노 HC-06 블루투스에 의한 DHT22 온습도 모니터링 (0) | 2018.02.12 |
앱 인벤터와 아두이노 HC-06 블루투스에 의한 DHT11 온습도 모니터(Arduino HC-06 Bluetooth DHT11 Temp Humidty Monitoring) (0) | 2018.01.10 |
NodeMCU 웹서버 Login 웹뷰어 앱인벤터 코딩 (0) | 2017.11.23 |