Arduino w/ relais stops working after a while

Hi there,

we recently opened up an exhibition which does also have some Arduino-based interactive samples. One of them is an old phone booth which stands on a base in which a pair of speakers and an in-wall motion sensor (like the ones found on normal house lights) were mounted. We have an Arduino plus Waveshield, and what happens is that if someone’s walking by the booth, a sound is played.

Since the motion sensors work on 240V, we used a relais to “connect” it to the Arduino. So what happens is that as soon as the motion sensors detects movement, he allows the current to pass, triggering the relais which then allows another current from/to the Arduino to pass.

We connected one digitalout with another through that relais, whereas the “input” pin is also connected to GND via a resistor (puldown). We tried it out and it worked like a charm. Now that the booth is “out in the wild”, we found out that the Arduino stops working after a couple of hours.

It’s really hard to find the problem since I can’t sit next to it four hours with my computer connected just to wait until it doesn’t work anymore and see if there’s an error message on the Serial port. I also can’t leave my computer there because it’s arranged in a public space. So maybe someone here has an idea what could be the problem (already tried another Arduino and/or Waveshield).

Here’s a very rough version of the wiring (sorry, not really experienced with this) as well as the code. The code does run through all the files, I checked that. But at some point, it just doesn’t work anymore… :frowning:

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

//Variables for Audio...

long lastAction = 0;
long pauseBetweenActions = 30000; //ms before another sound is triggered

int in1 = 9;
int out1 = 7;

int playIndex = 0;

void setup() {
  pinMode(in1, INPUT);
  pinMode(out1, OUTPUT);

  //pinMode(13, OUTPUT);

  digitalWrite(out1, HIGH);
  //Audio setup goes here...

void loop() {
  if(millis() - lastAction > pauseBetweenActions) {
    if(digitalRead(in1) == HIGH) {
      switch(playIndex) {
      case 0:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
      lastAction = millis();
      if(playIndex == 10)
        playIndex = 0;
      //playIndex = (playIndex == 4 ? 0:playIndex++);

void playfile(char *name) {
  // the file

Thanks for your suggestions,

Why are you using an output pin to provide your HIGH? Would it not be simpler to use the internal pullups, and invert your logic, saving a pin and an external resistor?

What is a “relais”?


  if(millis() - lastAction > pauseBetweenActions) {

The call to delay and your if statement are redundant.

what is a relais?


It is what ever his translator thinks a relay is.

That schematic tells us nothing about how it is wired up. A relay needs a driver what sort of circuit is this? Have you fitted reverse protection diodes on the relay coils?

Is it your design or is it some artist somewhere?

anymore and see if there's an error message on the Serial port.

Are you expecting an error message? There is nothing in the code you posted that would give you one.

I agree with Groove. There is no good reason to rely on 2 pins to sense a relay's switch closure.

The above link is all you would need to sense relay switch closure.

There is no good reason to rely on 2 pins to sense a relay's switch closure.

Very true but there is no reason why it wouldn't work or why it would stop working.

When it does stop working will pressing the reset button start it again or does it need a power cycle. When it does stop working can you still hear the relay clicking, if not it might be more of a problem with the sensor rather than the arduino.

My bet is that you have a logic problem somewhere that causes the program to wedge, and you have no choice but to debug it properly. Welcome to the world of software testing.

Hi guys,

first of all sorry for the late reply. I just moved into another flat and I don't have an internet connection yet so I had to wait until Monday :) I'll just go through all your answers:

@Groove: Why do I use an output pin to provide HIGH? I'm not coming from electronics (you can tell) but rather from computer science, and it seemed logic to me that, if you want to listen for a digital HIGH, you should also "send" a digital HIGH. I know the difference between LOW and HIGH is simply a change in voltage, but I still found this to be a logic approach... is there a reason why using the internal pullups with inversed logic is better - besides saving a pin and a resistor?

@James: a relais is a relay. I used the German word (actually it's a French word, so I thought it would be "international", sorry...). Oh, and the redundant stement was just a leftover from some earlier debugging...

@Grumpy_Mike: yupp, I thought that my schematic won't help you too much. The thing is: I'd really love to get into all that electronic stuff (and I will), but this time we did not have the time since we had to finish this thing. We had one "electronics guy" who put together the relay and the sensors and told us where we could plug in our input and output cables, so for us it's basically a black box. Unfortunately he's not available at the moment so we'll need to wait until we can ask him about the details... All I could do so far was using a Voltmeter to see if the relay actually does what it's supposed to do, and it does. If the sensors are triggered, the relay allows the current to pass from one digital pin to the other for about 20 sec.

About the error messages: There's nothing in the code I posted because I left out all the Serial.printlns for better readability.

I can't remember if resetting the Arduino was sufficient, I'll try that later today. The relay is definitely working.

@pwillard: Alright, we'll switch to the 5v pin then. But what I'd like to know is: is there really a difference if we use 5v instead of a digital pin that is set to high, or should we do it simply because it's a standard of good practice?

@gardner: I'm already an inhabitant of the world of software testing. C# and Java are already stealing lots of my time ;) Anyways, I just thought that I'll also post a thread here just in case it's some obvious problem i was overlooking. Debugging is a pain in the *** since it takes a really long time before the program crashes... Debugger would be awesome ;)

Thanks for all your replies and suggestions. We'll go back to the installation tonight and do some more testing, so hopefully we'll get that thing to work. I'll keep you updated.

Can you disconnect the relay and see if the Arduino still stops working after a few hours - maybe by including an LED blink as a heartbeat?

I know nothing about the libraries you are using, but stopping working after a few hours sounds like it could be a memory issue.

I also come from a comp sci background, but I recognise that I/O pins on a microcontroller should not be squandered.