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

ESP32-Based Voltage Monitoring System with Buzzer Alert and Limit Switch Reset

View and Edit Project In Cirkit DesignerImage of ESP32-Based Voltage Monitoring System with Buzzer Alert and Limit Switch Reset

Circuit Documentation

Summary

This circuit involves an ESP32 microcontroller connected to two voltage sensors, a buzzer, two relays, and a limit switch. The ESP32 monitors voltage readings from the sensors and activates the buzzer if the readings exceed a certain threshold. The relays are controlled by the ESP32, and the limit switch is used to reset the system.

Component List

  1. Relay Module 2 Channel

    • Description: A module with two relays for switching high-power devices.
    • Pins: GND, IN1, IN2, VCC, NC1, COM, NO1, NC2, NO2
  2. Voltage Sensor

    • Description: A sensor to measure voltage levels.
    • Pins: GND, VCC, Output, Vcc
  3. ESP32 (30 pin)

    • Description: A microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  4. Buzzer Module

    • Description: A module to produce sound.
    • Pins: GND, Vcc, I/O
  5. Limit Switch

    • Description: A switch to detect physical limits or positions.
    • Pins: C, NO, NC

Wiring Details

Relay Module 2 Channel

Voltage Sensor 1

Voltage Sensor 2

ESP32 (30 pin)

Buzzer Module

Limit Switch

Code Documentation

/*
 * This Arduino Sketch is for an ESP32 connected to 2 voltage sensors, a buzzer,
 * 2 relays, and a limit switch. The ESP32 counts voltage readings > 3V from
 * each sensor. If either sensor reaches a count of 10, the buzzer sounds every
 * 0.5 seconds. The buzzer stops and the count resets when the limit switch is
 * pressed.
 */

const int voltageSensor1Pin = 34; // Voltage sensor 1 output pin
const int voltageSensor2Pin = 35; // Voltage sensor 2 output pin
const int relay1Pin = 25;         // Relay 1 control pin
const int relay2Pin = 26;         // Relay 2 control pin
const int buzzerPin = 33;         // Buzzer control pin
const int limitSwitchPin = 32;    // Limit switch pin

int count1 = 0; // Counter for voltage sensor 1
int count2 = 0; // Counter for voltage sensor 2
bool buzzerState = false; // Buzzer state
unsigned long lastBuzzerToggle = 0; // Last time the buzzer toggled

void setup() {
  pinMode(voltageSensor1Pin, INPUT);
  pinMode(voltageSensor2Pin, INPUT);
  pinMode(relay1Pin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(limitSwitchPin, INPUT_PULLUP);
  digitalWrite(relay1Pin, LOW);
  digitalWrite(relay2Pin, LOW);
  digitalWrite(buzzerPin, LOW);
}

void loop() {
  if (digitalRead(limitSwitchPin) == LOW) {
    count1 = 0;
    count2 = 0;
    buzzerState = false;
    digitalWrite(buzzerPin, LOW);
  }

  if (analogRead(voltageSensor1Pin) > 3.0 * 4095 / 3.3) {
    count1++;
  }

  if (analogRead(voltageSensor2Pin) > 3.0 * 4095 / 3.3) {
    count2++;
  }

  if (count1 >= 10 || count2 >= 10) {
    unsigned long currentMillis = millis();
    if (currentMillis - lastBuzzerToggle >= 500) {
      buzzerState = !buzzerState;
      digitalWrite(buzzerPin, buzzerState ? HIGH : LOW);
      lastBuzzerToggle = currentMillis;
    }
  }
}

This code initializes the pins for the voltage sensors, relays, buzzer, and limit switch. It continuously monitors the voltage sensors and increments counters if the voltage exceeds 3V. If either counter reaches 10, the buzzer toggles every 0.5 seconds. Pressing the limit switch resets the counters and stops the buzzer.