Motion Sensing Micro-Processor Controled Night Light
Intro: Motion Sensing Micro-Processor Controled Night Light
Getting up at night to go to the bathroom or whatever has just gotten a whole lot better on the account of my motion sensing nightlight
I place this under the bed and as soon as you get up the sensor will detect motion and on comes the light.
This night light uses the popular PIR sensor to detect movement.
Then the ATtiny 2313 processes the signal and turns on the LED's for the set 2 minute, then off and waiting for another signal.
Repeat and repeat.
I place this under the bed and as soon as you get up the sensor will detect motion and on comes the light.
This night light uses the popular PIR sensor to detect movement.
Then the ATtiny 2313 processes the signal and turns on the LED's for the set 2 minute, then off and waiting for another signal.
Repeat and repeat.
STEP 1: ATtiny2313 Vs ATtiny85
So why use a ATtiny2313 and not an ATtiny85, when a ATtiny85 seams to be the more logical one to use?
The ATtiny2313 has many more pins than this project could ever use. Over kill on the pin count.
That also makes it psychically bigger that say a ATtiny85. 20 pins instead of just 8.
It doesn't have the byte capacity of a ATtiny85. ATtiny2313 has 2K bytes verses the ATtiny85 8K bytes.
Like most everything it comes down to cost. The ATtiny2313 is the cheapest micro-processor i can get in my area, when shipping ect is factored in.
ATtiny2313 is $1.75 USD. Where as an ATtiny85 is $4.50 each if i buy 2.
ATtiny2313 PDF
The ATtiny2313 has many more pins than this project could ever use. Over kill on the pin count.
That also makes it psychically bigger that say a ATtiny85. 20 pins instead of just 8.
It doesn't have the byte capacity of a ATtiny85. ATtiny2313 has 2K bytes verses the ATtiny85 8K bytes.
Like most everything it comes down to cost. The ATtiny2313 is the cheapest micro-processor i can get in my area, when shipping ect is factored in.
ATtiny2313 is $1.75 USD. Where as an ATtiny85 is $4.50 each if i buy 2.
ATtiny2313 PDF
STEP 2: Code
The ATtiny2313 only has 2000 bytes of flash memory available, but this sketch has 2572 bytes.
So how do we get all that is there?
We comment out all the serial communication in the sketch.
Those 3 lines of code took up a whopping 1438 bytes of flash that aren't used in the completed project anyway.
Use the serial communication when you are testing with your Arduino board.
Later when the sketch is transferred to the ATtiny2313, comment the serial out.
With the serial commented out and the code we will add for this project the sketch size will only be 1324 bytes total.
Great we are defiantly under the 2000 byte max limit.
This sketch is from ladyada, but has a 2 min delay add by me.
/* PIR sensor tester*/
int ledPin = 9; // Chip Pin Number is 12. choose the pin for the LED
int inputPin = 11; //Chip Pin Numbre is 14. choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
//Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
//Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
delay(120000); // <<<<<<<<<<< This delay was added giving us the 2 minute LED on time - Change as needed
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
//Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
STEP 3: Programming
STEP 4: Power Supply
I really like these cellphone charger type power supplies. Al-tho this one happens to be from a D-Link router.
I have found they always output more than the rated amount. This is rated at 5v. Actual output is 7v.
After running it through the LM7805 voltage regulator i measure 5.01v output. Just write.
I have found they always output more than the rated amount. This is rated at 5v. Actual output is 7v.
After running it through the LM7805 voltage regulator i measure 5.01v output. Just write.
STEP 5: Diagram
This is about as simple as i could make it.
STEP 6: Board and LEDs
The board is fairly simple with only 8 components.
For the LM7805 voltage regulator i used 2 #104 capacitors. That is not what the book calls for but i have found it works well enough i can not measure the difference with a DMM.
There is a 20 pin socket for the ATtiny2313 to sit in, then a 4K7 ohm resistor from pin 12 ( set as an output ) to the base of a 2N2222 transistor that is used to switch the ground on and off of the LED's. The positive side of the LED's are always connected to VCC.
Pin 14 is an input for the PIR sensor.. Pin 10 is ground and pin 20 is VCC.
The voltage regulation is set up like in the picture.
That's it, 4 connections.
Parts:
For the LM7805 voltage regulator i used 2 #104 capacitors. That is not what the book calls for but i have found it works well enough i can not measure the difference with a DMM.
There is a 20 pin socket for the ATtiny2313 to sit in, then a 4K7 ohm resistor from pin 12 ( set as an output ) to the base of a 2N2222 transistor that is used to switch the ground on and off of the LED's. The positive side of the LED's are always connected to VCC.
Pin 14 is an input for the PIR sensor.. Pin 10 is ground and pin 20 is VCC.
The voltage regulation is set up like in the picture.
That's it, 4 connections.
- Pin 10 GND
- Pin 12 out to Transistor
- Pin 14 in from PIR
- Pin 20 VCC
Parts:
- Attiny2313
- 20 Pin socket
- 4K7 resistor
- 2N2222 Transistor
- LM7805 Voltage Regulator
- #104 cap
- #104 cap
- Power Jack
- 9 components if you count the perf board
STEP 7: Prepare the Case
These are some containers i bought, 83 cents for 5 with lids. Affordable!
They are about 7x5x2 inch measurements.
Luckily this container had a ring all the way around it at the middle that i used a a guide line.
Just measured out 1 inch spacing and got the hot soldering iron out and started making holes.
7 holes 5 mm in diameter so the LED's had a snug fit.
They are about 7x5x2 inch measurements.
Luckily this container had a ring all the way around it at the middle that i used a a guide line.
Just measured out 1 inch spacing and got the hot soldering iron out and started making holes.
7 holes 5 mm in diameter so the LED's had a snug fit.
23 Comments
byron.green.904 3 years ago
diy_bloke 9 years ago
With just a quick look I got the program down to 984 bytes (in IDE 1,0) and 916 bytes (in IDE 1.6). that way it would fit in an attiny10 that is even cheaper than the 2313.
getting those last bytes off:
dont use constants for the pin numbers, just use the pin numbers.
shorten the names of your variables to 1 character
don't use 'int' for only storing small numbers, use 'byte'
diy_bloke 9 years ago
with regard to cost: if you havent already.... check out aliexpress. I know this instructable is 2 years old, but even then 4.80 for an attiny85 is outrageous.
I think currently when bought in bulk the attiny2313 is 70 euro cnts and the 85 some 95 eurocents
pete54321 10 years ago
Somewhere between 11pm and 5am or so?
WWC 10 years ago
If you search on here you will find what you are asking about.
Ridach 10 years ago
WWC 10 years ago
You are wanting to use 12v because your led strip uses 12v i am guessing.
The answer is yes, BUT in supplying 12v to the circuit board that only requires 5v then you will have to burn off 7v. Instead of using the 78L05 voltage regulator that i have used I would switch to a LM7805 voltage regulator and use a heat sink for it if it is getting hot.
Are you planning on making 2 circuits, one for the top of the stairs and one for the bottom or connecting 2 PIR sensors together into one circuit?
Ridach 10 years ago
WWC 10 years ago
Other than that which way is better is subjective depending on who is building it ect. Either way you will have wires running up and down the stairs several times unless you went wireless.
The 2 main ways i spose is have each PIR go into one controller or build 1 controller for each PIR, that you will have to decide.
One thing is if you used 2 controllers you would not have to change the program. If you used one controller you will need to change the program. I don't know how comfortable you are with Arduino programming.
I would like to see what you build.
Good Luck
Wayne
Toby Robb 10 years ago
WWC 10 years ago
Toby Robb 10 years ago
WWC 10 years ago
WWC 10 years ago
Toby Robb 10 years ago
WWC 10 years ago
WWC 10 years ago
Strontium 10 years ago
WWC 10 years ago
shannonlove 11 years ago
As an enhancement, you should consider using the red LED. You might need to check the spectrum but red light does not interfer with night vision. So, if your light goes off, the power goes off, you go to another dark room etc, you can still see.
I had a red light night light years ago I put in my bathroom. Made a big difference sliding back into bed trying not to wake the spouse. With the red light, I could see plainly in the dark when I came back to bed, without it, well, there was spousal grumpiness in the morning. Wish I could find those again.