Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32 and BMP388 Bluetooth-Enabled Weather Station with Servo Control

Image of ESP32 and BMP388 Bluetooth-Enabled Weather Station with Servo Control

Circuit Documentation

Summary

This circuit involves an ESP32 microcontroller, a BMP388 sensor, and a servo motor. The ESP32 receives a float value via Bluetooth, converts it to an angle, and rotates the servo to that angle. It also reads temperature and air pressure from the BMP388 sensor and sends these values via Bluetooth. The ESP32 then enters deep sleep mode for 2 minutes to conserve power.

Component List

  1. Seeed Studio XIAO ESP32C6

    • Description: A compact ESP32 microcontroller with Bluetooth and Wi-Fi capabilities.
    • Pins: GPIO0, GPIO1, GPIO2, GPIO21, GPIO22, GPIO23, GPIO16, 5V, GND, 3V3, GPIO18, GPIO20, GPIO19, GPIO17, B+, B-
  2. Adafruit BMP388

    • Description: A high-precision barometric pressure and temperature sensor.
    • Pins: VCC, 3.3V, GND, SCK/SCL, SDO/ADR, SDI/SDA, CS, INT
  3. Servo

    • Description: A standard servo motor used for precise control of angular position.
    • Pins: GND, VCC, PWM

Wiring Details

Seeed Studio XIAO ESP32C6

  • 5V: Connected to VCC of Adafruit BMP388 and VCC of Servo
  • GND: Connected to GND of Adafruit BMP388 and GND of Servo
  • GPIO19: Connected to SCK/SCL of Adafruit BMP388
  • GPIO20: Connected to SDO/ADR of Adafruit BMP388
  • GPIO18: Connected to SDI/SDA of Adafruit BMP388
  • GPIO21: Connected to CS of Adafruit BMP388
  • GPIO22: Connected to PWM of Servo

Adafruit BMP388

  • VCC: Connected to 5V of Seeed Studio XIAO ESP32C6
  • GND: Connected to GND of Seeed Studio XIAO ESP32C6
  • SCK/SCL: Connected to GPIO19 of Seeed Studio XIAO ESP32C6
  • SDO/ADR: Connected to GPIO20 of Seeed Studio XIAO ESP32C6
  • SDI/SDA: Connected to GPIO18 of Seeed Studio XIAO ESP32C6
  • CS: Connected to GPIO21 of Seeed Studio XIAO ESP32C6

Servo

  • VCC: Connected to 5V of Seeed Studio XIAO ESP32C6
  • GND: Connected to GND of Seeed Studio XIAO ESP32C6
  • PWM: Connected to GPIO22 of Seeed Studio XIAO ESP32C6

Code Documentation

/*
 * This Arduino Sketch for the ESP32 microcontroller performs the following tasks:
 * 1. Receives a float value (0-1) via Bluetooth, converts it to an angle (0-180),
 *    and rotates a connected servo to that angle.
 * 2. Reads temperature and air pressure from a BMP388 sensor and sends these
 *    values via Bluetooth.
 * 3. Shuts off unnecessary peripherals and enters deep sleep for 2 minutes.
 */

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP3XX.h>
#include <Servo.h>
#include <BluetoothSerial.h>

#define BMP_SCK 19
#define BMP_SDI 18
#define BMP_CS 21
#define BMP_SDO 20
#define SERVO_PIN 22

Adafruit_BMP3XX bmp;
Servo myServo;
BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32_BMP_Servo");
  myServo.attach(SERVO_PIN);
  if (!bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_SDI, BMP_SDO)) {
    Serial.println("Could not find a valid BMP388 sensor, check wiring!");
    while (1);
  }
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}

void loop() {
  if (SerialBT.available()) {
    float receivedValue = SerialBT.readString().toFloat();
    int angle = receivedValue * 180;
    myServo.write(angle);
  }
  if (!bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  float temperature = bmp.temperature;
  float pressure = bmp.pressure / 100.0;
  SerialBT.print("Temperature: ");
  SerialBT.print(temperature);
  SerialBT.print(" C, Pressure: ");
  SerialBT.print(pressure);
  SerialBT.println(" hPa");
  delay(1000);
  esp_sleep_enable_timer_wakeup(120 * 1000000);
  esp_deep_sleep_start();
}

This code initializes the BMP388 sensor and the servo motor, sets up Bluetooth communication, and enters a loop where it reads a float value via Bluetooth to control the servo's angle. It also reads temperature and pressure from the BMP388 sensor and sends these values via Bluetooth before entering deep sleep mode for 2 minutes.