Password based circuit breaker using arduino code

Here is an example of a password-based circuit breaker using Arduino:

Hardware Requirements:

Circuit Diagram:

The circuit consists of two relays, two diodes, a pushbutton switch, an LED indicator, and some resistors. The relays are used to control the circuit breaker, and the diodes are used to prevent back-EMF when the relays are turned off.

Here's a simplified circuit diagram:

          +---------------+
          |  Arduino    |
          |  (Digital Pin) |
          +---------------+
                  |
                  |  (5V)
                  v
          +---------------+
          |  Relay 1    |
          |  (NO, NC)  |
          +---------------+
                  |
                  |  (5V)
                  v
          +---------------+
          |  Diode 1    |
          |  (1N4001)  |
          +---------------+
                  |
                  |  (GND)
                  v
          +---------------+
          |  Load Circuit |
          |  (e.g. Lamp)  |
          +---------------+
                  |
                  |  (5V)
                  v
          +---------------+
          |  Relay 2    |
          |  (NO, NC)  |
          +---------------+
                  |
                  |  (5V)
                  v
          +---------------+
          |  Diode 2    |
          |  (1N4002)  |
          +---------------+
                  |
                  |  (GND)
                  v
          +---------------+
          |  Pushbutton  |
          |  (SW1)      |
          +---------------+
                  |
                  |  (5V)
                  v
          +---------------+
          |  LED Indicator|
          |  (R1, R2)    |
          +---------------+

Code:

Here is the Arduino code for the password-based circuit breaker:

const int relay1Pin = 2;  // Relay 1 pin
const int relay2Pin = 3;  // Relay 2 pin
const int pushbuttonPin = 4;  // Pushbutton pin
const int ledPin = 13;  // LED indicator pin

const char* password = "1234";  // Set the password here

int relayState = 0;  // Initial relay state (0 = off, 1 = on)

void setup() {
  pinMode(relay1Pin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);
  pinMode(pushbuttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(pushbuttonPin);
  if (buttonState == HIGH) {
    // Check if the password is correct
    if (checkPassword()) {
      // Turn on the relays
      digitalWrite(relay1Pin, HIGH);
      digitalWrite(relay2Pin, HIGH);
      relayState = 1;
      // Turn on the LED indicator
      digitalWrite(ledPin, HIGH);
    } else {
      // Password is incorrect, turn off the relays
      digitalWrite(relay1Pin, LOW);
      digitalWrite(relay2Pin, LOW);
      relayState = 0;
      // Turn off the LED indicator
      digitalWrite(ledPin, LOW);
    }
  } else {
    // Button is not pressed, turn off the relays
    digitalWrite(relay1Pin, LOW);
    digitalWrite(relay2Pin, LOW);
    relayState = 0;
    // Turn off the LED indicator
    digitalWrite(ledPin, LOW);
  }
}

bool checkPassword() {
  // Read the password from the user
  char inputPassword[5];
  int i = 0;
  while (i < 4) {
    int buttonState = digitalRead(pushbuttonPin);
    if (buttonState == HIGH) {
      inputPassword[i] = '1';
      i++;
    } else {
      inputPassword[i] = '0';
      i++;
    }
  }
  inputPassword[4] = '\0';  // Null-terminate the string

  // Check if the input password matches the set password
  if (strcmp(inputPassword, password) == 0) {
    return true;
  } else {
    return false;
  }
}

How it works:

  1. The user presses the pushbutton switch to enter the password.
  2. The Arduino reads the button state and stores it in a character array inputPassword.
  3. The checkPassword() function checks if the input password matches the set password.
  4. If the password is correct, the relays are turned on, and the LED indicator is lit.
  5. If the password is incorrect, the relays are turned off, and the LED indicator is turned off.
  6. The user can try again by pressing the pushbutton switch.

Note: This is a basic example and may not be suitable for production use. You may want to add additional features such as password retry limits, password reset functionality, and security measures to prevent tampering.