42 lines
833 B
C++
42 lines
833 B
C++
#include <SoftwareSerial.h>
|
|
#include "DHT.h"
|
|
|
|
// Bluetooth module
|
|
#define rxPin 11
|
|
#define txPin 10
|
|
SoftwareSerial mySerial(rxPin, txPin);
|
|
|
|
// DHT sensor
|
|
#define DHTPIN 9
|
|
#define DHTTYPE DHT22
|
|
DHT dht(DHTPIN, DHTTYPE);
|
|
|
|
void setup() {
|
|
pinMode(rxPin, INPUT);
|
|
pinMode(txPin, OUTPUT);
|
|
|
|
mySerial.begin(38400); // Bluetooth
|
|
Serial.begin(38400); // USB Serial Monitor (optional for debugging via arduino usb)
|
|
|
|
dht.begin();
|
|
}
|
|
|
|
void loop() {
|
|
float temp = dht.readTemperature();
|
|
float hum = dht.readHumidity();
|
|
|
|
String tempStr = "Temperature = " + String(temp) + " °C";
|
|
String humStr = "Humidite = " + String(hum) + " %";
|
|
|
|
// Send to Bluetooth
|
|
mySerial.println(tempStr);
|
|
mySerial.println(humStr);
|
|
|
|
// Show on Serial Monitor (for debugging)
|
|
Serial.println(tempStr);
|
|
Serial.println(humStr);
|
|
|
|
delay(10000);
|
|
}
|
|
|