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