I'm new in Arduino, but have some basics in electronics and programming. My question is very simple and so I hope the solution.
I'm using Arduino Nano 3.0 with ATMega328 on it. I just want a LED to be on forever, with this simple code:
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
}
Very easy! But here is the problem: my board resets about every 30 seconds and so the LED goes off for a while and then switch on again. For my application, this is not acceptable !!!!
my board resets about every 30 seconds and so the LED goes off for a while
So you have to find out what is causing it.
The information supplied so far doesn't contain any thing that you are doing wrong. So you need to supply more information.
What arduino do you have?
Have you previously set up the watchdog timer?
Is there anything that can cause interference close by, like motors, florescent lights, thermostats?
Have you got a series resistor in line with your LED?
To AWOL: my application is actually more complicated, as it involves also a buzzer and an external LED, but the problem stays. I'm powering it form USB.
To Grumpy_Mike: I tried to disable watchdog as following, but the problem remains:
#include <avr/wdt.h>
int led = 13;
ISR (WDT_vect)
{
wdt_disable();
}
To Grumpy_Mike: I have an Arduino Nano V.3.0 with ATMega328 with no interferences around. I'm using LED already on the board for now, with a series resistor, but I have the same problem even with a buzzer connected to a digital Pin: the board simply resets all alone!
I read this in the product page of Arduino Nano on Arduino website: maybe it can be of some help, but I don't understand exactly what it means.
Automatic (Software) Reset Rather then requiring a physical press of the reset button before an upload, the Arduino Nano is designed in a way that allows it to be reset by software running on a connected computer. One of the hardware flow control lines (DTR) of the FT232RL is connected to the reset line of the ATmega168 or ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. This means that the bootloader can have a shorter timeout, as the lowering of DTR can be well-coordinated with the start of the upload. This setup has other implications. When the Nano is connected to either a computer running Mac OS X or Linux, it resets each time a connection is made to it from software (via USB). For the following half-second or so, the bootloader is running on the Nano. While it is programmed to ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first few bytes of data sent to the board after a connection is opened. If a sketch running on the board receives one-time configuration or other data when it first starts, make sure that the software with which it communicates waits a second after opening the connection and before sending this data.[/i]