Twitching servo because of coding, Arduino Uno

Hello, im very new to this so im sorry if my question lacks information or isnt properly explained.

I have recently changed the coding for my project that includes a servo. After having done this tho, the servo now twitches. it has enough Voltage and Amperage wich i thought would have been the problem but its not.
I gues the coding i added for the display to read out the temp sensor might conflict with the library of the servo, but unfortunatly i do no understand enough to know this.
If any of u who do understand this could look at my code to see if this is the case i would appreciate it very much.

thanks!

#include <Servo.h>
#include <IRremote.h>
Servo servo_5;
const int irReceiverPin = 3;  // Connect the IR receiver sensor to pin 2
       // Connect an LED to pin 13 or use a relay for controlling a device


IRrecv irReceiver(irReceiverPin);
decode_results results;

#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 6
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 6 
Adafruit_SSD1306 display(OLED_RESET);
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
irReceiver.enableIRIn();  // Start the IR receiver
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
servo_5.attach(5, 500, 2500);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
servo_5.write(60);


  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  sensors.begin();      	// initialize the DS18B20 temperature sensor:
}


void loop() {
  if (irReceiver.decode(&results)) {
    Serial.println(results.value, HEX);
    
    // Check for the specific IR codes
    if (results.value == 0x9716BE3F) { // Change this value with the actual IR code
      activateTable();
    }
    else if (results.value == 0x3D9AE3F7) {
      activateSecondFeature();// Add code to handle the second IR command
      // For example: activateSecondFeature();
    }
    else if (results.value == 0x6182021B) {
      activateThirdFeature();// Add code to handle the third IR command
      // For example: activateThirdFeature();
    }
    else if (results.value == 0x8C22657B) {
      activateFourthFeature();// Add code to handle the third IR command
      // For example: activateThirdFeature();
    }
    else if (results.value == 0x488F3CBB) {
      activateFithFeature();// Add code to handle the third IR command
      // For example: activateThirdFeature();
    }
    else if (results.value == 0x449E79F) {
      activateSixthFeature();// Add code to handle the third IR command
      // For example: activateThirdFeature();
    }
    // Add more conditions for additional IR commands as needed

    irReceiver.resume();  // Receive the next value
  }
{ 
display.clearDisplay();  
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures(); 
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0));	// get and print the temperature in degree Celsius
delay(1000);
float T = sensors.getTempCByIndex(0);  // let T be temperature in degC from sensor
					// floating-point number, with a decimal point  
display.setTextSize(3);display.setTextColor(WHITE); display.setCursor(0,0);

display.print(T);

display.cp437(true);    	// code page 437
display.write(167);     	// character 167 is degree
display.println("C");
display.display();		// for the changes to make effect
}
}

void activateTable() {
digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(6000); // Wait for 5000 millisecond(s)
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(110);
    delay(1000); // Wait for 1000 millisecond(s)
    digitalWrite(7, HIGH);
    delay(22000); // Wait for 3000 millisecond(s)
    digitalWrite(7, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(60);
    delay(1000);
    digitalWrite(2, LOW);
    digitalWrite(4, HIGH);
    delay(6000);
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
}
// Add functions for handling other features as needed
// For example:

void activateSecondFeature() {
digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(6000); // Wait for 5000 millisecond(s)
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(110);
    delay(1000);// Wait for 1000 millisecond(s)
    digitalWrite(8, HIGH);
    delay(22000); // Wait for 3000 millisecond(s)
    digitalWrite(8, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(60);
    delay(1000); 
    digitalWrite(2, LOW);
    digitalWrite(4, HIGH);
    delay(6000);
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
}

void activateThirdFeature() {
digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(6000); // Wait for 5000 millisecond(s)
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(110);
    delay(1000);// Wait for 1000 millisecond(s)
    digitalWrite(12, HIGH);
    delay(62000); // Wait for 3000 millisecond(s)
    digitalWrite(12, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(60);
    delay(1000); 
    digitalWrite(2, LOW);
    digitalWrite(4, HIGH);
    delay(6000);
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
}
void activateFourthFeature() {
digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(6000); // Wait for 5000 millisecond(s)
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(110);
    delay(1000);// Wait for 1000 millisecond(s)
    digitalWrite(13, HIGH);
    delay(62000); // Wait for 3000 millisecond(s)
    digitalWrite(13, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(60);
    delay(1000); 
    digitalWrite(2, LOW);
    digitalWrite(4, HIGH);
    delay(6000);
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
}
void activateFithFeature() {
digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(6000); // Wait for 5000 millisecond(s)
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(110);
    delay(1000);// Wait for 1000 millisecond(s)
    digitalWrite(12, HIGH);
    digitalWrite(8, HIGH);
    delay(20000); // Wait for 3000 millisecond(s)
    digitalWrite(8, LOW);
    delay(40000);
    digitalWrite(12, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(60);
    delay(1000); 
    digitalWrite(2, LOW);
    digitalWrite(4, HIGH);
    delay(6000);
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
}
void activateSixthFeature() {
digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(6000); // Wait for 5000 millisecond(s)
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(110);
    delay(1000);// Wait for 1000 millisecond(s)
    digitalWrite(12, HIGH);
    digitalWrite(7, HIGH);
    delay(20000); // Wait for 3000 millisecond(s)
    digitalWrite(7, LOW);
    delay(40000);
    digitalWrite(12, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
    servo_5.write(60);
    delay(1000); 
    digitalWrite(2, LOW);
    digitalWrite(4, HIGH);
    delay(6000);
    digitalWrite(2, LOW);
    digitalWrite(4, LOW);
}

Do you have the ground of the Arduino connected to the ground of servo_5 and the (two? arduino and servo) power supply?

yes, i have all the grounds connected, i have a 12V 6A powersupply that feeds the arduino and other electronics used in the project. And a 5V 3A step-down module that power the servo.

Is the servo light-duty, like the SG90? The sketch has each servo movement surrounded with delay() times, so I think the issue is hardware.

the servo is the mg996r, and it only needs to move the weight of itsself and a little bit of plastic.

Your servo uses 6vdc at 2.5A.

Is the servo connected to a solderless breadboard?

it is connected directly to the 12 to 5v stepdown module, the ground IS connected to the breadboard. is uses between 3-6vdc i thought? does the extra V matter? i worked fine before

Are you sure of that specification?
The MG996R draws over 2.5 Amperes every time is starts moving.

Breadboards are for temporary experiments with low power logic circuits and cannot handle currents anywhere near that high. The tracks will burn. Solder the servo power connections, or use approved connectors.

yes, because i too thought the the problem was in the Amps so i bought a better stepdown. Can grounding also not be put on a Breadboard?

Not if significant currents flow in the ground track. That would include the servo power ground.

So if i connect the servo grounding straight to the 12V power supply grounding it wil work?

Please post a hand drawn schematic diagram of any circuit you wish to discuss.

I recommend testing the servo with a very simple "servo sweep" code, to exclude possible problems with memory, interrupt handling, etc..

i have just checked and the problem is not hardware, i think it has to do with the clock thats used to refresh the oled.

I don't know what you mean by "clock thats used to refresh the oled", but yes, coding can interfere with servo function.

About 95% of the servo problems reported on this forum are due to inadequate servo power supplies, so that is always the first thing to suspect.

ever since i added the coding for the screen this problem started to happen. Is there a way that one of the librarys i added goes in conflict with the servo?

There are many possible problems with libraries.

For example, if you are using the Uno R3 or similar, the screen can be a problem because the screen buffer consumes half of the dynamic RAM. The OneWire sensor library can be a problem, because it can disable interrupts. The IRRemote library might conflict with the Servo library over timer usage.

To isolate the problem, go back to the point where you had everything working, and add one new feature at a time. Stop when you find the offending addition, and fix the problem.

Thank you for the help!

This is usually "-1"

And you have two devices defined on one pin.

I am certain there are more of these in the wiring/sketch.

i thought the oled reset was the refresh rate, ill make sure to look at it, but i dont see how that would make the servo twitch?

It is a an indicator that your sketch and your connections are not matching, and probably some more that do make the servo twitch. Prove me wrong.