controlling a servo with one button,

I am trying to control a servo, with one button and a pro mini.

I need to press the button and it sends the servo from its preset position of 45 degrees, quite slowly to 135 degrees then stops until I press the button again where it sends the servo quite slowly back to 45 degrees again.
I have been pulling my hair out and though i have manage to upload a program after verifying it, It doesn’t do what I need it to do.

All this to motorise a level crossing on a model train set.

Can someone help befor I tear all my hair out please.

Servofinaltest.ino (607 Bytes)

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

How is your switch wired?

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

So what does your program do? Certainly sending the servo from 0 - 180 and back is unlikely to send it from 45-135 and back but what else is wrong?

I'd guess that you need to be testing when the button BECOMES pressed rather than just when it IS pressed. Have a look at the StateChangeDetection example in the IDE.

Steve

Thanks

I have been using an arduino for a while in various projects which include auto drive toy car, weather and led control which eventually ran to a one off set of indicators for a 1967 mini 1000.

My problem is I am on some very strong tablets and concentration is hard. My age & doesnt help as well.

What I am doing now is to find a way to use a mini pro, a micro servo and a push button so that a quick press of the button will, depending on their present position, open or close a set of level crossin gates for a model railway.

I am close, very close and a re write has helped but as yet apart from burning out one servo the button has not worked as I want it.

I thank you for your advice and will certainly check it out.

bfn
Peter Y

When you want help you should respond to instructions/questions from those trying to help you.

How is your switch wired?

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

Also for small sketches, it is best you post it as:
Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]