I was trying to create an LED under-the-bed lighting system for my parents. Here's the description:
"When someone puts their feet on the ground from the bed, it will activate a motion sensor that turns on the lights. I would like to have the lights stay on for at least 5 minutes. I would like to have this system connected to a power source and plugged in (not battery operated). Additionally, I would prefer to have LED strip lights on both sides of the bed (2 strips, I assume), as well as a motion sensor on each side of the bed (again, I assume this means 2 sensors) so that my Mom and Dad could activate their respective motion sensors when they put their feet on the ground."
I had a guy provide me schematics, a parts list, and the code, (all of which is attached) but I think there are a couple of glitches. First, the switch doesn't do what it's supposed to do (turn lights on when the IR sensor trips it, and turn lights off after 5 minutes), and I think there's something wrong with the wiring diagram close to the power source. The way it's wired, the LEDs never turn off, so I think they have to be wired at a different location than the schematic suggests. Either way, I'm hoping someone can help me understand where the glitches are and can help me out. I'd love to provide this gift to my elderly parents so they don't lose their balance when they get up in the middle of the night.
You paid actual money to some guy for this? Maybe I should change career!
No Arduino needed. The PIR sensors can trigger the relay themselves. You can adjust their sensitivity and the on-time with a small screwdriver. The Arduino is adding practically nothing to this circuit.
The code is amateurish.
The relay module has 2 relays but only one is used? Why? Could have switched the two strips separately. Or saved a little money by using a single relay module.
Appreciate the thoughts, PaulRB. I'm a woodworker and wanted to learn more about electronics, so I thought I'd get my feet wet with a simple project like this. Yes, I paid a couple of bucks but since I didn't know any better I figured I'd give it a go. Be gentle on a noob like me.
I'm a "learn by doing" kind of guy so if you have any suggestions about how to change the code and/or wiring schematics I'd very much appreciate it.
Is it one of your goals to start learning Arduino? If so, we need to find something for the Arduino to actually do. Right now, like I said, it has no purpose because you could connect the sensors to the relays and it would work just as well without the Arduino. If you want to get the project installed and working quickly, that's what I suggest.
So you could do that and then spend time making it better and including the Arduino.
You could, for example, get rid of the clicking relays, and have the led strips fade smoothly on and off over a couple of seconds, and just on the side of the bed where there is movement.
When reading it, I immediately thought about using capacitive sensors: a strip of aluminimum foil or so under the carpet, so the system reacts to someone touching the ground with their feet, not if you just hang your hand over the edge (which is what I often do). Also a bedsheet can't cover the PIR. It may even be possible to adjust sensitivity that it really needs a big foot on the ground before triggering.
You'd definitely need a microcontroller to do something like that.
Ok, great - thanks to everyone for your input. So, being a noob, can someone provide some guidance as to how to do this? I could absolutely use some help understanding how to put this all together so it actually works...
dducic:
Ok, great - thanks to everyone for your input. So, being a noob, can someone provide some guidance as to how to do this? I could absolutely use some help understanding how to put this all together so it actually works...
It's quite literally as described above - do some searches on Amazon or ebay or so.
Take 12V wall wart, connect on one end of PIR sensor, connect LED strip on the other side, and done. You may have to adjust the sensitivity a bit. That's it.
INTP, I was actually asking about how to connect everything with the equipment I have, which is listed above, and that's a little more involved than just plugging one thing in another with the equipment you showed (which is different from mine). I was looking for opportunities to learn a little about electronics and how they are all wired together.
I think I have enough to make it all work - thanks everyone.
I'd simply say, if you have bought all this stuff already and have got to the point of testing it, then continue.
You have certainly got the basis of a solution. You will also have a learning experience.
I'd suggest starting with a very simple sketch to begin to understand the behaviour of the passive IR sensors you have purchased so you can set these optimally for your project. It has 3 controls ( a jumper and 2 potentiometers) and seems to take 1 minute to stabilise after power on.
Use the wiring diagram you have and simply omit the second PIR and LED.
#define pirPin 2 // connect sensor 1 pin to arduino digital pin 2
#define relayPin 12 // attach relay pin to arduino digital pin 12
void setup() {
Serial.begin(9600);
Serial.println("Starting...");
pinMode(pirPin, INPUT_PULLUP); // set pir pin 1 input
pinMode(relayPin, OUTPUT); // set relay pin output
}
void loop() {
if ( digitalRead( pirPin == HIGH ) ) {
digitalWrite( relayPin, HIGH ) ;
Serial.println("Relay on");
}
else {
digitalWrite( relayPin, LOW ) ;
Serial.println("Relay off");
}
delay(1000) ; // 1 second. not nice but OK for a simple sketch.
}
Once you have got something working, you can start adding features eg the fading that has already been suggested, suppression of output during PIR stabilisation time, an LDR so that the light output can be supressed during daylight etc. etc. In parallel, you can start testing/using bits of the original sketch.
Thank you, 6v6gt - much appreciated. I will take your advice and give it a go. I'm a kinesthetic learner (learn by doing) so I will definitely follow your suggested approach.