The issue has come back. I have disabled the reset fuse which has shown to clear up the issue. So I wonder if I can conclude that it is noise on the reset line.
The ATmega48PA/88PA/168PA/328P has four sources of reset:
• Power-on Reset. The MCU is reset when the supply voltage is below the Power-on Reset
threshold (VPOT).
• External Reset. The MCU is reset when a low level is present on the RESET pin for longer than
the minimum pulse length.
• Watchdog System Reset. The MCU is reset when the Watchdog Timer period expires and the
Watchdog System Reset mode is enabled.
• Brown-out Reset. The MCU is reset when the supply voltage VCC is below the Brown-out Reset
threshold (VBOT) and the Brown-out Detector is enabled.
#include <avr/sleep.h>
#include <avr/interrupt.h>
int counter;
void setup(void)
{
Serial.begin(9600);
Serial.println("Started");
counter = 0;
pinMode(2, INPUT); // our sleep interrupt pin
digitalWrite(2, HIGH);
}
void loop(void)
{
counter++;
Serial.println(counter);
GoToSleep();
}
void wakeUpNow()
{
}
void GoToSleep() // here we put the arduino to sleep
{
Serial.println("Sleeping");
Serial.println();
Serial.println();
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
attachInterrupt(0,wakeUpNow,RISING);// Use pin 2 to wake up
delay(500);
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep: disable sleep...
detachInterrupt(0); // disables interrupt 0 on pin 2 so the wakeUpNow code will not be executed during normal running time.
}