DHT11+BH1750+土壤湿度的协议栈代码
时间: 2023-09-17 15:07:09 浏览: 123
以下是DHT11和BH1750传感器的协议栈代码示例,使用Arduino编程语言:
DHT11协议栈代码:
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 7
void setup() {
Serial.begin(9600);
}
void loop() {
int chk = DHT.read(DHT11_PIN);
Serial.print("Humidity (%): ");
Serial.print(DHT.humidity);
Serial.print(", Temperature (°C): ");
Serial.println(DHT.temperature);
delay(2000);
}
BH1750协议栈代码:
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup() {
Serial.begin(9600);
Wire.begin();
lightMeter.begin();
}
void loop() {
uint16_t lux = lightMeter.readLightLevel();
Serial.print("Light level: ");
Serial.println(lux);
delay(2000);
}
土壤湿度协议栈代码:
int soilMoisturePin = A0;
int soilMoistureValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
soilMoistureValue = analogRead(soilMoisturePin);
Serial.print("Soil Moisture: ");
Serial.print(soilMoistureValue);
Serial.println(" %");
delay(2000);
}
阅读全文