Go Down

Topic: Problem with led (PIN 13) Arduino mega 2560 (Read 664 times) previous topic - next topic

cr93

Dec 10, 2013, 05:22 pm Last Edit: Dec 10, 2013, 05:47 pm by cr93 Reason: 1
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.

LarryD

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.
The way you have it in your schematic isn't the same as how you have it wired up!

cr93

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...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy