Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Based Bluetooth Temperature and Humidity Monitor with OLED Display and Alert Buzzer

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Bluetooth Temperature and Humidity Monitor with OLED Display and Alert Buzzer

Circuit Documentation

Summary

The circuit in question is designed to monitor temperature and humidity using an AHT10 sensor, display the readings on a 128x64 OLED display, and provide a visual alert through a buzzer if the temperature exceeds a predefined threshold. The circuit is controlled by an Arduino Nano microcontroller, which also handles Bluetooth communication through an HC-05 Bluetooth module. The circuit includes resistors for current limiting and pull-up purposes.

Component List

Arduino Nano

Buzzer

128x64 OLED Display (I2C IIC SPI Serial)

Resistor (100 Ohms)

Resistor (2000 Ohms)

HC-05 Bluetooth Module

AHT10

Wiring Details

Arduino Nano

Buzzer

128x64 OLED Display (I2C IIC SPI Serial)

Resistor (100 Ohms)

Resistor (2000 Ohms)

HC-05 Bluetooth Module

AHT10

Documented Code

The code for the Arduino Nano is written in C++ and is intended to be compiled and uploaded using the Arduino IDE. The code is responsible for initializing the AHT10 sensor and OLED display, reading temperature and humidity values, displaying these values on the OLED, and controlling the buzzer based on the temperature threshold. Additionally, it handles serial communication to send sensor readings over Bluetooth.

#include <Wire.h>
#include <AHTxx.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR 0x3C
#define BUZZER_PIN 9  // Define the pin for the buzzer
#define TEMP_THRESHOLD 36.0  // Temperature threshold for buzzer

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
float ahtValue;  // to store T/RH result
AHTxx aht10(AHTXX_ADDRESS_X38, AHT1x_SENSOR);  // sensor address, sensor type

void setup() {
  Serial.begin(115200);  // Serial communication for Bluetooth
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();

  while (aht10.begin() != true) {
    Serial.println(F("AHT1x not connected or fail to load calibration coefficient"));
    delay(5000);
  }

  Serial.println(F("AHT10 OK"));

  pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as output
  digitalWrite(BUZZER_PIN, LOW); // Ensure buzzer is off initially
}

void loop() {
  // Read temperature
  ahtValue = aht10.readTemperature();
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(30, 0);
  display.println(F("Temp-"));

  if (ahtValue != AHTXX_ERROR) {
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(35, 25);
    display.println(ahtValue);
    display.display();

    // Check if temperature exceeds the threshold of 36°C and control buzzer
    if (ahtValue > TEMP_THRESHOLD) {
      digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
    } else {
      digitalWrite(BUZZER_PIN, LOW);  // Turn off buzzer
    }

    // Send temperature over Bluetooth
    Serial.print("Temperature: ");
    Serial.print(ahtValue);
    Serial.println(" C");
  } else {
    printStatus();
    digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer if error occurs
  }

  delay(2000);  // Delay between temperature readings

  // Read humidity
  ahtValue = aht10.readHumidity();
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(30, 0);
  display.println(F("Humd-"));

  if (ahtValue != AHTXX_ERROR) {
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(35, 25);
    display.println(ahtValue);
    display.display();

    // Send humidity over Bluetooth
    Serial.print("Humidity: ");
    Serial.print(ahtValue);
    Serial.println(" %");
  } else {
    printStatus();
  }

  delay(2000);  // Delay between humidity readings
}

void printStatus() {
  switch (aht10.getStatus()) {
    case AHTXX_NO_ERROR:
      Serial.println(F("No error"));
      break;
    case AHTXX_BUSY_ERROR:
      Serial.println(F("Sensor busy, increase polling time"));
      break;
    case AHTXX_ACK_ERROR:
      Serial.println(F("Sensor didn't return ACK, check connection"));
      break;
    case AHTXX_DATA_ERROR:
      Serial.println(F("Received data smaller than expected, check connection"));
      break;
    case AHTXX_CRC8_ERROR:
      Serial.println(F("CRC8 error, data may be corrupt"));
      break;
    default:
      Serial.println(F("Unknown status"));
      break;
  }
}

This code includes libraries for the AHTxx sensor and the Adafruit SSD1306 OLED display, defines constants for the display size and I2C address, and sets up the necessary pins and thresholds. The setup() function initializes the serial communication, display, and sensor, while the loop() function continuously reads the sensor data, updates the display, and checks the temperature against the threshold to control the buzzer. It also includes a printStatus() function to output sensor status messages to the serial monitor.