本帖最後由 ted 於 2017-1-3 23:13 編輯
有參考超音波傳輸 但THD11用的是函式庫 所以不一樣?
還是我的想法錯了?
可以直接只傳數值到Android?
還是程式碼傳送資料那裏該怎麼改?
藍芽模組式HC-06
程式碼:
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#define dht_dpin A0 //定義訊號要從Pin A0 進來
dht DHT;
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
SoftwareSerial I2CBT(10,11); // RX TX 對應腳
byte serialA;
void setup(){
Serial.begin(9600);
delay(300); //Let system settle
Serial.println("Humidity and temperature\n\n");
delay(700); //Wait rest of 1000ms recommended delay before
//accessing sensor
//Serial.begin(9600);
lcd.begin(16,2);
Serial.println("Mohamed Chaara Temp and Humidity Sensor Test");
//pinMode(10,INPUT); //define pin modes for tx,rx pin
//pinMode(11,OUTPUT);
I2CBT.begin(9600); //與藍牙發射器的鮑率為 9600
}
void loop(){
DHT.read11(dht_dpin); //去library裡面找DHT.read11
Serial.print("Humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(700); //每1000ms更新一次
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print("C");
// set the cursor to (16,1):
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
byte Data[3];
byte cmmd[20];
int insize;
char str[256];
int i=analogRead(A0);//read sensor value
serialA=I2CBT.read();
Data[0]='z';
Data[1]=i/256;
Data[2]=i%256;
sprintf(str,"i: %d 0: %d 1: %d 2: %d",i,Data[0],Data[1],Data[2]);
Serial.println(str);
if (serialA == 87){
for(int j=0;j<3;j++)
I2CBT.write(Data[j]);
serialA=0;
}
delay(100);
} |