HELP !!!! Watchdog timer in Arduino mega 2560

Hello every one

Can some one help me out in how to use watch dog timer in an program

I want that if there is no input on pin A0 for 5 sec a subroutine should run(i.e. led on pin 13 should be ON)

I want that if there is no input on pin A0

What do you mean by "no input"?

What do you mean by "no input"?

I think that pretty well sums up the semantic content of OPs posts.

no input means 0V at any pin

Actually i have made an home automization project

in my project i am using resistive touch screen

so i want that then there is no input from my touch screen pin for 5 sec i want to run a particular subroutine.

hope this makes my problem more clear

no input means 0V at any pin

Not in general it doesn't. 0V at an analog pin may be perfectly reasonable.

Why do you think you need to use the watchdog? More people get bit by watchdogs than are protected by them.

Is there some other way to solve my problem without watchdog ???? please tell me

Is there something wrong with your punctuation keys?

Is there some other way to solve my problem

If we knew what your problem was, probably, yes.

sorry for the punctuation keys

my problem is that

if there is no signal from my touch screen for 5 sec i want to run a particular subroutine

hope you get my problem

Every time you get input from the touch screen, note the time (using "millis")
Every time through your main background loop, check the current time, and see if it is more than 5000 milliseconds since the noted time.

so i want that then there is no input from my touch screen pin for 5 sec i want to run a particular subroutine.

Every time there is input, reset the time when input occurred.

Periodically, see if now minus then exceeds some interval. If so, call the routine. No chain, no dog-food bowl, no dog food, no pooper scooper, no rabies shots.

Thanks for information

let me try that out

does mills() work in background ?

does mills() work in background ?

No, but that's OK since there is no "background". The Arduino doesn't have an operating system, and only one process space.

I don't know what you mean by that, but millis() works in setup() and loop() and code called from them if that's what you're asking. If in doubt, try it - there are plenty of examples showing how millis() can be used.

thanks guys

i will work on it

Uhmm.. I appreciate how you guys were able to solve the problem with the "no input"...

But uhmm how do you actually write a watchdog code for Arduino Mega?

wdt_enable(WDTO_8S); does not work as what I am experiencing.. in mega adk..

Like

#include <avr.wdt.h>

void setup()
{
  Serial.begin(9600);
  wdt_disable();
  wdt_reset();
  
  wdt_enable(WDTO_8S);
  Serial.println("setup");
  
}

void loop()
{
  
}