Practical case: Light alarm with relay and door sensor

Schematic — Practical case: Light alarm with relay and door sensor

Objective and use case

What you will build: A simple alarm system that turns on a 12 V light by means of a relay when a door with a magnetic switch is opened. You can optionally add a small 12 V siren as an additional signal.

What it is for

  • Turn on a courtesy light when opening the door of a closet, storage room, or pantry.
  • Warn with a red light that an exit door in a hallway has been left open.
  • Activate a beacon light at the entrance of a garage when the main door is opened.
  • Use an indicator light to show “door not properly closed” in furniture or display cabinets.
  • Integrate a small 12 V siren together with the light for basic acoustic alerts.

Expected result

  • The relay coil receives ≈ supply voltage (for example 12 V DC) when the door is open.
  • The relay coil current is kept within specification (≈ 30–60 mA depending on the model).
  • The voltage between COM and NO of the relay drops to ≈ 0 V when the relay is activated (contact closed).
  • The 12 V lamp or LED turns on in less than 0.5 s after opening the door.
  • Power consumption at rest (door closed) is practically zero, apart from minimal circuit losses.

Target audience: Student; Level: Beginner–intermediate in basic 12 V DC electronics

Architecture/flow: 12 V DC supply → door magnetic switch → relay coil → relay contacts (COM–NO) in series with the 12 V lamp/LED or siren; when the door is opened the magnetic switch closes, the relay coil is energized, and the light/acoustic load is powered directly.

Materials

  • 1 × 12 V DC power supply (500 mA or more).
  • 1 × 12 V DC relay, 1 changeover pole (SPDT: COM, NO, NC contacts).
  • 1 × Magnetic door switch (reed type with magnet, normally closed or normally open contact; we will use normally closed/NC type).
  • 1 × Protection diode for the relay coil (for example 1N4007).
  • 1 × 12 V lamp or 12 V LED strip (max. current according to relay contact capacity; e.g. ≤ 1 A).
  • 1 × Indicator LED (optional, for example standard 5 mm red LED).
  • 1 × Resistor for the indicator LED (1 kΩ, 1/4 W).
  • Wires and breadboard (if the relay is for PCB) or terminal block.
  • 1 × Digital multimeter (for voltage and current).

Wiring guide

Treat this section as the official connection specification. The ASCII schematic in the following section implements EXACTLY these connections.

  • Main power:
  • Connect the positive terminal of the 12 V supply to the node labeled +12V.
  • Connect the negative terminal of the 12 V supply to the node labeled GND.

  • Relay coil:

  • Connect one terminal of the relay coil to the +12V node.
  • Connect the other terminal of the relay coil to the VB node.

  • Magnetic door switch (sensor):

  • Connect one of the terminals of the magnetic switch to the VB node.
  • Connect the other terminal of the magnetic switch to the GND node.
  • A normally closed (NC) switch is assumed: with the door closed, the contact is closed and connects VB node to GND.

  • Protection diode (flyback diode):

  • Connect the diode cathode (marked with a band, in the schematic it will appear as [D1] 1N4007) to the +12V node.
  • Connect the diode anode to the VB node.
  • The diode is in parallel with the relay coil, but reverse-biased with respect to the power supply (it MUST NOT conduct in normal operation).

  • Relay power contacts (for the 12 V lamp/LED):

  • Use the relay’s common (COM) and normally open (NO) contacts.
  • Connect the relay COM contact to the +12V node.
  • Connect the relay NO contact to the VL node.
  • Connect the other terminal of the 12 V lamp/LED to the GND node.
  • Connect the VL node to one of the terminals of the 12 V lamp/LED.
  • The relay NC contact is not used in this practical case; leave it unconnected.

  • Relay activation indicator LED (optional):

  • Connect the indicator LED anode (positive side) to the +12V node through the resistor:
    • Connect the +12V node to one end of the resistor [R1] 1 kΩ.
    • Connect the other end of [R1] to the VI node.
  • Connect the indicator LED cathode to the VB node.
  • The VI node only serves as a junction between resistor [R1] and the indicator LED anode.

Schematic

            +12V
            |
            +--------------------+--------------------+
            |                    |                    |
          [R1] 1kΩ              [K]                  COM (relé)
            |                 Bobina                  |
      VI node o                 |                     |
            |                 VB node o---------------+
          [LED] Indicador        |                  NO (relé)
            |                 [D1] 1N4007             |
            |                  |                      |
           GND                 |                      o VL node
                               |                      |
                           Interruptor                [LAMP] 12V
                          magnético NC                |
                               |                      |
                              GND                    GND
Schematic (ASCII)

Quick legend:
[K] Bobina is the relay coil (between +12V and VB node).
– COM and NO are the relay power contacts.
[LAMP] 12V is the 12 V lamp or load.
[LED] Indicador is the small panel LED, with its resistor [R1] 1kΩ.
[D1] 1N4007 is the coil protection diode.


Measurements and tests

  • Basic voltage verification:

    • Measure the voltage between +12V and GND with the multimeter in DC voltmeter mode. It should read ~12 V.
    • With the door CLOSED (NC switch closed), measure between VB node and GND. It should read ~0 V (it is at ground through the switch).
    • With the door OPEN (switch open), measure between VB node and GND. It should read approximately 12 V (the coil is powered).
  • Relay activation check:

    • With the multimeter in DC voltmeter mode, measure between COM and NO of the relay:
      • Door closed: COM-NO should show a voltage close to that of the load or be “open” (if you measure continuity, it should indicate open circuit).
      • Door open: COM-NO should show a very low resistance (almost a short circuit); in voltmeter mode, the voltage between COM and NO will be ≈ 0 V when the relay is activated.
    • Observe the 12 V lamp/LED: it should clearly turn on when the door opens and turn off when the door closes.
  • Relay coil current measurement (I_coil):

    • I_coil (coil current) is the current that flows through the relay coil when it is activated.
    • To measure it, set the multimeter to DC ammeter mode and place it in series with the coil:
      • Disconnect the wire that goes from +12V to the coil.
      • Connect the positive terminal of the ammeter to +12V.
      • Connect the negative terminal of the ammeter to the coil terminal that previously went to +12V.
    • Open the door to activate the relay and read the current: compare it with the typical value from the datasheet (e.g., 40 mA). It should be in a similar range.
  • Verification of voltage drop across the load (V_LAMP):

    • V_LAMP is the voltage that appears directly across the terminals of the 12 V lamp/LED.
    • With the multimeter in DC voltmeter mode, place the test leads on each end of the lamp.
    • With the door open (relay activated), it should read a value close to 12 V.
    • With the door closed (relay deactivated), V_LAMP should be ≈ 0 V.
  • Dynamic functional tests:

    • Open and close the door repeatedly, checking:
      • That the relay operates without flickering or strange noises.
      • That the indicator LED (if installed) lights only when the relay is activated (door open).
      • That neither the relay nor the lamp heats excessively for prolonged use times (touch carefully after several minutes).

Common errors and how to avoid them

  • Forgetting the coil protection diode:
  • When the coil is disconnected, a voltage spike is generated that can damage other components.
  • Make sure that [D1] 1N4007 is in parallel with the coil, with cathode to +12V and anode to VB node.

  • Swapping the relay contacts (accidentally using NC instead of NO):

  • Check the datasheet or the drawing on the relay housing to correctly identify COM, NO, and NC.
  • If you connect the lamp to NC instead of NO, the light will be on at rest and off when the door is opened (inverted behavior).

  • Using the wrong type of magnetic switch:

  • This practical case assumes an NC switch (closed with the door closed).
  • If your sensor is normally open (NO), the logic is inverted: review the measurements and adapt if necessary (you might want to use the relay’s NC contact to keep the desired behavior).

  • Overloading the relay contacts:

  • Check the maximum allowable current of the relay contacts (e.g. 3 A at 12 V DC).
  • Make sure the lamp or load does not exceed that value; if it is higher, you must use a more robust relay or an intermediate stage (contactors, MOSFET, etc.).

  • Incorrect connection of the indicator LED:

  • Do not forget the series resistor [R1] 1 kΩ to limit LED current.
  • Check polarity: anode toward the resistor (and then to +12V), cathode toward VB node.

Safety and good practices

  • Always work with the supply disconnected while making or modifying connections.
  • Even though you are only using 12 V, avoid short circuits: they can damage the supply or dangerously heat the wires.
  • If you adapt this circuit to control mains voltages (230 V AC) through the relay:
  • Maintain complete physical separation between the low-voltage (12 V) side and the mains side.
  • Do not handle the mains side unless you have specific and certified training.
  • Use junction boxes, terminal blocks, and insulation suitable for mains electricity.

Possible improvements and extensions

  • Add a 12 V siren in parallel with the lamp to have both audible and visual alarms.
  • Add a timer (for example, using an RC circuit with a transistor or a small microcontroller) so that the light turns off by itself X minutes after opening the door.
  • Implement a manual deactivation switch that allows you to temporarily disable the alarm without dismantling the system.
  • Integrate an additional sensor (for example, an ambient light sensor) so that the lamp only activates at night.

More Practical Cases at Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon affiliate, I earn from qualifying purchases. If you buy through this link, you help support this project.

Quick quiz

Question 1: What is the main function of the system described in the article?




Question 2: Which element is used to detect the opening of the door?




Question 3: According to the described architecture, in what basic order are the elements connected?




Question 4: What happens to the relay coil when the door is open?




Question 5: What approximate current value should flow through the relay coil according to the article?




Question 6: When the relay is activated, what happens to the voltage between COM and NO?




Question 7: What operating condition is expected when the door is closed (at rest)?




Question 8: In approximately what time should the 12 V lamp or LED turn on after opening the door?




Question 9: Which of these is a typical use of the system according to the article?




Question 10: In addition to the 12 V light, what device can optionally be integrated into the system?




More Practical Cases on Prometeo.blog

Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:
Scroll to Top