Relay / sensor interference (?)

Hi,

I've got a PIR sensor which triggers an led (for testing) when it detects motion - the led stays on for a period of time, and switches off again. The led is on a timer, which resets each time the PIR sensor senses motion, so that the led switches off only when there has been no motion for a period of time. (This all works fine).

I've then tried to include a relay which controls an old fluorescent lamp (although no mains power at the moment). I've connected the relay (and tested it with a simple 1 second on/1 second off loop) and attempted to trigger it at the same time as the led, however with the relay included the led and relay switch on again immediately after the timer runs out (without any motion being detected).

I've tried to use the Serial monitor to work out what's going on, and it seems as though when the relay switches off it's causing the PIR sensor to trigger which restarts the timer. I know there are sometimes issues with interference from relays and have heard of some potential solutions (a separate power source for the relay?), but I have no idea where to start looking for a solution.

Any help would be great.

The relay is a single Songle SRD-05VDC-SL-C (http://iarduino.ru/img/catalog/111111111111111.jpg). I haven't included any further info on the wiring because it's working fine without the addition of the relay.

Matt

Ideally, posting a circuit diagram, an image of your project and your code would allow members to provide the best quality of help.

Ah well, my guess would be that its insufficient power to the Arduino. Note that if using 12VDC for power, thermal overload kicks in at a much lower current draw than if the supply voltage is lowered to 7.5VDC. Better yet, using the USB jack (if available) to provide power @5VDC will allow up to 500mA current draw.

Got caught up over Christmas, finally back looking at this now.

I've got rid of everything else I had connected so now it's only the relay and PIR sensor attached to the Arduino, with a simple sketch to test the reading of the PIR sensor when the relay is triggered. The same thing occurs - when the relay is triggered (and the lamp switches on) the PIR sensor registers movement although nothing has moved.

This is the PIR sensor I'm using (PIR Motion Sensor (JST) — Little Bird) and I've connected it following the instructions here (http://bildr.org/2011/06/pir_arduino/). I was a little confused by the instruction "Aside from power, the signal pin connects to any digital pin on your Arduino but also needs a 10k pullup resistor between the signal and 5V." but I think I worked it out. Have attached a photo of the project to make sure - if you need me to draw up a diagram, let me know (have never done so before).

Here's the code that I'm using to test it with:

int pirPin = 2;
int pirRelayPin = 10;

void setup() {

pinMode(pirRelayPin, OUTPUT);
pinMode(pirPin, INPUT);

Serial.begin(9600);

}

void loop() {

digitalWrite(pirRelayPin, LOW);

Serial.println("On");

Serial.println(digitalRead(pirPin));

delay(2000);

digitalWrite(pirRelayPin, HIGH);

Serial.println("Off");

Serial.println(digitalRead(pirPin));

delay(2000);

}

And the Serial Monitor reads the following (1 means no motion, and happens when Relay switches HIGH, and 0 should mean motion, and reads when the Relay switches LOW:

On
1
Off
1
On
0
Off
1
On
0
Off
1

The picture of the relay from their website (here) shows that it doesn't use an opto isolator, only a transistor to trigger the relay. In any case, you should power the relay separately with its own 5V supply (not coming from the Arduino). Just connect the GND of the second supply to the Arduino and do not use the Arduino's 5V to power the relay board.

Thanks so much! With the test code it seems to be working now. I'll hook the other sensors etc. back up tonight to make sure, but looking good. :slight_smile:

If you have to power the relay from the Arduino 5V, adding more decoupling, perhaps 100uF, would
be a wise precaution. If you can power it separately you shouldn't see problems (well once the mains
load is being switched that might cause interference of course).

Thanks for the suggestion, MarkT. Although it's working with a sep. power supply, it would be easier if I could power it directly from the Arduino. Where on the circuit would you suggest I place the capacitor? Based on what I've read, I'd put it between the Vcc and Gnd pins for the relay?