Emergency Light Controller with Backup Battery and Automatic Test

Emergency Light Controller with backup battery and automatic hourly tests using Arduino for reliable power outage response and system status indication.

Brief Introduction

Emergency Light Controller with Backup Battery and Automatic Test (arduino)
DESCRIPTION:
This project implements a controller for emergency lights powered by a backup battery. The system monitors the presence of mains voltage and, in case of absence, automatically activates the emergency lights powered by the battery. There is a periodic automatic test that verifies the correct operation of the lights and battery, signaling any anomalies via a status LED. The system uses a button to manually start the test and a buzzer for acoustic signals.

ADDITIONAL NOTES:
The thresholdValue must be calibrated based on the voltage sensor used and the resistive divider. The automatic test starts every hour and lasts 10 seconds, during which the emergency lights turn on and the buzzer flashes to signal the test. The button allows manual test start at any time. Transistors are used as switches to drive the emergency lights powered at 12V by the backup battery, thus protecting the Arduino from high voltages.

EXPLANATIONS:
- The mainsSensorPin reads the mains voltage through a resistive divider that reduces the voltage to a safe value for Arduino (max 5V).
- Mains control is essential to decide whether to activate the emergency lights powered by the backup battery.
- The red status LED indicates if the system is in emergency or test mode.
- The button is configured with INPUT_PULLUP to simplify wiring and reading.
- The periodic automatic test verifies the correct operation of the lights and battery, signaling via buzzer and LED.
- Transistors allow driving the 12V emergency lights without overloading Arduino pins.
- The blinkBuzzer function creates an intermittent acoustic signal to highlight the ongoing test.

Example Code: arduino

// Emergency light controller with backup battery and automatic test
// Arduino Uno

// Pin definitions
const int pinLedStato = 13;       // Red status LED
const int pinLuce1 = 8;           // Emergency light control 1
const int pinLuce2 = 9;           // Emergency light control 2
const int pinPulsanteTest = 2;    // Button for manual test
const int pinBuzzer = 10;         // Buzzer for acoustic signals
const int pinSensoreRete = A0;   // Mains voltage sensor (divider)

// Thresholds and timings
const int sogliaRete = 100;       // Minimum analog value to consider mains present (to calibrate)
const unsigned long intervalloTestAutomatico = 3600000UL; // 1 hour in milliseconds
const unsigned long durataTest = 10000UL; // Duration of automatic and manual test (10 seconds)

// State variables
bool retePresente = true;
bool testInCorso = false;
unsigned long ultimoTest = 0;
unsigned long inizioTest = 0;

void setup() {
  pinMode(pinLedStato, OUTPUT);
  pinMode(pinLuce1, OUTPUT);
  pinMode(pinLuce2, OUTPUT);
  pinMode(pinBuzzer, OUTPUT);
  pinMode(pinPulsanteTest, INPUT_PULLUP); // Button with internal pull-up

  digitalWrite(pinLedStato, LOW);
  digitalWrite(pinLuce1, LOW);
  digitalWrite(pinLuce2, LOW);
  digitalWrite(pinBuzzer, LOW);

  Serial.begin(9600);
  ultimoTest = millis();
}

void loop() {
  // Read mains voltage sensor
  int valoreRete = analogRead(pinSensoreRete);
  // Serial.println(valoreRete); // Debug

  // Check mains presence
  if (valoreRete > sogliaRete) {
    retePresente = true;
  } else {
    retePresente = false;
  }

  // Manage emergency lights
  if (!retePresente) {
    // Mains absent: turn on emergency lights
    accendiLuciEmergenza(true);
    digitalWrite(pinLedStato, HIGH); // Red LED on indicates active emergency
  } else {
    // Mains present: turn off emergency lights
    accendiLuciEmergenza(false);
    digitalWrite(pinLedStato, LOW);
  }

  // Check button for manual test
  if (digitalRead(pinPulsanteTest) == LOW && !testInCorso) {
    // Button pressed, start test
    avviaTest();
  }

  // Check automatic test
  if (!testInCorso && (millis() - ultimoTest >= intervalloTestAutomatico)) {
    avviaTest();
  }

  // If test in progress, manage duration and signals
  if (testInCorso) {
    unsigned long tempoTrascorso = millis() - inizioTest;

    if (tempoTrascorso < durataTest) {
      // During test: turn on lights and blinking buzzer
      accendiLuciEmergenza(true);
      lampeggiaBuzzer(tempoTrascorso);
      digitalWrite(pinLedStato, HIGH); // Red LED on during test
    } else {
      // End test
      testInCorso = false;
      ultimoTest = millis();
      accendiLuciEmergenza(!retePresente); // Restore lights state based on mains
      digitalWrite(pinLedStato, retePresente ? LOW : HIGH);
      digitalWrite(pinBuzzer, LOW);
    }
  }

  delay(50); // Small delay for stability
}

// Function to turn emergency lights on or off
void accendiLuciEmergenza(bool stato) {
  digitalWrite(pinLuce1, stato ? HIGH : LOW);
  digitalWrite(pinLuce2, stato ? HIGH : LOW);
}

// Function to start automatic/manual test
void avviaTest() {
  testInCorso = true;
  inizioTest = millis();
  Serial.println("Starting emergency lights test");
}

// Function to blink buzzer during test
void lampeggiaBuzzer(unsigned long tempo) {
  // Blink frequency 2Hz (on 250ms, off 250ms)
  if ((tempo / 250) % 2 == 0) {
    digitalWrite(pinBuzzer, HIGH);
  } else {
    digitalWrite(pinBuzzer, LOW);
  }
}
×
×
×
Do you want to regenerate the answer?
×
Export chat
Choose export format
Generazione PDF in corso…
Allegati
×
You are about to close the chat and switch to the image generator. If you are not logged in, you will lose our chat. Do you confirm?
You are viewing a shared chat in temporary mode. It will not be saved.
×
Saved prompts
×
Private note
×
Label
×
Search all chats
×
Your insights
Analyzing…
×
AI Preferences
Assistant name 30
Answer length
AI model
Structured answers
Include examples
Use emojis
Guide me, don't solve Hints and questions instead of a ready answer
More settings →
×
Share this chat
Anyone opening this link can view the chat or add it to their profile as their own chat.
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
Shared chat
Someone shared a chat with you. Do you want to just view it or add it to your chats?
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
×

Saved messages

Loading...

×

Chat History

example-programs · CHAT HISTORY

Loading...

AI Preferences

×
  • BasicQuick and essential answers for study
  • MediumHigher quality for study and programming
  • AdvancedComplex reasoning and detailed analysis
Explain Steps

What do you need?

Arduino Uno (x1)

Red 5mm LED (x1) - Status LED

White 5mm LEDs (x2) - Emergency lights

220Ω Resistor (x3) - for LEDs

Button (x1) - for manual test start

Piezo buzzer (x1) - acoustic signals

AC voltage sensor module (or resistive divider) for mains detection (x1)

12V backup battery power supply (x1)

NPN Transistor (e.g. 2N2222) or MOSFET to drive emergency lights (x2)

10kΩ transistor base resistor (x2)

CONNECTIONS:

Mains voltage sensor connected to analog input A0 (via divider for safety, max 5V Arduino input)

Red status LED connected to D13 via 220Ω resistor

White emergency LEDs connected to D8 and D9 via transistor and 220Ω resistors

Button connected to D2 and GND (configured with internal INPUT_PULLUP)

Buzzer connected to D10

Transistor base for lights connected to D8 and D9 via 10kΩ resistors

Transistor collector connected to negative pole of lights, emitter to GND

Emergency lights powered by 12V backup battery, transistor acts as low-side switch to turn them on

Similar Topics