const int button1Pin = 2;
const int button2Pin = 3;
const int button3Pin = 4;
const int buzzerPin = 9;
int votes1 = 0, votes2 = 0, votes3 = 0;
bool votingAllowed = false;
bool systemEnded = false;
unsigned long unlockStartTime = 0;
unsigned long unlockDuration = 20000; // 20 seconds after UNLOCK command
void setup() {
[Link](9600);
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
[Link](" EVM Initialized. Use commands: UNLOCK | RESET | END");
printVoteCount();
void loop() {
// Auto-lock after 20 seconds of being unlocked
if (votingAllowed && !systemEnded && millis() - unlockStartTime >= unlockDuration) {
votingAllowed = false;
[Link](" Timeout: Voting auto-locked after 20 seconds.");
// Handle Bluetooth commands
if ([Link]()) {
String command = [Link]('\n');
[Link]();
if ([Link]("UNLOCK")) {
if (!systemEnded) {
votingAllowed = true;
unlockStartTime = millis(); // start unlock timer
[Link]("🔓 Voting UNLOCKED for 20 seconds.");
else if ([Link]("RESET")) {
votes1 = votes2 = votes3 = 0;
votingAllowed = false;
systemEnded = false;
[Link]("♻️Votes RESET.");
printVoteCount();
}
else if ([Link]("END")) {
votingAllowed = false;
systemEnded = true;
[Link]("🛑 Voting ENDED permanently.");
// Check if a vote happens
if (votingAllowed && !systemEnded) {
if (digitalRead(button1Pin) == LOW) {
votes1++;
registerVote(1);
} else if (digitalRead(button2Pin) == LOW) {
votes2++;
registerVote(2);
} else if (digitalRead(button3Pin) == LOW) {
votes3++;
registerVote(3);
void registerVote(int candidate) {
// Sound buzzer
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
// Report vote
[Link]("✅ Vote cast for Candidate ");
[Link](candidate);
printVoteCount();
// Lock after vote
votingAllowed = false;
[Link]("🔒 Voting LOCKED after vote.");
void printVoteCount() {
[Link]("📊 Vote Count → C1: ");
[Link](votes1);
[Link](" | C2: ");
[Link](votes2);
[Link](" | C3: ");
[Link](votes3);