# School project - Occupancy sensor light switch

Status
Not open for further replies.

#### Julie77

##### Newbie level 2
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 ... ?

Julie

#### milan.rajik

##### Banned
Can you use PIC microcontroller for the project ?

#### Julie77

##### Newbie level 2
Hello Milan, yes I can use anything pretty much to build this project

#### D.A.(Tony)Stewart

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.

#### milan.rajik

##### Banned
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

Code:
INTEDG_bit = 1;
to

Code:
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.

#### Attachments

• Light Switch.rar
39.8 KB · Views: 17
• Light Switch.png
13.2 KB · Views: 32
• Light Switch Relay.png
22.5 KB · Views: 34
• Light Switch Relay.rar
16.5 KB · Views: 15
• Light Switch ver2.rar
76.1 KB · Views: 15
Last edited:

#### D.A.(Tony)Stewart

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.

#### milan.rajik

##### Banned
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.

Last edited:

#### D.A.(Tony)Stewart

Agreed, several to cover all zone and a CD4060 timer to Mosfet is all that is need plus DC and LEDs or Relay to AC.

#### milan.rajik

##### Banned
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.

#### Attachments

• Light Switch WDT enabled.rar
44.5 KB · Views: 61
• Light Switch PIC12F683.rar
46.8 KB · Views: 21
• Light Switch WDT enabled rev1.rar
44.6 KB · Views: 59
• light switch.png
27 KB · Views: 29
Last edited:

Status
Not open for further replies.