#define POT_PIN 34 // Potentiometer middle pin -> GPIO34 (ADC1)
#define LED_PIN 2 // LED connected to GPIO2
#define BUZZER_PIN 4 // Buzzer connected to GPIO4
int lastValue = 0;
int threshold = 200; // Sensitivity for tamper detection
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
int sensorValue = analogRead(POT_PIN); // Read pot value (0–4095 for ESP32)
Serial.println(sensorValue);
// Check for tampering: sudden change in weight
if (abs(sensorValue - lastValue) > threshold) {
Serial.println("⚠️ Tampering Detected!");
digitalWrite(LED_PIN, HIGH); // Turn LED ON
digitalWrite(BUZZER_PIN, HIGH); // Buzzer ON
delay(1000);
} else {
digitalWrite(LED_PIN, LOW); // LED OFF
digitalWrite(BUZZER_PIN, LOW); // Buzzer OFF
}
lastValue = sensorValue; // Update previous value
delay(200);
}