[實驗]
亮度感測 Sensor
利用光敏電阻特性(阻抗會隨亮度明暗而有所變化),與10KΩ電阻分壓 所測得電壓變化,來達到亮度檢測之輸入。
濕度感測 Sensor
利用兩根迴紋針,與55KΩ電阻分壓 所測得電壓變化,來達到亮度檢測之輸入。
藍芽模組
藍芽模組 型號:HC-05 參考
安裝 參考
設定 Baud Rate 參考
Sensor 電路
.png)
[量測結果]
實驗二(test2.ino):讀取光敏電阻及土壤濕度訊號,並發送至藍芽模組。
// 在 2x16 LCD 上顯示 溫濕度 並傳送至藍芽模組
// Program : 張碩文 SteveChang, PMP (sown813@gmail.com)
// 引用 LiquidCrystal Library
#include <LiquidCrystal.h>
// 光敏電阻 (photocell) 接在 anallog pin 0
int LightSensor = A0;
// 濕度 接在 anallog pin 1
int MoistureSensor = A1; // photocell variable
#define BUFFERSIZE 127
uint8_t inBuffer[BUFFERSIZE];
int inLength; // length of data in the buffer
// 建立 LiquidCrystal 的變數 LCD
// LCD 接腳: RS, Enable, D4, D5, D6, D7
// 對應到 Arduino 接腳: 12, 11, 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void setup() {
// 設定藍芽 57600
Serial.begin(57600);
// 設定 LCD 的行列數目 (2 x 16)
lcd.begin(16, 2);
Serial.print("Setup......");
}
void loop() {
// 讀取光敏電阻
float value1 = LightFormat( analogRead(LightSensor) );
// 讀取濕度
float value2 = MoistureFormat( analogRead(MoistureSensor) );
// 將游標設到 column 0, line 0
// (注意: line 1 是第二行(row),因為是從 0 開始數起):
lcd.setCursor(0, 0);
lcd.print(" Light: ");
lcd.print(value1,1);
lcd.print("% ");
lcd.setCursor(0, 1);
lcd.print("Moisture: ");
lcd.print(value2,1);
lcd.print("% ");
// 列印 Arduino 重開之後經過的秒數
// lcd.print(millis()/1000);
Serial.print("亮度 : ");
Serial.print(value1);
Serial.print("% 濕度 : ");
Serial.print(value2);
Serial.println("%");
delay(1000);
// read string if available
if (Serial.available()) {
inLength = 0;
while (Serial.available()) {
inBuffer[ inLength] = Serial.read();
inLength++;
if (inLength >= BUFFERSIZE)
break;
}
}
}
// 調整顯示格式
float LightFormat(int value)
{
if(value > 1000) return 100;
return value / 10.0;
}
// 調整顯示格式
float MoistureFormat(int value)
{
return value / 10.0;
}
沒有留言:
張貼留言