Unable to load code and reset not functionning.

Hello everyone. I am new to arduino and I need some help with my arduino Mega 2560. Hope someone can help me.

Ever since I uploaded the sketch below, my arduino card doesn’t work anymore. I try the reset button multiple times but the led beside pin13 does not flash either. And I can’t upload any sketch into the card anymore. The uploading process just stuck half way. I have tried uploading an empty sketch with only void setup(){ Serial.begin();} + void loop() using the option ‘uploading using programmer’ and yes I managed to upload the empty sketch ( I considered it uploaded seeing that the upload process didn’t get stuck halfway) but my card is still not working : the reset button doesn’t work and i can’t seem to upload any sketch without the help of ‘uploading using programmer’. And at the end of the upload I got a message : avrdude: usbdev_open(): did not find any USB device “usb”

I have tried uploading a simple serial.print code using the programmer but when I tested the card using the serial monitor there wasn’t any reply from the serial monitor.

I have verified the correct port and I have installed the necessary driver during all these process. I believe it is this code wdt_enable(WDTO_15MS); that cause all this. I felt helpless and can’t figure what should I do to solve this problem.

Is there anyone willing to help? Please…

#include “Arduino.h”
#include <avr/wdt.h>
int LedPIN=8;
int incoming = 0;
void setup()
{
Serial.begin(9600);
analogWrite(LedPIN,0);
wdt_enable(WDTO_15MS);
}

void loop()
{
if(Serial.available()>0)
{
char ch = Serial.read();
if(ch >= ‘0’ && ch <= ‘9’)
{
analogWrite(LedPIN,125);
Serial.write(ch);
}
else
{
analogWrite(LedPIN,0);
Serial.write(ch);
}
}
}

I think your bootloader is being interrupted by the WDT. Try this:

Hold down the Reset button. Click the Upload button for a benign sketch. When you see the RX light blink, release the Reset button.

Hopefully this will allow you to initiate an upload before your old sketch can re-enable the WDT.

The current UNO bootloader is supposed to disable the WDT on reset so you might want to update your bootloader some day. You can get a nice USBasp programmer from China/Hong Kong for $4.

Programmer ($2.84): http://www.ebay.com/itm/1-Pcs-USB-USBasp-USBISP-3-3V-5V-51-AVR-Downloader-Programmer-USB-ATMEGA8-HE-/400583840341

Adapter from the 10-pin cable to the 6-pin Arduino connector ($1.16): http://www.ebay.com/itm/10Pin-Convert-To-Standard-6-Pin-Adapter-Board-For-ATMEL-STK500-AVRISP-USBASP-/161080527823

If you want one with a nice case you can get the whole set for $6.66 (The Price of the Beast!): http://www.ebay.com/itm/5V-USBASP-ISP-AVR-Programmer-Case-10-Pin-Convert-to-Standard-6-Pin-Adapter-Board-/200956456654

I think the bootloader uploader on my link below uploads the new 2560 bootloader that fixes the WDT issue:

http://www.gammon.com.au/forum/?id=11635