How do I make sure Arduino is working properly?

I am using Arduino Duemilanove and Ethernet Shield with 2 buttons and 1 motion sensor attached. There's also a relay attached which turns on when a certain condition is met. The ethernet shield is used to send command to a display software which is set on port 3040. When upon receiving any command (basically text) from Arduino, would change the projection. This software also controls DMX lighting. The working of the whole stuff goes like this.

At the beginning, all DMX lighting were set to off. When any motion is detected by the sensor, Arduino would send command to the display software to run any images or video into projection and turn the lights on. This would run for a while until this display software sends a text back to Arduino and sets the relay on for a few seconds. This relay is actually used to trigger a custom radio which upon on would start outputting some sound until it end itself which is some 30 seconds. After this radio ends, all DMX lighting would light up. The lights would go off after 10 minutes and this thing repeats.

The odd thing, based on a number of test we've done (~20 times):

  • Two or three times, Arduino didn't detect anything from the motion sensor even though there's someone walking through it.
  • The relay doesn't trigger even though (assuming) Arduino receives command from the display software.

So my questions is:

  • How do we make sure Arduino is actually working properly? I read about logging, is there any other way of making sure Arduino is behaving like the way it is programmed? Either through hardware component logging or software logging (gobetwino).
  • Can anybody shed some light on their first hand experience on logging, preferably software logging, like gobetwino?
  • This is more of a connectivity issue, how do I make sure that Arduino with its Ethernet Shield is always connected? I put the following block of code inside the loop() but when I tried to check the connection availability, it doesn't show anything. Looks to me the ethernet library is buggy.
if(!client.connected()) {
    client.connect();
    Serial.println(client.connected());
}

Thanks and appreciated!

Does the failure of the sensor to trigger action occur when the ethernet shield is not connected, too?

If so, remove the ethernet shield, and write a simple sketch to react to the sensor. Only when the hardware and software is known to work should you try to integrate it into the whole sketch/hardware setup.

The same holds true for the relay. Remove the ethernet shield, and write a simple sketch to toggle the relay once a second.

How do we make sure Arduino is actually working properly?

Write simple sketches to test the hardware individually. User Serial.print(ln)() to send data to the PC, to be displayed in the Serial Monitor.

Can anybody shed some light on their first hand experience on logging, preferably software logging, like gobetwino?

Do you really need to log the output, or are you just looking to view the data?

If I wanted to log it, I'd use Processing to interface with the serial port (there are examples provided), and write all data received from the serial port to a file.

This is more of a connectivity issue, how do I make sure that Arduino with its Ethernet Shield is always connected? I put the following block of code inside the loop() but when I tried to check the connection availability, it doesn't show anything. Looks to me the ethernet library is buggy.

Is the Arduino acting as a client or a server? If it is a client, you can't force it to be connected if the server refused the connection request.

If it is a server, you can't force a client to be connected, either. Clients have to connect on their own. The server needs to allow the connection.

Do you really have enough experience with the library to determine if there is a bug, or is it that you haven't successfully developed a project using the shield, so you aren't positive of what you are doing, and whether or not the library is working properly?

Does the failure of the sensor to trigger action occur when the ethernet shield is not connected, too?

If so, remove the ethernet shield, and write a simple sketch to react to the sensor. Only when the hardware and software is known to work should you try to integrate it into the whole sketch/hardware setup.

I forgot to say that out of roughly 20 times, the sensor didn't trigger for 2 or 3 times. The same thing happened to the relay, it didn't turn on for a few times. And it was random, like in one test the motion sensor fail to trigger but relay was ok. Next the sensor triggered ok but relay didn't seem to on. I'll do another isolated test case to make sure these 2 things work as expected.

Do you really need to log the output, or are you just looking to view the data?

If I wanted to log it, I'd use Processing to interface with the serial port (there are examples provided), and write all data received from the serial port to a file.

I am just looking to view the data. Part of the reason is, there's this computer with display software installed on and we've set it to start the project and lighting control automatically upon receiving button click from Arduino. And I resisted using the serial monitor because whenever it opens, Arduino would restarts. And also, it needs to be opened to see what's Arduino is printing. So I am more keen on to have a simple yet automated logging to see what excatly Arduino has been sending and receiving.

Is the Arduino acting as a client or a server? If it is a client, you can't force it to be connected if the server refused the connection request.

If it is a server, you can't force a client to be connected, either. Clients have to connect on their own. The server needs to allow the connection.

It is both client and server. Acting as client when it sends data to the computer of the display software and as server when it listen to any incoming data from the said computer.

Do you really have enough experience with the library to determine if there is a bug, or is it that you haven't successfully developed a project using the shield, so you aren't positive of what you are doing, and whether or not the library is working properly?

I apologize if 'buggy' is too strong a word for this case. I was saying that it seemed to me (based on a number of tests I did), the client.connected() function didn't return any result at all (as expected), both when the ethernet shield is connected and disconnected to LAN. Here's a block of code with extra detail removed. The reconnection in the loop part is where the oddity is.

void setup(){
Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(100);

  Serial.println("connecting...");

  while (!client.connect()) {
    if(client.connect()) {  
      Serial.println("connected");
      delay(50);
    }
    else {  
      Serial.println("connecting failed"); 
      delay(50); 
    }
  }
  Serial.println("connected");
  client.println("run\n"); //when connected at startup, do run
  }
}

void loop(){ 

  if (!client.connected()) { //reconnection in loop
    client.stop();
    if (client.connect()) {
      client.println();
      delay(50);
      client.println("run\n"); 
      show = false;
      buttonLock = false;
    } 
    else {
      Serial.println("Reconnect failed");
      delay(50);
    }
  }
}