// LED and Buzzer Pin Definitions
const int greenLedPin = 13;
const int blueLedPin = 14;
const int redLedPin = 15;
const int yellowLedPin = 16;
const int buzzerPin = 15; // Buzzer for emergency alert
// Button Pin Definitions
const int greenButtonPin = 17; // Button to activate Green LED
const int blueButtonPin = 18; // Button to activate Blue LED
const int redButtonPin = 19; // Button to activate Red LED and buzzer
const int yellowButtonPin = 21; // Button to activate Yellow LED
void setup() {
Serial.begin(115200);
// Set up LED and Buzzer pins as OUTPUT
pinMode(greenLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Set up button pins as INPUT_PULLUP (using internal pull-up resistors)
pinMode(greenButtonPin, INPUT_PULLUP);
pinMode(blueButtonPin, INPUT_PULLUP);
pinMode(redButtonPin, INPUT_PULLUP);
pinMode(yellowButtonPin, INPUT_PULLUP);
// Initialize all LEDs and buzzer to OFF
digitalWrite(greenLedPin, LOW);
digitalWrite(blueLedPin, LOW);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(buzzerPin, LOW);
}
void loop() {
// Green Button - Running Condition
if (digitalRead(greenButtonPin) == LOW) {
delay(200); // Debounce delay
turnOnOnly(greenLedPin);
Serial.println("Green LED (Running Condition) is ON");
}
// Blue Button - Running Condition
if (digitalRead(blueButtonPin) == LOW) {
delay(200); // Debounce delay
turnOnOnly(blueLedPin);
Serial.println("Blue LED (Running Condition) is ON");
}
// Red Button - Protection Activated (Emergency)
if (digitalRead(redButtonPin) == LOW) {
delay(200); // Debounce delay
turnOnOnly(redLedPin);
digitalWrite(buzzerPin, HIGH); // Turn on buzzer for emergency
Serial.println("Red LED (Protection Activated) and Buzzer are ON");
} else {
digitalWrite(buzzerPin, LOW); // Turn off buzzer if Red LED is off
}
// Yellow Button - Idle Condition
if (digitalRead(yellowButtonPin) == LOW) {
delay(200); // Debounce delay
turnOnOnly(yellowLedPin);
Serial.println("Yellow LED (Idle Condition) is ON");
}
// Small delay to avoid accidental multiple presses
delay(50);
}
// Function to turn on one LED and turn off others
void turnOnOnly(int ledPin) {
digitalWrite(greenLedPin, ledPin == greenLedPin ? HIGH : LOW);
digitalWrite(blueLedPin, ledPin == blueLedPin ? HIGH : LOW);
digitalWrite(redLedPin, ledPin == redLedPin ? HIGH : LOW);
digitalWrite(yellowLedPin, ledPin == yellowLedPin ? HIGH : LOW);
}