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.
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.
Optional DIY-016 5 V buzzer, ESP32U, and additional user-supplied driver/protection parts selected after measurement
Wire the parts, upload the sketch from the kit page, then test this project by watching the Serial Monitor or the output behavior.
You learn how the controller reads real sensor signals, makes a decision in code, and turns that result into a useful output.
Every item is in the kit — nothing extra to buy.
All 6 parts in one box, with this project and 6 more to build from them.
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+.
Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.
/*
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);
}
Measure temperature, relative humidity, and pressure near a plant while keeping the module dry and away from direct sun, water, fingers, and warm electronics. Compare se…
Capture the sketch's machine-readable DATA lines, import them into a spreadsheet, and chart how the references change after watering or as a test sample dries. Add times…
Build the reviewed main project, capture four local calibration endpoints, and stream soil, water, temperature, humidity, pressure, and status data to Serial Monitor. Th…
We use cookies that the shop needs to work — signing in, your cart, form security. We also measure how the shop is used so we can stock the right parts and fix what is broken. Choose “Only essential” and we will not load Google Analytics or the Meta pixel, and will not record your visit. Read more.