Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

School project - Occupancy sensor light switch

Not open for further replies.


Newbie level 2
Apr 26, 2015
Reaction score
Trophy points
Activity points
Hello there :)

I'm new on this Forum... but I need some help for my school project : :dance:
We came up with this project:

- It's a motion sensor that will be linked to a timer (5min) that will turn off the light(s) if no one is in the room after 5min.
The motion sensor and timer will be connected to the light switch.

Is anyone has any idea of how to make this ... ?

Thank you very much in advance for your help :)


Can you use PIC microcontroller for the project ?

Hello Milan, yes I can use anything pretty much to build this project

Driveway motion sensor work ok except have ambient light adj for disabling during daylight so adjustment needed.

To replicate the design with low voltage, you need several 100mA pulsed IR senders and a diffused wide angle IR detector.

The pulses are sent and detected by separating the light inside so only outside reflections are strongest. Then the level is high gain AC amplified and then peak detected. This DC is then rectified again for variation or a Photo Receiver chip with AGC on the same wavelength (e.g 850 nm) is bridge rectified for change in signal due to motion. A window comparator circuit with two open collector outputs are joined so that either a drop in refelction or a rise means motion has occurred.
The response time depends on the low pass filter so use 10 seconds or 1 minute with plastic film caps and 10Meg Rs to achieve .if the teacher is motionless, the lights will go off, so normally a CD4060 5 minute timer , reset by motion ( inverted window detector low = reset high ) is all you need.

Make sense?

The IR senders are cheap 1V 100mA 5mm IR diodes in series with R to 5V to limit current.
The rep rate can match a TV Rx chip at 22kHz or whatever with AGC works well up to 30m with analog AGC out . Ac amplify this to window detector. Use a fresnel film lens or similar plastic to disperse light with low ref
Internal refection if IR Rx is not black, (daylight blocking filter) it will pick up FL lamp flicker.

Fine the attached mikroC PRO PIC code. It uses PIC16F628A with 4 MHz internal oscillator. WDT is disabled. MCLR is disabled. See image for circuit. If you want to drive a light then remove the LED and connect a BC337 and a relay. Also connect a 1N4007 diode in parallel to relay coil so that cathode connects to Vcc and anode to collector of BC337.

Proteus 8.2 SP2 format file is also included. You have to use PIR sensor for motion detection. I don't remember whether the signal given by PIR sensor is high to low or low to high. I have coded for low to high. If it doesn't work with your PIR sensor then just change

INTEDG_bit = 1;

INTEDG_bit = 0;
in code and compile.

To do this you will need mikroElektronika's mikroC PRO PIC compiler. As the code is small it will compile in demo compiler. Just download and install mikroC PRO PIC compiler if needed.

Edit : Circuit with relay attached.

Edit: My mistake. The code is wrong. I will post the fixed code soon.

Edit: Fixed the code. When motion is detected it turns ON the light and starts a 5 minutes timer. If no motion is detected for 5 minutes then it turns OFF the light. I think this is what you need. If yes, use ver2 project.


  • Light Switch.rar
    39.8 KB · Views: 60
  • Light Switch.png
    Light Switch.png
    13.2 KB · Views: 62
  • Light Switch Relay.png
    Light Switch Relay.png
    22.5 KB · Views: 62
  • Light Switch Relay.rar
    16.5 KB · Views: 58
  • Light Switch ver2.rar
    76.1 KB · Views: 59
Last edited:

It may be excellent code, but excellent optical gain change or reflected IR change up or down with high sensitivity and threshold and time delay control comes first.

As it is a school project, I think PIR sensors from eBay can be used for the purpose.

I have used this PIR sensor for motion detection and never faced problems.

**broken link removed**
Last edited:

You can also use any 8 pin PIC12F for the project. I don't know which PIC is available at your place. If you decide to use 8 pin PIC12F device then let me know and I will post a project for it.

Edit WDT enabled project attached. Just to make sure that your project doesn't hang during demonstration.

- - - Updated - - -

Fixed code attached.


  • Light Switch WDT enabled.rar
    44.5 KB · Views: 95
  • Light Switch PIC12F683.rar
    46.8 KB · Views: 51
  • Light Switch WDT enabled rev1.rar
    44.6 KB · Views: 90
  • light switch.png
    light switch.png
    27 KB · Views: 58
Last edited:

Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to