Sharjah, UAE GST
Home/ Projects/ Optional audible-alert investigation
Project 6 of 7 Basics

Optional audible-alert investigation

Characterize the buzzer's current, trigger threshold, and active level before choosing a transistor or driver. Write and compile a separate alert sketch only after the interface is reviewed. This project is not wired or implemented by the supplied main firmware.

ESP32 Plant Monitoring Learning Kit
One of 7 projects in the ESP32 Plant Monitoring Learning Kit — the parts below are from that kit.

What you build in this project

Optional audible-alert investigation is one focused build from the ESP32 Plant Monitoring Learning Kit. It uses the parts listed below to make a working electronics example, then you can combine it with the other projects in the kit.

Characterize the buzzer's current, trigger threshold, and active level before choosing a transistor or driver. Write and compile a separate alert sketch only after the interface is reviewed. This project is not wired or implemented by the supplied main firmware.

Parts used

Optional DIY-016 5 V buzzer, ESP32U, and additional user-supplied driver/protection parts selected after measurement

What to check

Wire the parts, upload the sketch from the kit page, then test this project by watching the Serial Monitor or the output behavior.

What you learn

You learn how the controller reads real sensor signals, makes a decision in code, and turns that result into a useful output.

What this project uses

Every item is in the kit — nothing extra to buy.

Build this with

ESP32 Plant Monitoring Learning Kit

All 6 parts in one box, with this project and 6 more to build from them.

AED 65.00 See the kit
Need only these parts? Order them loose · from AED 50.91
Used in this project tick what you still need
Also needed untick if you already have them
Selected parts AED 50.91

One of each part. Packs (resistor assortment, jumper wires) already hold more than a single build needs. ESP32U, and additional user-supplied driver/protection parts selected after measurement: included in the kit, ask us for it loose. Delivery is AED 20, free on orders AED 100+.

Sketch for this project

Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.

Optional audible-alert investigation arduino
/*
  ESP32 Plant Monitoring Learning Kit
  Project 6: Optional audible-alert investigation

  Wiring: optional DIY-016 active buzzer - signal GPIO27, VCC 3V3 (check
  the module's rating; it is sold as a 5 V part), GND. Soil sensor on GPIO34.

  What you learn: an alert should be rare and clear. The sketch beeps
  twice when the soil percentage drops below DRY_SOIL_PERCENT, then stays
  quiet for QUIET_MINUTES so it does not nag; a recovered plant resets it.
  Endpoints are fixed here - take yours from project 2.
*/

const int BUZZER_PIN = 27;
const int SOIL_PIN = 34;
const int DRY_RAW = 3200;          // from your calibration study
const int WET_RAW = 1400;
const int DRY_SOIL_PERCENT = 30;
const unsigned long QUIET_MINUTES = 1;   // 1 min here; 60 for a real plant
const unsigned long SAMPLE_MS = 1000;

unsigned long lastSample = 0, lastAlert = 0;
bool alertArmed = true;

void beep(int times) {
  for (int i = 0; i < times; i++) {
    digitalWrite(BUZZER_PIN, HIGH); delay(120);
    digitalWrite(BUZZER_PIN, LOW);  delay(120);
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(SOIL_PIN, INPUT);
  analogReadResolution(12);
  Serial.println("t_s,soil_raw,soil_pct,state");
}

void loop() {
  if (millis() - lastSample < SAMPLE_MS) return;
  lastSample = millis();
  int raw = analogRead(SOIL_PIN);
  int percent = constrain(map(raw, DRY_RAW, WET_RAW, 0, 100), 0, 100);
  bool dry = percent < DRY_SOIL_PERCENT;
  const char *state = "OK";
  if (dry) {
    if (alertArmed) {
      beep(2);
      lastAlert = millis();
      alertArmed = false;
      state = "ALERT";
      Serial.println("ALERT: soil is dry - water the plant");
    } else if (millis() - lastAlert > QUIET_MINUTES * 60000UL) {
      alertArmed = true;        // the quiet period is over: remind once more
      state = "DRY";
    } else state = "DRY (quiet)";
  } else {
    alertArmed = true;          // watered: the next dry spell alerts again
  }
  Serial.print(millis() / 1000); Serial.print(",");
  Serial.print(raw); Serial.print(",");
  Serial.print(percent); Serial.print(",");
  Serial.println(state);
}
ℹOptional DIY-016 buzzer on GPIO27: two beeps when soil drops below DRY_SOIL_PERCENT, then quiet for QUIET_MINUTES. Simulator-tested.

More from this kit

All projects →

Bot
ECHO
Online — usually replies instantly
Catalog assistant: verify final stock/price on the product page before checkout.