add the bluetooth module
This commit is contained in:
parent
ba0c952e3b
commit
984930cfde
@ -1,13 +1,41 @@
|
||||
#include <SoftwareSerial.h>
|
||||
#include "DHT.h"
|
||||
#define DHTPIN 2
|
||||
|
||||
// Bluetooth module
|
||||
#define rxPin 11
|
||||
#define txPin 10
|
||||
SoftwareSerial mySerial(rxPin, txPin);
|
||||
|
||||
// DHT sensor
|
||||
#define DHTPIN 9
|
||||
#define DHTTYPE DHT11
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
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() {
|
||||
Serial.println("Temperature = " + String(dht.readTemperature())+" °C");
|
||||
Serial.println("Humidite = " + String(dht.readHumidity())+" %");
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user