Momentary switch continues to returns high for 3-4 seconds after release

I'm using an Arduino Uno and breadboard.

Simple single LED circuit with current given from pin 9, following a HIGH return to pin 2.

Pin 2 is a simple circuit with 10kohm resistor and a momentary switch.

Everything works but LED stays on for longer than the momentary press.

I have checked the hardware is not faulty.

When switch pressed and released pin 2 continues to return a high value for several seconds (I have confirmed this by printing to the serial) afterwards?

Is this just residual current? Is there a solution so momentary switch acts like a momentary switch not a delay switch?

Not enough information for us to help you.

benpaddlejones:
Pin 2 is a simple circuit with 10kohm resistor and a momentary switch.

We need a better description of your circuit.

benpaddlejones:
I have checked the hardware is not faulty.

How did you check it?

benpaddlejones:
(I have confirmed this by printing to the serial) afterwards?

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it’s OK to add it as an attachment.

benpaddlejones:
Is this just residual current?

It’s either a problem with your circuit or a problem with your code.

benpaddlejones:
Is there a solution so momentary switch acts like a momentary switch not a delay switch?

Yes:

benpaddlejones:
I'm using an Arduino Uno and breadboard.

Simple single LED circuit with current given from pin 9, following a HIGH return to pin 2.

Pin 2 is a simple circuit with 10kohm resistor and a momentary switch.

Everything works but LED stays on for longer than the momentary press.

I have checked the hardware is not faulty.

When switch pressed and released pin 2 continues to return a high value for several seconds (I have confirmed this by printing to the serial) afterwards?

Is this just residual current? Is there a solution so momentary switch acts like a momentary switch not a delay switch?

You have miswired the pullup or pulldown resistor on the button somehow, such that the pin is floating.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

MarkT:
You have miswired the pullup or pulldown resistor on the button somehow, such that the pin is floating.

Thanks, you are 100% correct my circuit was wrong, any chance you could direct me to an explanation of the electrical theory? I assumed a simple circuit like in the attached would do the same but I obviously don’t understand the pull up/down circuit.

What I don’t get is why is the resistor between the switch and ground? When I moved the resistor between the switch and the pin I crashed the controller which seams the logic place to put it?

edit: Now I understand: Pull up/ Pull down resistor - explained ( with calculation ) - YouTube

This circuit worked perfectly with my code: https://www.arduino.cc/en/Tutorial/Button