Program code for servo motors

Hello I have a problem with code and servo motors im using 2 servo motors with gymbal and the starting angle is bad, I want to make that when i turn on system they will stay on different angle, with the code i made that they will turn to desired position but after that servos are getting back i think to 0 position, I didnt want for them to go back just to stay at desired angle when i start system. Btw sorry for bad english

can't really help without seeing the code

1 Like

Start with the exam[ple code for the Servo library. Slowly build from there to get to what you want.

1 Like

Assuming you are using Servo.h library, it is essential to write the first position for each servo BEFORE attaching it to a pin. That way, the servo timer interrupt routine gets the right pulse width from the start.

That is because when Arduino starts, it controls the servo motor to a hard-coded position.

You need to store current position in the flash memory. Each time Arduino starts, it need to read the position from the flash memory and control servo motor to that position.

Make use of the eeprom to store the desired positions and at start up of your program, read the eeprom first to retrieve the positions of your previous choosing and set your motors accordingly.