Hi
I am using an Arduino as a crude watch dog. I am sending data into the serial port. If the data is "A" all is OK but if the data is "B" the Arduino is opening a relay. This works fine. However I would like to add a check so that the relay opens if the data stream fails because the sending computer hangs or the serial lead falls out. Being very new to the Arduino I cannot figure out how to go about this. Any advice appreciated.
Regards
Ian
Just to be clear, is your an Arduino with a USB to serial interface, or a 'real' serial interface?
Have you programmed before, and you are looking for information on which signal the USART will raise if the 'carrier' is dropped, or how to set up a watch dog timer?
How long will this be running (hours, days, weeks, years?)
At the risk of mis-answering your question, apologies in advance ...
Are you using code like the SerialCallResponse example?
You can modify that to get a simple watch-dog timer effect.
Create a variable to store the time that the Arduino last saw some data, e.g.:
unsigned long lastTime;
and a variable (or macro if you know C/C++) initialised to a suitable value:
long watchDogTime = 10000; // 10 seconds in milli seconds
initialise lastTime:
void setup()
{
...
lastTime = millis(); // initialise watch dog timer
}
void loop()
{
// if we get a valid byte, everything okay:
if (Serial.available() > 0) {
lastTime = millis(); // reset watch dog timer
...
} else if (millis()-lastTime > watchDogTime) {
// watch dog timer tripped
...
}
}
[edit]Ooops - I ask about the time this will need to operate correctly because the millis() timer wraps when it overflows. [/edit]
HTH
GB
Ooops - I ask about the time this will need to operate correctly because the millis() timer wraps when it overflows.
One change and the wrap is no longer a concern...
[glow]const unsigned [/glow]long watchDogTime = 10000; // 10 seconds in milli seconds
Hi
Many thanks.
The serial is USB.
Running for up to 24 hours.
Yes I am using the SerialCallResponse routines.
I have programmed before but business programmes coded in TAS don't give much help when using something like Arduino. I knew timing was involved but just could not get my head round it.
Just out of interest how would you check the USART if the carrier dropped?
Regards
Ian
The serial is USB.
...
Just out of interest how would you check the USART if the carrier dropped?
I believe that Data Carrier Detect (DCD) needs a reasonably complete RS232 interface. I don't believe there is a way to detect a dropped carrier if you are using the Arduino's normal FTDI USB to serial.
Are you powering the Arduino from the USB? It will 'die' if the USB cable is removed.
HTH
GB
Hi
I am powering from USB. The system works well thanks to your help. If the USB cable is removed the relay opens and if the connected PC fails in any way the relay opens. So I have achieved the result I was after.
My question about the carrier was academic as I am trying to understand the Arduino and the way it works more than I do.
Regards
Ian
My question about the carrier was academic as I am trying to understand the Arduino and the way it works more than I do.
Keep asking. I think we are all here to learn 
I seem to have the process:
- Read it => remember,
- Do it => feel confident
- Explain it to a reader => understand
- Teach it to a doer => learn what I didn't understand

Take care
GB