Projects / Main door locked or unlocked indicator

Main door locked or unlocked indicator

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO17.7 mA

    Test the sensor on the bench

    Magnet near, LED changes.

  2. NANO

    Find the magnet face

    The one that triggers it.

  3. NANO

    Glue the magnet to the bolt

    Check it does not rub.

  4. NANO

    Place the sensor in the frame

    Line it up with the bolt.

  5. NANO

    Run the cable

    Away from mains wiring.

  6. NANO

    Upload and test

    Lock and unlock a few times.

  7. NANO17.8 mA

    Mount the Nano and LEDs

    By the bedroom.

In short

How do you build a main door locked or unlocked indicator?

A hall sensor in the door frame notices the lock bolt and shows a green or red light by the bedroom, so you know it is locked at night. You need Arduino Nano, Hall Effect Sensor A3144, Neodymium magnets (10 × 3 mm), LED 5 mm green, LED 5 mm red and Resistor 220 Ω × 2. It takes 7 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
A3144 pin 1 (VCC)Nano 5VPower (flat face toward you, pins down)
A3144 pin 2 (GND)Nano GNDGround
A3144 pin 3 (OUT)Nano D2Low when the magnet is near (internal pull-up)
Green LED anode220 ohm to Nano D5, cathode to GNDLocked
Red LED anode220 ohm to Nano D6, cathode to GNDUnlocked
CableThree-core, a few metres at most, between the sensor and the NanoRun it along the skirting

Code

The A3144 is a hall switch: its output goes low when a magnet's south pole is near the marked face, and high otherwise. Glue a small neodymium magnet to the end of the lock bolt, or to the door's deadbolt tongue, and put the sensor in the frame where it lines up when the bolt is thrown. Test the magnet both ways round, because the A3144 senses only one polarity. Run a thin three-core cable to the bedroom, where the Nano and two LEDs sit; a few metres is fine, but a long cable can pick up noise, so keep it short and away from mains wiring. The sketch lights green when the magnet is seen and red when it is not, and blinks red if the door has been unlocked for ten minutes. This is an indicator, not a security device: a stuck sensor or a loose magnet can show the wrong state, so always check the lock by hand if it matters, and never use it to decide whether a person is safe. Add a real-time clock if you want a night-only reminder. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Door lock indicator: green when the bolt magnet is detected, red when it is not, blinking if unlocked for a long time.
// Board: Arduino Nano. A3144 output is LOW when a magnet of the right polarity is near.
const uint8_t HALL = 2, GREEN = 5, RED = 6;
const unsigned long LONG_UNLOCKED_MS = 10UL * 60UL * 1000UL;   // blink red after ten minutes unlocked
unsigned long unlockedSince = 0;
bool lastLocked = false;
void setup() {
  pinMode(HALL, INPUT_PULLUP);
  pinMode(GREEN, OUTPUT); pinMode(RED, OUTPUT);
}
void loop() {
  bool locked = digitalRead(HALL) == LOW;
  if (!locked && lastLocked) unlockedSince = millis();
  if (!locked && unlockedSince == 0) unlockedSince = millis();
  lastLocked = locked;
  if (locked) {
    digitalWrite(GREEN, HIGH); digitalWrite(RED, LOW);
    unlockedSince = 0;
  } else {
    digitalWrite(GREEN, LOW);
    bool longTime = millis() - unlockedSince > LONG_UNLOCKED_MS;
    if (longTime) digitalWrite(RED, (millis() / 500) % 2);   // blink
    else digitalWrite(RED, HIGH);
  }
  delay(50);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Bolt thrownGreen on
Bolt openRed on
Open for ten minutesRed blinks
Cable movedState does not flicker

If it does not work

Always red

Flip the magnet or move the sensor closer.

Flickers

Shorten the cable or add a small capacitor at the sensor.

Both off

Check the LED legs and resistors.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the main door locked or unlocked indicator?

Arduino Nano, Hall Effect Sensor A3144, Neodymium magnets (10 × 3 mm), LED 5 mm green, LED 5 mm red and Resistor 220 Ω × 2.

How long does the main door locked or unlocked indicator take to build?

About 75 minutes for a beginner maker, in 7 steps.

How do I know the main door locked or unlocked indicator works?

Bolt thrown: Green on. Bolt open: Red on. Open for ten minutes: Red blinks.

Always red: what should I check?

Flip the magnet or move the sensor closer.

Flickers: what should I check?

Shorten the cable or add a small capacitor at the sensor.

Both off: what should I check?

Check the LED legs and resistors.