I might be missing a resistor or something, but with the following code and prototype layout, is there something I'm missing? The logic seems to work out ok in the code, the relay 'led' lights, but the relay doesn't actuate every time the PIR goes HIGH. Sometimes it does, sometimes it doesn't. I don't get it.

What is the coil resistance of that relay?If that's less than 150? then you don't want to run it directly from an Arduino output, it needs the help of a transistor.Does the fritzing diagram indicate a "flyback diode" across the coil, too?(There are solid examples for using relays and transistors at the Arduino Playground.)

"Who is like unto the beast? who is able to make war with him?"When all else fails, check your wiring!

I don't see a resistor on the led either, that could be drawing the power supply down enough to make the relay unreliable. You are probably frying your Arduino outputs. Might slow things down too, I know I can't see a led change state in a few microseconds.TomJ

Einstein once said you don't really understand anything until you can explain it to your Grandmother

Sorry about the coloring. Is there a standard? I used black for power, green for ground, red for signaling. I removed the LED as you suggested. I get the same results. I'll check out the tutorial. Thanks for the link!

Not sure if it's a colour standard in the official sense, but take your cue from the sensor you connected to where the wires started out as red for +ve, black for ground and yellow for control.... servos are the same too.

Red and black for 5 and 0 is pretty much standard....

It would certainly be worth hooking the relay to its own power and simply using the Arduino as control.

And to use a transistor to control the relay. NEVER connect a coil Like a RELAY COIL TO AN Arduino pin, unbuffered.

Bob

Well that is a little drastic isn't it? There are many small DC 5 volt reed relays that draw well less then 30ma and as long as you install a diode across the relay coil terminals you can drive them fine directly from a arduino output pin, I've done it frequently with no drama.

Thank you guys for the education. I'll update my wiring with the proper colors to the proper locations, and grab a diode on the way home from Radio Shack. The specs show this relay will work fine with 15-20mA triggering. I've confirmed that by using the signal from the PIR, which flips the relay on and off every time the PIR goes HIGH/LOW. I think the problem is the missing diode. I'll update after I try that.

So if you are using that relay directly without the module, you will need a transistor (and still the diode to protect that transistor).

If you are using the module, you do not need a diode because the module has transistors and diodes built in.But you will need to power the module and there's no sign of you doing that in your Fritzing sketch.

I wanted to activate a relay ONLY when the PIR was initially activated, kinda like a light switch; wave your hand, the light comes on, then again later to turn it off. The Sainsmart relay module didn't need any additional diodes, resisters, etc. The voltage and signalling provided by the Arduino Uno is sufficient. The problem was in my code. Here is it in case anyone should need it. Thank you all! My first project, now I just need to mount and solder and get it installed in my new custom-made headboard.