Motion Triggered Hallway Lamp

Intro: Motion Triggered Hallway Lamp

In this project we are building a simple motion triggered hallway lamp. It's super convenient to not need to worry about finding the light switch when coming home at night or getting up to get some water during the night. The sensor will detect your presence and illuminate the hallway for 2 minutes.

Step 1: The Parts

  • You will need:
  • Arduino (due to the simplicity of this project I would say any will do, or like in my other instructables an atmega standalone circuit will also do)
  • Resistor
  • HC-SR501 Motion Sensor
  • LED (optional)
  • A lamp, or anything you want to switch on
  • Relay board
  • ULN2x03A
  • Breadboard / Perfboard
  • Maybe a photoresistor if you don't want the lights to turn on during daytime

The tools:

  • Cable stripper
  • Knife
  • If you are not going to build the project on a breadboard: soldering iron
  • Pliers

Step 2: The Circuit

As we need multiple connections to 5V and GND, connect the 5V and GND Pins of your arduino to the rails of a breadboard.

Connect D1 and D2 to the inputs of your ULN2x03A.

Connect the according outputs of your ULN2x03A to IN1 and IN2 of your relay board. Connect VCC and GND of the relay board.

I used a ULN2x03A because you shouldn't switch inductive loads like relays directly with the arduino, as the current draw most likely exceeds the safe rating and may damage your chip.

Connect Pin 9 and 10 of the ULN2x03A to GND and 5V.

Connect an LED with a suiteable resistor (I used 450 Ohm) to GND and Pin 13 of the arduino.

Connect the GND and 5V pins of the motion sensor to your power rails, and connect the output pin to Pin 3 of the arduino.

Disconnect everything from power before you start cutting / connecting any cables. You are working with mains voltage. Mistakes can lead to serious injury or death. If not done correctly, you may also start a fire. I do not take responsibility for any damages done to you, others or your property. I'm not an electrician, so maybe the way I did is not correct either. If you do not know what you are doing or feel uncomfortable, leave the project be or consult someone who knows. Proceed at your own risk.

Cut the power cable of your lamp, and connect the cables from the power plug to the COM ports of your relay. Connect the cables from the lamp to the NO (normally open) terminals.

I live in europe and devices such as lamps with no earth lug usually are euro plugs, and do not have polarity protection. So in my opinion it is not enough to just switch one cable, as you may be just switching neutral and the lamp is still connected with the phase cable. With switching both cables I make sure the lamp is really disconnected from power when off. 2 channel relays are not expensive, you should do the same.

Step 3: The Code

I tried to comment all important steps. I included the watchdog timer because in my setup with the bare atmega chip, the system would hang occasionally every few days and I came home to a dark hallway. So far this seems to have fixed the problem.

Due to the bad lighting conditions in my hallway, even during day time, I didn't bother to include something to distinguish between day and night time, as my photoresistor wasn't sensitive enough.

If you can, get a cheap photoresistor like this one. You can use the trim poti to calibrate it. Add something like

if (value == HIGH && valuephoto == LOW) // motion detected and the photoresistor outputs that the hallway is dark

to the code.

int relayp1 = 1; // Relay Pin 1
int relayp2 = 2; // Relay Pin 2 int IRmotionPin = 3; // Input from Motion Sensor int LED = 13; // LED

int value; // value (HIGH or LOW) of the motion sensor

#include // include watchdog timer

void setup() {

// set all the pin modes pinMode(relayp1, OUTPUT); pinMode(relayp2, OUTPUT); pinMode(LED, OUTPUT); pinMode(IRmotionPin, INPUT);

// set all the pins to initial conditions digitalWrite(LED, HIGH); digitalWrite(relayp1, LOW); digitalWrite(relayp2, LOW); delay(2000); // LED should be on for 2 sec so I can see that the board is powered up, important to me as I used the bare chip, otherwise I wouldn't have any indication if the system is booting digitalWrite(LED, LOW); wdt_enable(WDTO_8S); // If the system hangs for more than 8s, the system should reboot }

void loop() { value = digitalRead(IRmotionPin); // get the state of the sensor

if (value == HIGH) // motion detected { digitalWrite(relayp1, HIGH); // turn on the lamp digitalWrite(relayp2, HIGH); // turn on the lamp

for(int i=0; i <=120; i++){ // lamp should stay on for 2 minutes delay(1000); wdt_reset(); // reset the watchdog timer }

digitalWrite(relayp1, LOW); digitalWrite(relayp2, LOW); } else { wdt_reset(); // if the reading is LOW, do nothing, BUT reset the watchdog timer }

}

Step 4: Putting It Together

I drilled a small holein the back of my cabinet in my hallway, to put the system and power outlet out of plain view. I used some double sided adhesive tape to fix the motion sensor.

Share

    Recommendations

    • Audio Contest 2018

      Audio Contest 2018
    • Furniture Contest 2018

      Furniture Contest 2018
    • Fix It! Contest

      Fix It! Contest

    2 Discussions

    0
    None
    JorgD5

    Question 6 months ago

    can i ask why you put an arduino between it?

    the pir can be used directly with a relayboard with its 5min to 1 sec timer adjustable potentiometer. if you realy need to control it for a longer time i would suggest an attiny85.

    or if you wanne control it or send data for cheap use a esp8266-01s

    just wanne help :)

    1 more answer
    0
    None
    chuck-finleyJorgD5

    Answer 6 months ago

    Thank you for your input. I actually used a standalone atmega chip but referred to an arduino in the instructable for the simplicity. I originally planned to combine the project with a sensor for day and nighttimes but found out that the lightning conditions in my hallway would not really allow me to sharply distinguish between the times I need the lamp to turn on or not by a photoresistor. I will probably extent the project with a solution to that that justifies the need of a controller of some kind in the future. This was one of my first projects with the arduino/atmega so I kind of missed the opportunity that I don't really need it. Good catch!