Help coding a Button to control a servo motor

Hi, im trying to code a button to control a servo motor but I'm running into the issue that I'm needing to hold down the button to stop the servo motor from rotating rather than having it so if I press it once, it registers that the button state is HIGH and stops the motor without having to hold it down.

Have a look at the state change detection tutorial.. It shows how to detect the state transitions as opposed to the state levels.

anjaligarg1023:
rather than having it so if I press it once, it registers that the button state is HIGH

While you're doing this:

groundFungus:
Have a look at the state change detection tutorial..

... change things to the better practice of press meaning low. Wire the button to ground from the pin, pinMode to enable internal pullups, and change the code to look for a low.

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: