Arduino Problem (Response Delay)


Hi guys I don’t know if you encounter this problem with arduino, but I want to share this problem and the things I’ve done to solve this it.

Problem:


I upload one of the example program(02.Digital / Button) to “arduino UNO”. Base on the program when  port 2 receives 5v port 13 must release 5v and when port 2 receives 0v, port 13 must release 0v. When I try to put 5v to port 2, port 13 releases 5v but when I remove the 5v supply to port 2, port 13 is still “ON” and it turns “OFF” after a few seconds. The question here is “ the program doesn’t contain any timer to delay port 13 to turn “OFF”, then  why port 13 is delayed?”, I also try to change the ports on the program, but the response of the program is still the same.

The program below is one of the example program of arduino, and base on this program if port 2 is “ON” port 13 must turn “ON”, and if Port 2 is “OFF” port 13 must turn “OFF”.





The Picture below shows the circuit diagram that I created for the program above. When I press the button at port 2, LED will turn “ON” and when I release the button at Port 2 LED must turn “OFF” but instead of turning “OFF” immediately it will turn “OFF” after a few seconds.



Solution:


I try to research on the forums but I didn’t find any answer, my theory about this circuit is “there might be some voltage on port 2 that remains after releasing the button”, it sounds crazy because there is no component connected in port 2 that can store voltage like capacitor, but I still try my theory, I put a resistor and LED in parallel with port 2 (see the picture bellow), the purpose of these resistor and LED is to discharge the excess voltage on port 2 after releasing the button. I never expect it but I works, there is no delay on response anymore.


I hope my article is helpful thank you.

Note: the picture of arduino program above is not mine, it is one of the example program of arduino software.

6 comments:

  1. thanks,its very useful to upgrade my knowledge further

    ReplyDelete
    Replies
    1. Welcome bro, I am glad that my article is useful to you

      Delete
  2. Hi Andrew,
    shouldn't you have a pullup(~10k) on port 2 pin? I have never encountered what you are experiencing and I have been using Uno and variants for many years. I don't know if the Atmel 328 has soft pullups but maybe that would work too.

    ReplyDelete
    Replies
    1. Haven't try to put 10k pull up resistor, I just share this article because even I can't explain what happened

      Delete
  3. You need to put a pullup on inputs. You are just connecting 5 volts directly to the input and wondering why it does not respond correctly.

    ReplyDelete
  4. Each of the 14 digital pins on the Uno can be used as an input or output, using pinMode(),digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive 20 mA as recommended operating condition and has an internal pull-up resistor (disconnected by default) of 20-50k ohm.

    ReplyDelete