Closed Swatiharale closed 3 months ago
// Constants
// Initialize DHT sensor DHT dht(DHTPIN, DHTTYPE);
// Initialize software serial for Bluetooth SoftwareSerial BTSerial(BT_RX, BT_TX);
void setup() { Serial.begin(9600); BTSerial.begin(9600); dht.begin(); }
void loop() { // Reading temperature and humidity float h = dht.readHumidity(); float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again) if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; }
// Prepare data string String data = "Temperature: " + String(t) + "°C, Humidity: " + String(h) + "%";
// Send data via Bluetooth BTSerial.println(data);
// Print data to Serial Monitor Serial.println(data);
// Wait a few seconds between measurements delay(2000); }
include
include
// Constants
define DHTPIN 2 // Digital pin connected to the DHT sensor
define DHTTYPE DHT22 // DHT 22 (AM2302)
define BT_TX 10 // Bluetooth module TX to Arduino RX
define BT_RX 11 // Bluetooth module RX to Arduino TX
// Initialize DHT sensor DHT dht(DHTPIN, DHTTYPE);
// Initialize software serial for Bluetooth SoftwareSerial BTSerial(BT_RX, BT_TX);
void setup() { Serial.begin(9600); BTSerial.begin(9600); dht.begin(); }
void loop() { // Reading temperature and humidity float h = dht.readHumidity(); float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again) if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; }
// Prepare data string String data = "Temperature: " + String(t) + "°C, Humidity: " + String(h) + "%";
// Send data via Bluetooth BTSerial.println(data);
// Print data to Serial Monitor Serial.println(data);
// Wait a few seconds between measurements delay(2000); }