AR-191ArduinoBeginner

Arduino Uno + HC-05 Bluetooth Temperature and Humidity (DHT11)

Watch your room's temperature and humidity live on your phone: the Arduino Uno reads a DHT11 every 2 seconds and the HC-05 sends the values over Bluetooth, no internet needed. Android only: iPhones can't connect to the HC-05, use an HM-10 for iPhone. Pair the HC-05 in your phone's Bluetooth settings, then go to Workshop › Devices › Add a device › Bluetooth, pick Arduino Uno + HC-05/06 and Temperature and humidity, and upload the code from Get the code.

0.0(0)
Arduino Uno + HC-05 Bluetooth Temperature and Humidity (DHT11)
Ever wondered how warm your room really is, or why the air feels heavy? In this project you wire a small DHT11 module to an Arduino Uno with three wires: VCC to 5V, DATA to D4, GND to GND. Every 2 seconds the board sends the temperature and humidity to your phone over the HC-05; the app shows two readings and a live chart, with no internet or server. The HC-05 uses classic Bluetooth, so this project works on Android only: iPhones can't connect to the HC-05, so use an HM-10 for iPhone. The module goes on D2 and D3, with a 1 kΩ and 2 kΩ voltage divider on its RXD pin. First pair your phone with the HC-05 in its Bluetooth settings (the PIN is usually 1234 or 0000). Then add a new Bluetooth device in the app, pick the Arduino Uno + HC-05/06 board and the Temperature and humidity template, and upload the code from Get the code. The DHT sensor library (Adafruit) must be installed from the Library Manager in the Arduino IDE. The Set up as a Bluetooth panel button on this page also takes you to this panel's setup; update the app if you can't see the option. Learning: measuring with a DHT11, sending data over classic Bluetooth with SoftwareSerial, catching sensor errors and a timer that never waits.

Video

Circuit Diagram

Arduino Uno + HC-05 Bluetooth Temperature and Humidity (DHT11) - Circuit Diagram

Source Code

C++ (Arduino IDE)
1// ┌────────────────────────────────────┐
2// │ BlueGrays · bluegrays.com          │
3// │ Bluetooth · Arduino Uno + HC-05/06 │
4// │ BG-Hava                            │
5// └────────────────────────────────────┘
6// Temperature and humidity
7// Arduino IDE board: Arduino Uno
8// HC-05/06 is classic Bluetooth: Android only, iPhones can't connect. Its name is changed in AT mode (optional).
9
10#include <SoftwareSerial.h>
11#include <DHT.h>  // Library Manager: 'DHT sensor library' (Adafruit)
12
13const char BLE_NAME[] = "BG-Hava";  // the board advertises with this name, the app finds it in the list by it
14
15// Pins: change them here if you wired differently
16const int DHT_PIN = 4;
17const unsigned long READ_EVERY_MS = 2000;  // a new reading is sent every 2 seconds
18
19void btWrite(const char *text);
20void onValue(const char *key, const char *value);
21void sendAll();
22void onLinkLost();
23
24// ── The app sends "key=value" lines; on "?" the board sends all its values ──
25char line[65];
26uint8_t lineLen = 0;
27unsigned long lastRxMs = 0;
28
29bool is(const char *a, const char *b) { return strcmp(a, b) == 0; }
30bool isOn(const char *v) { return v[0] == '1'; }
31
32void sendText(const char *key, const char *value) {
33  char out[72];
34  snprintf(out, sizeof(out), "%s=%s\n", key, value);
35  btWrite(out);
36}
37
38void sendInt(const char *key, long value) {
39  char text[12];
40  snprintf(text, sizeof(text), "%ld", value);
41  sendText(key, text);
42}
43
44void sendFloat(const char *key, float value) {
45  char text[16];
46  dtostrf(value, 1, 1, text);
47  sendText(key, text);
48}
49
50void handleLine(char *text) {
51  char *eq = strchr(text, '=');
52  if (eq == nullptr) {
53    if (text[strlen(text) - 1] == '?') {
54      btWrite("@v=1.0\n");  // the "@v" line tells the app the code version
55      sendAll();
56    }
57    return;
58  }
59  *eq = '\0';
60  onValue(text, eq + 1);
61}
62
63void feed(char c) {
64  lastRxMs = millis();
65  if (c == '\n' || c == '\r') {
66    if (lineLen == 0) return;
67    line[lineLen] = '\0';
68    lineLen = 0;
69    handleLine(line);
70  } else if (lineLen < sizeof(line) - 1) {
71    line[lineLen++] = c;
72  }
73}
74
75// ── Bluetooth (SoftwareSerial) ──
76SoftwareSerial bt(2, 3);  // module TXD → D2, RXD → D3 (through a 1k/2k divider), 9600 baud
77
78void btWrite(const char *text) { bt.print(text); }
79
80void btBegin() { bt.begin(9600); }
81
82void btPoll() {
83  while (bt.available()) feed(bt.read());
84}
85
86// ── Arduino Uno + HC-05/06 ──
87DHT dht(DHT_PIN, DHT11);
88float temperature = NAN, humidity = NAN;
89unsigned long lastReadMs = 0;
90
91// if the sensor can't be read the app gets "@err=dht": check the wiring
92void readSensor() {
93  float t = dht.readTemperature();
94  float h = dht.readHumidity();
95  if (isnan(t) || isnan(h)) {
96    btWrite("@err=dht\n");
97    return;
98  }
99  temperature = t;
100  humidity = h;
101}
102
103void sendReadings() {
104  if (isnan(temperature)) return;
105  sendFloat("sicaklik", temperature);
106  sendInt("nem", lround(humidity));
107}
108
109void onValue(const char *key, const char *value) {
110}
111
112void sendAll() {
113  if (isnan(temperature)) readSensor();
114  sendReadings();
115}
116
117void onLinkLost() {
118}
119
120void setup() {
121  Serial.begin(115200);
122  dht.begin();
123  btBegin();
124  Serial.print(F("BlueGrays Bluetooth: "));
125  Serial.println(BLE_NAME);
126}
127
128void loop() {
129  btPoll();
130  if (millis() - lastReadMs >= READ_EVERY_MS) {
131    lastReadMs = millis();
132    readSensor();
133    sendReadings();
134  }
135}
136

FAQ

Does it work with an iPhone?

No, this project works on Android only. The HC-05 uses classic Bluetooth, and iPhones can't connect to classic Bluetooth modules. For iPhone, use an HM-10: in the app you pick Arduino Uno + HM-10 as the board. The Bluetooth temperature and humidity guide built with an ESP32 also works on iPhone. On Android, first pair the HC-05 in your phone's Bluetooth settings (the PIN is usually 1234 or 0000), then connect from the app.

Can I use a DHT22 instead of the DHT11?

Yes. The DHT22 (AM2302) measures a wider range more precisely: about -40 to 80 °C, ±0.5 °C. The wiring stays the same. The template in the app is made for the DHT11, so you need to change DHT11 to DHT22 in the DHT dht(DHT_PIN, DHT11) line of the code and upload it again. The panel's chart scale is set for the DHT11 range (0 to 50 °C).

Why do the values change every 2 seconds, and how accurate are they?

The DHT11 can't be read more than about once a second, so the code measures and sends every 2 seconds with READ_EVERY_MS = 2000. The temperature goes out with one decimal (°C) and the humidity as a whole number (%). The sensor measures 0 to 50 °C and 20% to 90% humidity; the temperature error is about ±2 °C. That is enough to keep an eye on a room; for more precision move to a DHT22.

What happens if the connection drops? Are the readings saved?

The board only sends the current value and keeps no history. The HC-05 doesn't tell the Uno when the connection drops; the board keeps measuring but the values don't reach the phone. The chart is drawn from values that arrive while the panel is open and the board is connected. The range is about 10 metres in the open. When you reconnect, the app sends ? and the board sends the latest values right away.