Pages: [1] 2   Go Down
Author Topic: Mega 2560 - Led 13 often on without code  (Read 1671 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Could you tell me why this simple code put onboard Led 13 always on ?

/*
 *
 * Controle d'un relai après un certain temps
 *
 */
 
int pinRelai = 31; // commande du relai (via transistor P2N2222AG)


void setup() {
  pinMode( pinRelai, OUTPUT );
}

void loop() {
  delay(5000);
  digitalWrite( pinRelai, HIGH );
  delay(5000);
  digitalWrite( pinRelai, LOW );
 
}
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What size resistor do you have connecting the digital output pin to the base of the transistor?

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

10k ohm
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm stumped.  An interesting mystery.  The relay is happy, right?

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes relay does function.

With some code, Led is on, with other it's off

Strange

Thierry
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
With some code, Led is on, with other it's off

Strange
Not really. Whether the pin is INPUT or OUTPUT matters. Whether the pin is HIGH or LOW matters. Without seeing the two different codes, all we can do is assume that it is perfectly normal.
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3863
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a Uno and find that with sketches which don't even refer to that pin at all, the built-in led on 13 is on more often than not.

I stick these lines in at the top of each sketch, because having that led on when I don't want it on, annoys the cr@p out of me!

Code:
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
Logged

The Elders of the Internet know who I am.....

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like a bootloader bug.  Worth reporting if it's an official Arduino board.

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

--> PaulS

You have an example of code in my post.  I juste do copy-paste as a new program, run it and Led will light
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

--> JimboZA

Nice to meet another one with same problem  :-)

Thierry
Logged

Germany
Offline Offline
Newbie
*
Karma: 1
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all,

i just received my arduino mega 2560 r3 and led on pin 13 is always on, even with "bare minimum" sketch.
when i use the blink example it blinks correctly.

have you found any solution to this?
is that the only problem you have or might this be just the tip of the iceberg and the whole board is flawed?

cheers,
stefan
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I drug out a selection of Arduinos - a Duemilanove, a Micro, a Mega, a Leonardo, a Due, and an Esplora. I loaded the same sketch onto each one. On the Due, the LED on pin 13 stayed on. On all the others, the LED on pin 13 was off while the sketch was running. Changing the pin from 31 to 13, for each board, caused the onboard LED to flash, as expected.

I guess, then, that JimboZA's suggestion is what you need to do, if having the onboard LED on bothers you.
Logged

Germany
Offline Offline
Newbie
*
Karma: 1
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi Paul,

whoaa, thanks for your investigation!
so pin13 is off on your MEGA but on on the DUE... seems random to me smiley-wink

a resistor from pin 13 to ground "solves" the problem, i just hope that there aren't any underlying defects that cause this behavior.


thanks again,
stefan
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
a resistor from pin 13 to ground "solves" the problem
That is what JimboZA's code does, in effect, but all in software.
Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 723
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could a floating pin somehow drive the LED?
Logged

Pages: [1] 2   Go Up
Jump to: