const int CURRENT_PIN = A0;
const int TEMP_PIN = A1;
const int RELAY_PIN = 7;
const int BUZZER_PIN = 8;
const int RESET_PIN = 2;
const int RELAY_ON = HIGH;
const int RELAY_OFF = LOW;
const float CORD_RATING = 10.0; // amps
const float TEMP_LIMIT = 60.0; // degrees C
const float BETA = 3950.0;
bool tripped = false;
float readCurrent() {
return analogRead(CURRENT_PIN) * 15.0 / 1023.0; // 0 to 15 A
}
float readTemp() {
int raw = analogRead(TEMP_PIN);
return 1 / (log(1 / (1023.0 / raw - 1)) / BETA + 1.0 / 298.15) - 273.15;
}
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(RESET_PIN, INPUT_PULLUP);
digitalWrite(RELAY_PIN, RELAY_ON); // power ON at start
}
void loop() {
float current = readCurrent();
float temp = readTemp();
// Trip if overloaded or too hot
if (current > CORD_RATING || temp > TEMP_LIMIT) {
tripped = true;
}
// Cut power and sound the buzzer
if (tripped) {
digitalWrite(RELAY_PIN, RELAY_OFF);
digitalWrite(BUZZER_PIN, HIGH);
}
// Reset only works when the cord is safe again
if (tripped && digitalRead(RESET_PIN) == LOW &&
current <= CORD_RATING && temp <= TEMP_LIMIT) {
tripped = false;
digitalWrite(RELAY_PIN, RELAY_ON);
digitalWrite(BUZZER_PIN, LOW);
}
Serial.print("Current: ");
Serial.print(current);
Serial.print(" A | Temp: ");
Serial.print(temp);
Serial.println(tripped ? " C | TRIPPED" : " C | OK");
delay(500);
}