DOOR LIGHT CONTROL SYSTEM

Photo of author

By Jackson Taylor

Home » Electronics Topics » Arduino » DOOR LIGHT CONTROL SYSTEM

As an Amazon Associate we earn from qualifying purchases.

A door light control system turns a room light on and off automatically, based on what the door is doing and whether anyone is inside. You no longer fumble for a switch with full hands, and you stop leaving lights on in empty rooms. This project builds one with an Arduino (ATmega328), a Hall effect sensor, a PIR motion sensor and a relay.

How a door light control system works

The idea is simple. One sensor tells the controller that the door has moved. A second sensor checks whether someone is actually in the room. The controller combines the two signals and switches the light through a relay.

  • The Hall effect sensor detects the door opening or closing, using a small magnet fixed to the door.
  • The PIR sensor detects motion inside the room.
  • The Arduino reads both sensors and decides when to switch the light.
  • The relay switches the bulb, so the low-voltage board never touches mains power directly.

Block diagram

Block Diagram
Block diagram of the door light control system.

The block diagram shows the signal path. The PIR sensor and the Hall effect sensor feed the Arduino. The Arduino drives the relay, and the relay switches the bulb. A power supply feeds the controller and the sensors.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

Components used

  • PIR sensor
  • Hall effect sensor, plus a small magnet
  • Arduino (ATmega328) controller
  • Relay (or a relay module)
  • Power supply
  • A bulb and holder for the load

Working

PIR sensor

PIR sensors sense motion. They are almost always used to detect whether a person has moved into or out of the sensor’s range. They are small, inexpensive, low-power, easy to use and they don’t wear out, which is why they are common in appliances and gadgets in homes and businesses. You will also see them called “Passive Infrared”, “Pyroelectric” or “IR motion” sensors.

Hall effect sensor

A Hall effect sensor is a transducer that varies its output voltage in response to a magnetic field. Hall effect sensors are used for proximity switching, positioning, speed detection and current sensing.

See also
CUK CONVERTER SIMULATION AND HARDWARE USING ARDUINO AND MATLAB SIMULINK

In its simplest form, the sensor works as an analog transducer and returns a voltage directly. If the magnetic field is known, the magnet’s distance from the Hall plate can be worked out. With a group of sensors, the relative position of the magnet can be deduced. In a door project you only need to know whether the magnet is near or far, so a simple switching type is enough.

Putting it together

When the door is opened or closed, the Hall effect sensor is activated and the controller switches the relay accordingly. After about 2 seconds the PIR sensor is activated and checks for motion inside the room. If it sees motion, the bulb is switched on. When there is no motion, the bulb is switched off.

The short delay matters. The PIR sensor needs a moment to settle, and the person who just walked through the door may still be moving in front of it.

Circuit

Circuit Diagram
Circuit diagram of the door light control system.

In the sample program below, the connections are:

  • Pin 5: Hall effect sensor input, using the internal pull-up resistor.
  • Pin 6: PIR sensor output.
  • Pin 13: output to the relay (or the on-board LED while testing).

Check your sensor module’s pinout and supply voltage before powering anything. Most relay modules need their own supply or a suitable power rail, and some are triggered by a low signal rather than a high one.

Program

void setup()
{
    pinMode(13,OUTPUT);
    pinMode(5,INPUT_PULLUP);//hal
    pinMode(6,INPUT);//pir
}
void loop()
{
    if((digitalRead(5)==0)&&(digitalRead(6)==1))
    {
        digitalWrite(13,HIGH);
        delay(1000);
        digitalWrite(13,LOW);
    }
    else if (digitalRead(5)==1){ digitalWrite(13,HIGH);    delay(1000);}
    else;
}

What the code does

Because pin 5 uses INPUT_PULLUP, it reads 1 when the Hall sensor output is not pulled low and 0 when it is. With a typical switching Hall sensor, the output goes low when the magnet is close. The sketch reads this as follows:

  • If the Hall input is 0 and the PIR output is 1, the output on pin 13 goes high for one second and then low.
  • If the Hall input is 1, the output goes high for one second and the loop repeats, so the light stays on while that condition holds.
  • In any other case nothing changes.
See also
A New Quadratic Boost Converter with High Voltage Step-up Ratio and Reduced Voltage stress

This is a basic version. It does not include the 2-second wait before the PIR check described above, and it relies on delay(), which pauses the whole program. Depending on how you mount the magnet, you may need to swap the conditions.

Ideas for improving it

  • Add a timer. Use millis() instead of delay() so the light stays on for a set time after the last motion.
  • Add the 2-second PIR delay. Wait after the door event before reading the PIR, as in the working description.
  • Add a daylight check. A light-dependent resistor stops the light switching on in a bright room. Our guide to reading a light sensor with Arduino covers this.
  • Add an alert. The same door sensor can raise an alarm. See the Arduino security system with door sensors for one approach.

Safety notes

The Arduino side runs at low voltage, but the relay’s output side may switch mains power. Keep mains wiring separate from the low-voltage board, use an enclosure, and make sure the relay is rated for the bulb you are switching. If you are not confident with mains wiring, test with a low-voltage LED lamp or get a qualified electrician to do that part.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

Ready-made alternatives

If you would rather not build it yourself, off-the-shelf options exist. Commercial smart door sensors can trigger lights through a hub or app. Pairing them with a smart light switch or smart light bulbs gives similar behavior without wiring a relay. The Arduino build is still a good choice if you want to learn how it works or customize the logic.

FAQ

Why use both a Hall sensor and a PIR sensor?

The Hall sensor tells the system the door has moved, and the PIR sensor confirms someone is in the room. Using both avoids switching the light on when the door is opened and nobody enters, and it lets the light turn off when the room is empty.

See also
INTERFACING RF TRANSMITTER AND RECEIVER

Can I use a reed switch instead of a Hall effect sensor?

Yes. A magnetic reed switch also detects a magnet near the door frame. The wiring and logic are similar, though you may need to invert the condition in the code.

Why does the PIR sensor wait a couple of seconds?

PIR sensors need a short time to settle and can give false readings right after an event. A short delay after the door moves gives a more reliable motion reading.

Can this control something other than a bulb?

Yes, within the relay’s rating. The same logic can switch a fan or another light, as long as the load stays within what the relay is designed to handle.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works