Pages: [1]   Go Down
Author Topic: Problem with led (PIN 13) Arduino mega 2560  (Read 482 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

Hello guys, i am having a problem with the PIN 13, the led that most of arduinos have, i made a code that by pushing a button it will turn on or turn off a led, for the led i used the DIGITAL PIN 22 and for the button the DIGITAL PIN 23. the code works fine but after a while the led (PIN 22) turns off and the led (PIN 13) turns on by 2 seconds and turn off that situation happens time after time. I dont know why happen that...

This is the code that i'm using:

int led=22 , pulsador=23 , valor_pulsador, led_2=13;
void setup(){ 
pinMode(led,OUTPUT); 
pinMode(pulsador,INPUT);
pinMode(led_2,OUTPUT);
}
void loop(){
digitalWrite(led_2,LOW);
valor_pulsador=digitalRead(pulsador); 
if(valor_pulsador==HIGH){
digitalWrite(led,HIGH);
}
else

digitalWrite(led,LOW); 

}

By the way that problem only happens when i use as a voltage source the arduino's USB cable, when i use a as voltage source a battery it doesn't happen.
« Last Edit: December 10, 2013, 11:47:35 am by cr93 » Logged

Offline Offline
Faraday Member
**
Karma: 68
Posts: 2794
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change:
pinMode(pulsador,INPUT);
to
pinMode(pulsador,INPUT_PULLUP);

See:
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
http://www.gammon.com.au/forum/?id=11955

Look up debounce also.
Logged

The way you have it in your schematic isn't the same as how you have it wired up! That goes for me too.

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

I did what you said but it didn't work, the problem isn't the button because i tried with the same code that i posted at the beginning and the LED (PIN 13) keeps turning on and then turning off each 30 seconds, i dont know why do that if i putted in the code digitalWrite(led_2,LOW); i made another code, that keep a led on, just that, but after 30 seconds the led of PIN 13 blink 4 times and then return to keep the led(PIN 53) on its like an interruption, i repeat this only happens when i use as voltage sourcce arduino's USB cable, but when i use my cellphone loader, it doesn't happen. Here is the code:

int led = 53 , led_2 = 13;
void setup(){
pinMode(led,OUTPUT);
pinMode(led_2,OUTPUT); 
}
void loop(){ 
digitalWrite(led,HIGH);
digitalWrite(led_2,LOW);   
}

I think it might be the arduino's USB cable the problem or the Arduino's itself but i'm not sure...
Logged

Pages: [1]   Go Up
Jump to: