Ok, so I have been trying to make a simple servo program that is activated by pressing a button and then turns the servo for 6 seconds. After that, it goes to the original position. Now that's how I want it to work, yet when I run my program the servo stops when I press the button until I release but, and when I release it turns in a strange cycle. this is the code: #include <Servo.h> //Biblioteka Serva
Servo serwomechanizm;
int pozycja = 0;
int zmiana = 6;
What do you mean by strange? While your first code would do as you said this one while the button is down will move the servo to one place and hold it there for six seconds and then return it to zero. However it probably doesn’t have time to get all the way to zero again before you set it off going again. This is because you only give the servo half a second to get back to zero which is not long enough.
the problem is that it does not work like that. It doesnt hold it there for 6 seconds. And it should also require me to press this button, before each cycle starts again. It does not. For some reason the servo goes back and forth, then it takes a short break and goes again, without caring about the button.
I know for sure that the connections between the servo and the arduino are ok as I put them as they should be using a tutorial, and it worked, but the button was my doing, and I am new as I said, so I don't know if it is correct.
Yes your button is not wired up correctly.
It should bridge the gap in the bread board so each pin is on a different strip, and then wire across opposite corners to make the connection.
You should not even try to power a servo from the Arduino 5V pin, as you can damage the Arduino, and the servo probably won't work correctly. Ignore tutorials that say otherwise.
Use a 4xAA battery pack to power the servo, and connect the grounds.
No because I am on an iPad and can’t generate pictures. So can you understand this?
Remove your button and rotate it 90 degrees and then plug it back in. You will also have to move one of the wires so it is connected to the button’s terminal.
What jremington said. I had a project where I tried powering the Arduino and the servos from the same 4xAA battery pack and the voltage drop when the servo moved caused the Arduino to reset. You may have already damaged your board.