Servo motors not working

Title. I have tried with multiple servos of mg996r variety and ms18 so I dont think its the servo being broken. I also tested the arduino and its running blink fine.

Heres my code and connections. I've also tested using an outside powersource for more power.

Similar setups have worked in the past.

I've also tried with different computers to see if they work.

I also tried redownloading arduino, resetting the computer, and resetting the arduino.

I have also checked the port.

Thank you for any advice or help.


Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Which pin of the Mega is the servo signal wire connected to ?

pin40 is placed little to left

1 Like

I don't know your shield, but for your servo you need more than 2A power source.

You should not power a servo from the 5V output of the Mega. You may damage the Mega and/or the computer connected to the USB port.
Even the small servos can draw more current than a standard USB port can provide.
Use an external 5V source for the servo.
When using an external supply, make sure that the supply ground is connected to the Mega GND

Please read @UKHeliBob's post about posting code.

Use a separate power supply for the servo, capable of providing at least 2.5 Amperes per MG996R servo, and don't forget to connect the grounds. The Arduino 5V output cannot be used to power servos.

As @kolaha indicates, you have pin 40 in code and the signal wire plugged into pin 23.