W-Night Light One
Lets create a night light that is way better than a cheap one you see at the store with more features.
This project was intended as a follow-up due to one of my projects not working correctly (a remote controlled smart fan). For this project we are creating a night light with sensors and making it easy to assemble and place in any part of your house or building!
In the future you can also equip the chip with a wireless network or blue-tooth chip to notify if someone is in the room.
Our mission is to make a night light that doesn't use batteries and has decent sensing capabilities and functions to beat the current market of night lights. In the future we could also add capabilities such as bluetooth and wi-fi to our night light, but the mico-controller used in this project does not have enough pins. You may substitue the micro controller for any of your choice; just study the code below and fit to your needs.
A Slight Issue:
If a person or object stays within the specified range, the LEDs will remain on. If you want to fix this, just add another if statement to handle a continuos detection for the lights to be off. I would add this feature, but a normal person would just enter and leave the restroom, not stand there. During the first part of the video I was using an infra-red distance detector, but later switched to an Ultra-Sonic sound sensor. I want to thank my awesome buddy Masahiko for the help. Initially I was going to program it another way, but he taught me his way as it's efficient.
What You Will Need:
Most of the parts listed below can be found on eBay or Amazon. The micro controller chip I used can be bought from Microchip. A link will be on it below. If you can't get exact values for the part specifications, at least get something close or similar.
1x Perf Board
1x SPDT Switch
1x Pair Male and Female PS Socket 2.1mm
1x 12V ~ 9V PS Adapter 2.1mm
1x LM7805 Voltage Regulator
5x White LED (or any LED you like)
2x 0.1 ~ 0.4 uF Capacitor (ceramic or film)
1x GL5528LDR - Photoresistor
1x 10k ~ 12k ohm resistor
1x HCSR04 - Ultra-Sonic Sound Sensor
5x 200 ~ 300 ohm resistors
1x Microchip Pickit 3 -> ebay link
1x uC Microchip PIC16F18324 (or similar family device) -> microchip link
Video and Demonstration:
The video below also shows how to make the device with explanations and visuals to follow.
Schematic and Diagrams:
Below are the schematic for wiring your components to the chip and a diagram for setting-up the night light. You can set it up how ever you want though.
Hey, Almost Finished:
Now you need some sort of enclosure for this device. I just took a box and cut-it out to fit my device. I also used tape and a hot glue gun. You may use whatever you want. For the ultra sonic sound sensor, have it enclosed in something but make sure you don't block the transmitter and receiver. Make sure there are no open wires on your LEDs and circuit. I used velcrose tape or straps to stick the device and ultra sonic sound sensor to a surface.
Now for the code. First, the IDE I'm using is MPLAB v3.60 and the XC8 compiler...
The code below for the most part in the beginning is code that is setting our configuration for the PIC microcontroller. If you take a look at the data-sheet for the associated part you can see what each parameter does. Once we are done with basic configuration we are setting up the things we want to use on the microcontroller, such as a clock frequency, timers, and adc. After the while loop that runs forever we have functions and methods below. These functions are self-explanatory, but I will explain the interrupt one. This one is also responsible for how the night light works. Here we use a timer along with a capture and compare mode (or module) to know how far an object is based on how many clock edges. With that value we store it in variables mentioned above, which are global, and is used in the forever while loop in the main function.
The code was compiled using MPLab v3.61 Microchip, XC8 compiler.
Thank You and Good Luck:
Good luck on this project! I hope you find it fun and have learned something from it! I'm working on multiple projects (still), so I'm very busy!
Comments powered by CComment