Main door locked or unlocked indicator
Build it step by step
0 of 7 doneTest the sensor on the bench
Magnet near, LED changes.
Find the magnet face
The one that triggers it.
Glue the magnet to the bolt
Check it does not rub.
Place the sensor in the frame
Line it up with the bolt.
Run the cable
Away from mains wiring.
Upload and test
Lock and unlock a few times.
Mount the Nano and LEDs
By the bedroom.
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
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- Mechanical & Hardware
- SemiconductorsBuyLED 5 mm green × 1
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 2
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| A3144 pin 1 (VCC) | Nano 5V | Power (flat face toward you, pins down) |
| A3144 pin 2 (GND) | Nano GND | Ground |
| A3144 pin 3 (OUT) | Nano D2 | Low when the magnet is near (internal pull-up) |
| Green LED anode | 220 ohm to Nano D5, cathode to GND | Locked |
| Red LED anode | 220 ohm to Nano D6, cathode to GND | Unlocked |
| Cable | Three-core, a few metres at most, between the sensor and the Nano | Run 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.
| Check | Expected |
|---|---|
| Bolt thrown | Green on |
| Bolt open | Red on |
| Open for ten minutes | Red blinks |
| Cable moved | State 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 →
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.
