Servo twitch when wire library is used

Hi All, been working for some time on a remote control tracked vehicle. It will have some level of automation so it has an MPU6050 installed and the code below is used to read the data I need from it. I recently purchased some Turnigy MG90 servos for a head to be added with yaw and pitch control and this is where my problems have started.

When I have the code below activated, bearing in mind right now it just looks for the data and puts it into a variable, the servo will twitch like mad. If I omit the code, it works just fine.

I will eventually use (and have tested it already) the variable from that function for rotating the vehicle to the same position the head is looking but for now, everything in this function is limited to the function itself.

Am I going completely mad? I'm sure someone is going to point me to some documentation regarding the servo.h include and the wire library include but I have searched and cant find it.

Been scratching my head for a while on this and I have no idea what is going on, any help would be greatly appreciated.

Thanks!

void readYaw()
{
  Wire.beginTransmission(MPU);
  Wire.write(0x43); // Gyro data first register address 0x43
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
  GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
  GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = GyroZ - 0.133;
  vehicleYaw =  vehicleYaw + GyroZ * elapsedTime;
}

Could the problem be in the code that you have not posted I wonder ?

For example, which libraries and pins are being used ?
How is the servo powered ?

1 Like

Hi, thanks for the reply. The servo has 5v of power from a buck convertor with a 1000uf capacitor to filter the voltage a little. It seems rock solid and just to be safe I also added a ferrite ring to the servo lead to try to eliminate any RF interference. There are other devices also powered from this output such as the Arduino itself which powers the HC-05 Bluetooth Module and the MPU6050 (I have a power diagram if needed?)

I have added the code in it's entirety below, I am very much a beginner at all of this so please go easy on me :wink:

Thanks again!!

// ===== MOTOR CONTROL PINS =====

// Right Hand Motor pins of W-3
int enA = 6; //Pins 9 and 10 cannot be used as PWM pins when using the servo library
int in1 = 8; //HIGH for backward motion
int in2 = 7; //HIGH for forward motion

// Left Hand Motor pins of W-3
int enB = 3;
int in3 = 5; //HIGH for backward motion
int in4 = 4; //HIGH for forward motion

// motor triggers
byte LeftMotor = 0;
byte RightMotor = 0;


// ===== MPU5060 Setup =====
#include <Wire.h>
const int MPU = 0x68; // MPU6050 I2C address
float GyroX, GyroY, GyroZ;
float vehicleYaw;

// ===== LOOP TIMERS =====

float elapsedTime, currentTime, previousTime, currentMicros;

// ===== Activity LED Timer stuff ====
unsigned long ActivityLEDInteval = 1500;
unsigned long blinkDuration = 400;
byte ActivityLEDState = HIGH;
unsigned long previousActivityLEDTime = 0;
int counter = 0;

// ===== PINOUT FOR UPPER HULL =====
// SERVOS Have been swapped temporarily
// pitch servo removed for testing
//const byte PitchServo = A2; //Blue = Yaw servo = A1
const byte YawServo = A1; //Orange = Pitch Servo = A2
//A3 //Red = spare
//A4 //Brown = spare
const byte Speaker = A0; //Speaker RED = A0
//Green = Gnd (to 5v board)
//Yellow = Vcc (to 5v board)

// ===== PINOUT FOR LOWER HULL =====

const byte PowerLED = 10; //Green Power LED = 13
const byte ActivityLED = 11; //Orange Activity LED = 12

// ===== SERVO LIMITS =====

const byte maxYaw = 180; // Yaw full left is 180
const byte minYaw = 10; // Yaw Servo full right is 10
// Yaw mid point is 95

const byte maxPitch = 115; // Pitch Servo full down is 115
const byte minPitch = 50; // Pitch Servo full up is 50
// Pitch Servo mid point is 80

// ===== Head Motion =====
float yawActual, servoYawActual, servoOffset, yawVehicleOffset;
float yawError = 0;
float yawTarget, yawVal;
float dt;

// ===== Bluetooth Data =====
char BluetoothData;
float A;
float B;

// ===== Industrial Light & Magic =====
byte connectionFound = 0;

// ===== HEAD MOTION =====
int headYawTarget;
byte headYaw = 4;

#include <Servo.h>

Servo Yaw;
//Servo Pitch;

void setup() {

  // Set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

  // Turn off motors - Initial state
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  // Pinmodes
  pinMode(PowerLED, OUTPUT);
  pinMode(ActivityLED, OUTPUT);
  pinMode(Speaker, OUTPUT);
  //pinMode(PitchServo, OUTPUT);
  pinMode(YawServo, OUTPUT);

  //wire library setup for mpu5060
  Serial.begin(9600);
  Wire.begin();                      // Initialize comunication
  Wire.beginTransmission(MPU);       // Start communication with MPU6050 // MPU=0x68
  Wire.write(0x6B);                  // Talk to the register 6B
  Wire.write(0x00);                  // Make reset - place a 0 into the 6B register
  Wire.endTransmission(true);        //end the transmission

  // Configure Gyro Sensitivity - Full Scale Range (default +/- 250deg/s)
  Wire.beginTransmission(MPU);
  Wire.write(0x1B);                   // Talk to the GYRO_CONFIG register (1B hex)
  Wire.write(0x10);                   // Set the register bits as 00010000 (1000deg/s full scale)
  Wire.endTransmission(true);

  setupComplete();
}

// =======================================================================
// =======================================================================
// =======================================================================

void setupComplete()
{
  // Reset servo positions and beep twice to indicate setup is complete
  Yaw.attach(YawServo);
  //Pitch.attach(PitchServo);
  //Pitch.write(80);
  Yaw.write(90);
  delay(500);
  //Pitch.detach();

  delay(450);
  digitalWrite(PowerLED, HIGH); // power led on to indicate power
  //tone(Speaker, 600, 500); // POST complete beep
}

// =======================================================================
// =======================================================================
// =======================================================================

void loop() {

  previousTime = currentTime;        // Previous time is stored before the actual time read
  currentTime = millis();            // Current time actual time read
  currentMicros = micros();
  elapsedTime = (currentTime - previousTime) / 250; // not sure why it's by 250 but it works???

  //get the input and sensor data first
  btInput();
  readYaw();

  //move motors and servos
  analogControlRight();
  analogControlLeft();

  //Effects
  ActivityLEDChange();

}

// =======================================================================
// =======================================================================
// =======================================================================

void btInput()
{
  if (Serial.available())
  {
    BluetoothData = Serial.read(); //Get next character from bluetooth

    //Test for a connection
    if (connectionFound == 0) //nake sure this only happens once
    {
      connectionFound = 1;
      //tone(Speaker, 800, 100); // Connection Found
    }

    if (BluetoothData == 'A')
    {
      A = Serial.parseInt();
      RightMotor = 1;
    }
    if (BluetoothData == 'B')
    {
      B = Serial.parseInt();
      LeftMotor = 1;
    }

    if (BluetoothData == 'Y')
    {
      headYawTarget = Serial.parseInt();
      int yawPrevious = Yaw.read();
      Yaw.write((yawPrevious * 0.8) + (headYawTarget * 0.2));
    }

  }
}


// =======================================================================
// =======================================================================
// =======================================================================


void analogControlRight()
{
  //measure the input from the controller and adjust the speed of the
  //right wheel accordingly
  if (RightMotor == 1)
  {
    if (A < 120 && A > -120) // dead zone stop all
    {
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      A = 0;
    }
    else
    {
      if (A > 0) // forward so set motor direction
      {
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
      }
      else // backward instead
      {
        A = -A;
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
      }
    }
    analogWrite(enA, A);
    RightMotor = 0;
  }
}



// =======================================================================
// =======================================================================
// =======================================================================

void analogControlLeft()
{
  //measure the input from the controller and adjust the speed of the
  //left wheel accordingly
  if (LeftMotor == 1)
  {
    if (B < 120 && B > -120) // dead zone - stop all
    {
      digitalWrite(in4, LOW);
      digitalWrite(in3, LOW);
      B = 0;
    }
    else
    {
      if (B > 0)
      {
        digitalWrite(in4, LOW);
        digitalWrite(in3, HIGH);
      }
      else
      {

        B = -B;
        digitalWrite(in4, HIGH);
        digitalWrite(in3, LOW);
      }

    }
    analogWrite(enB, B);
    LeftMotor = 0; // reset the loop for the next value
  }
}

// =======================================================================
// =======================================================================
// =======================================================================

void headYawMotion()
{
  if (headYaw == 0) // turned on
  {
    dt += currentTime - previousTime;
    if (dt >= 100) // wait for each servo update
    {
      Yaw.write(headYawTarget);
      dt = 0;
    }
  }
}

// =======================================================================
// =======================================================================
// =======================================================================

void readYaw()
{
  Wire.beginTransmission(MPU);
  Wire.write(0x43); // Gyro data first register address 0x43
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
  GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
  GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = GyroZ - 0.133;
  vehicleYaw =  vehicleYaw + GyroZ * elapsedTime;
}

// =======================================================================
// =======================================================================
// =======================================================================

void ActivityLEDChange() {
  //Blink without delay - Thanks to Robin2 from the arduino forums
  if (ActivityLEDState == LOW) {
    if (currentTime - previousActivityLEDTime >= ActivityLEDInteval) {
      ActivityLEDState = HIGH;
      previousActivityLEDTime += ActivityLEDInteval;
    }
  }
  else {
    if (currentTime - previousActivityLEDTime >= blinkDuration) {
      ActivityLEDState = LOW;
      previousActivityLEDTime += blinkDuration;
    }
  }
  // Change the LED Time and inteval after a number of
  // LED changes to make it blink more randomly
  if (digitalRead(ActivityLED) != ActivityLEDState)
  {
    counter++;
    if (counter == 10)
    {
      if (ActivityLEDInteval == 1500)
      {
        ActivityLEDInteval = 100;
        blinkDuration = 100;
        counter = 3;
      }
      else
      {
        ActivityLEDInteval = 1500;
        blinkDuration = 400;
        counter = 0;
      }
    }
  }
  digitalWrite(ActivityLED, ActivityLEDState);
}

// =======================================================================
// =======================================================================
// =======================================================================

Hi,
You could have a conflict with timers.
I'm not sure what timer the Wire and Servo each use.
There is a library that uses timer2 that may fix your problem.

Tom... :grinning: :+1: :coffee: :australia:

Thanks Tom, I will have a good look at that as an option and see if I can get it to work for me! Appreciate your help!

Ok so I have implemented the library and I found something strange. First, the numbers used are obviously not in degrees, I assume it must be frequency or something. I have managed to get the servo to turn to a certain position to test it and that works until I go past a certain point, I think it must be a limit of the servo but at a certain point close to 180 degrees, the servo will move to the end initially then back near the middle and the twitches. If I set the limits correctly it seems to move to the position and then stays there, perfect! I just need to work out how to move it more than once now, for some reason when I use the code separately, it will move back and forth but in my code it moves once and then stops. I'm sure I will figure it out with more time, only so much you can do on a lunch break ha ha! Thanks for the assistance anyway, will be back with some code if I can't get it to work :slight_smile:

The ServoTimer2 library uses microseconds as opposed to degrees. The values varies from 1000 at one end of servo travel through 1500 in the centre to 2000 at the other end of travel

Hi,
This may help, it uses the timing rather than the degrees for the turn control.

/* In ServoTimer2 library we must write the Pulsewidth of the servo and the servo moves to that position using that. 
Most commonly 1500 means 90 degree. The maximum pulsewidth is 2250 and minimum is 750. 
Which would mean 750 is for 0 degree and 2250 is for 180 degree. But let me tell you, this varies from servo to servo. 
Just send in your values and see what happens. Don't worry this wont destroy or harm your servo motor a bit.
Now I'll make the same code for ServoTimer 2 and thus you'll get what actually the differences are.*/

#include"ServoTimer2.h"
ServoTimer2 servo1;
void setup() 
{
servo1.attach(6);   
}
void loop() 
{                 // put your main code here, to run repeatedly:
servo1.write(750);  //min pulse width for 0 degree
delay(1000);
servo1.write(1500);  //pulse width for 90 degree
delay(1000);
servo1.write(2250);  //max pulse width for around 180 degree
delay(1000);
}

The comments explain the 750, 1500, and 2250 values.

Tom... :grinning: :+1: :coffee: :australia:

Awesome, that does explain it well! Thanks for the additional info. I did some playing with the code and found similar end points. Going to go through all of my code again to get control with the remote and see how that goes!

Ok so after some more testing this morning, I found that the 'Tone' function, seemingly doesn't like the new library for controlling the servo. Yesterday I tested it and it seemed to stop twitching and I was satisfied that after some work, this would be my solution.

This morning I tried to get the Bluetooth connection working and controlling the head movement and I found that what is actually happening, is that as soon as a tone is played, it seems to crash the entire servo library somehow and the is no longer any function on the servo at all. The twitching seemed to stop in this case because the library had crashed (or something).

Anyway, when I removed the Tone code from the start of the code, sure enough I can now control the head with the Bluetooth connection but the twitching is behaving as it was before. So, I have gone through the code again and I can't figure out what is causing the problem. I have attached the revised code in case someone has the time to look through it and see what I can't.

Thanks again guys, appreciate the time!

#include <ServoTimer2.h>
#include <Wire.h>

// ===== MOTOR CONTROL PINS =====

// Right Hand Motor pins of W-3
int enA = 6; //Pins 9 and 10 cannot be used as PWM pins when using the servo library
int in1 = 8; //HIGH for backward motion
int in2 = 7; //HIGH for forward motion

// Left Hand Motor pins of W-3
int enB = 3;
int in3 = 5; //HIGH for backward motion
int in4 = 4; //HIGH for forward motion

// motor triggers
byte LeftMotor = 0;
byte RightMotor = 0;


// ===== MPU5060 Setup =====

const int MPU = 0x68; // MPU6050 I2C address
float GyroX, GyroY, GyroZ;
float vehicleYaw;

// ===== LOOP TIMERS =====

float elapsedTime, currentTime, previousTime, currentMicros, dt;

// ===== Activity LED Timer stuff ====
unsigned long ActivityLEDInteval = 1500;
unsigned long blinkDuration = 400;
byte ActivityLEDState = HIGH;
unsigned long previousActivityLEDTime = 0;
int counter = 0;

// ===== PINOUT FOR UPPER HULL =====
// pitch servo removed for testing
//const byte PitchServo = A2; //Blue = Yaw servo = A1
const byte YawServo = A1; //Orange = Pitch Servo = A2
//A3 //Red = spare
//A4 //Brown = spare
const byte Speaker = A0; //Speaker RED = A0
//Green = Gnd (to 5v board)
//Yellow = Vcc (to 5v board)

// ===== PINOUT FOR LOWER HULL =====

const byte PowerLED = 10; //Green Power LED = 13
const byte ActivityLED = 11; //Orange Activity LED = 12

// ===== SERVO LIMITS =====

const byte maxYaw = 2100; // Yaw full left is 180
const byte minYaw = 750; // Yaw Servo full right is 10
// Yaw mid point is 1425

//Pitch servo end point will have to be look at again
//const byte maxPitch = 115; // Pitch Servo full down is 115
//const byte minPitch = 50; // Pitch Servo full up is 50
// Pitch Servo mid point is 80

// ===== Bluetooth Data =====
char BluetoothData;
float A;
float B;
byte connectionFound = 0;

// ===== HEAD MOTION =====
int headYawTarget;
byte headYaw = 4;
int yawPrevious;


ServoTimer2 Yaw;
//ServoTimer2 Pitch;

void setup() {

  // Set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

  // Turn off motors - Initial state
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  // Pinmodes
  pinMode(PowerLED, OUTPUT);
  pinMode(ActivityLED, OUTPUT);
  pinMode(Speaker, OUTPUT);
  //pinMode(PitchServo, OUTPUT);
  pinMode(YawServo, OUTPUT);

  //wire library setup for mpu5060
  Serial.begin(9600);
  Wire.begin();                      // Initialize comunication
  Wire.beginTransmission(MPU);       // Start communication with MPU6050 // MPU=0x68
  Wire.write(0x6B);                  // Talk to the register 6B
  Wire.write(0x00);                  // Make reset - place a 0 into the 6B register
  Wire.endTransmission(true);        //end the transmission

  // Configure Gyro Sensitivity - Full Scale Range (default +/- 250deg/s)
  Wire.beginTransmission(MPU);
  Wire.write(0x1B);                   // Talk to the GYRO_CONFIG register (1B hex)
  Wire.write(0x10);                   // Set the register bits as 00010000 (1000deg/s full scale)
  Wire.endTransmission(true);

  setupComplete();
}

// =======================================================================
// =======================================================================
// =======================================================================

void setupComplete()
{
  // Reset servo positions and beep twice to indicate setup is complete
  Yaw.attach(YawServo);
  //Pitch.attach(PitchServo);
  //Pitch.write(80);
  Yaw.write(1425);
  delay(450);
  digitalWrite(PowerLED, HIGH); // power led on to indicate power
  //tone(Speaker, 600, 500); // POST complete beep
}

// =======================================================================
// =======================================================================
// =======================================================================

void loop() {

  previousTime = currentTime;        // Previous time is stored before the actual time read
  currentTime = millis();            // Current time actual time read
  currentMicros = micros();
  elapsedTime = (currentTime - previousTime) / 250; // not sure why it's by 250 but it works???

  //get the input and sensor data first
  btInput();
  readYaw();
  
  //move motors and servos
  analogControlRight();
  analogControlLeft();

  //Effects
  ActivityLEDChange();

}

// =======================================================================
// =======================================================================
// =======================================================================

void btInput()
{
  if (Serial.available())
  {
    BluetoothData = Serial.read(); //Get next character from bluetooth

    //Test for a connection
    
    if (connectionFound == 0) //nake sure this only happens once
    {
      connectionFound = 1;
      //tone(Speaker, 800, 100); // Connection Found
    }
 
  
    if (BluetoothData == 'A')
    {
      A = Serial.parseInt();
      RightMotor = 1;
    }
    if (BluetoothData == 'B')
    {
      B = Serial.parseInt();
      LeftMotor = 1;
    }

    if (BluetoothData == 'Y')
    {
      headYawTarget = Serial.parseInt();
      yawPrevious = Yaw.read();
      Yaw.write((yawPrevious * 0.4) + (headYawTarget * 0.6));
      headYaw = 0;
    }

  }
}


// =======================================================================
// =======================================================================
// =======================================================================


void analogControlRight()
{
  //measure the input from the controller and adjust the speed of the
  //right wheel accordingly
  if (RightMotor == 1)
  {
    if (A < 120 && A > -120) // dead zone stop all
    {
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      A = 0;
    }
    else
    {
      if (A > 0) // forward so set motor direction
      {
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
      }
      else // backward instead
      {
        A = -A;
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
      }
    }
    analogWrite(enA, A);
    RightMotor = 0;
  }
}



// =======================================================================
// =======================================================================
// =======================================================================

void analogControlLeft()
{
  //measure the input from the controller and adjust the speed of the
  //left wheel accordingly
  if (LeftMotor == 1)
  {
    if (B < 120 && B > -120) // dead zone - stop all
    {
      digitalWrite(in4, LOW);
      digitalWrite(in3, LOW);
      B = 0;
    }
    else
    {
      if (B > 0)
      {
        digitalWrite(in4, LOW);
        digitalWrite(in3, HIGH);
      }
      else
      {

        B = -B;
        digitalWrite(in4, HIGH);
        digitalWrite(in3, LOW);
      }

    }
    analogWrite(enB, B);
    LeftMotor = 0; // reset the loop for the next value
  }
}

// =======================================================================
// =======================================================================
// =======================================================================

void headYawMotion()
{
  if (headYaw == 0) // turned on
  {
    dt += currentTime - previousTime;
    if (dt >= 100) // wait for each servo update
    {
      Yaw.write(headYawTarget);
      dt = 0;
      headYaw = 4;
    }
  }
}

// =======================================================================
// =======================================================================
// =======================================================================

void readYaw()
{
  Wire.beginTransmission(MPU);
  Wire.write(0x43); // Gyro data first register address 0x43
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
  GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
  GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = GyroZ - 0.133;
  vehicleYaw =  vehicleYaw + GyroZ * elapsedTime;
}

// =======================================================================
// =======================================================================
// =======================================================================

void ActivityLEDChange() {
  //Blink without delay - Thanks to Robin2 from the arduino forums
  if (ActivityLEDState == LOW) {
    if (currentTime - previousActivityLEDTime >= ActivityLEDInteval) {
      ActivityLEDState = HIGH;
      previousActivityLEDTime += ActivityLEDInteval;
    }
  }
  else {
    if (currentTime - previousActivityLEDTime >= blinkDuration) {
      ActivityLEDState = LOW;
      previousActivityLEDTime += blinkDuration;
    }
  }
  // Change the LED Time and inteval after a number of
  // LED changes to make it blink more randomly
  if (digitalRead(ActivityLED) != ActivityLEDState)
  {
    counter++;
    if (counter == 10)
    {
      if (ActivityLEDInteval == 1500)
      {
        ActivityLEDInteval = 100;
        blinkDuration = 100;
        counter = 3;
      }
      else
      {
        ActivityLEDInteval = 1500;
        blinkDuration = 400;
        counter = 0;
      }
    }
  }
  digitalWrite(ActivityLED, ActivityLEDState);
}

// =======================================================================
// =======================================================================
// =======================================================================

Hey all, so I have been playing around with this to try to figure out what is going on. I had noticed that even with the wire library disabled, there was still a tiny bit of twitching. As soon as I added the second servo, this got worse. By this point I was thinking it may be a wiring or power issue. I stripped the whole thing down and replaced all of the power cables to 20AWG from the crappy cheap DuPont cables I was using. I also changed the wiring a little (diagram below) so that the servos had their own buck convertor and the Arduio would have it's own too. I now have a dedicated 5v going to the two servos and a dedicated 7v going to the arduino which powers a couple of things itself. I included some high quality XT30 connectors for each power connection that is not soldered in place. i feel like the power should be rock solid now but it's still doing the same thing.

After a bit more thinking I decided to check the amperage going from the battery to the small distribution board and found that even with the two 12v motors running, both servos moving quickly, all 4 leds turned on and the HC-05 and MPU6050 doing stuff, the total consumption was only 60ma. This can't be right can it? I have 3 18650 batteries powering the project and i am wondering if this is the problem?

If anyone has any input or thought i would love to hear them.

Thanks everyone!

Power Delivery:

Hi,

You don't need the 7V supply, use another 5V supply and connect it directly to the 5V pin on the UNO.
The 7V is regulated down to 5V with a linear regulator in the UNO, it has limited current capacity and in your case would only consume energy in its inefficiency.

Tom... :grinning: :+1: :coffee: :australia:

Thanks Tom, I did originally have 5v connected to the VIN pin on the Arduino which seemed to work but i found a bunch of people saying it should be 7v on that pin so i upped it. If I connect 5v directly to the 5v pin would that be better? From what I have read, I have up to 900ma available through the 5v pins with this setup but realistically only need enough for the HC-05, MPU6050 and a few LEDs. And of course the Arduino itself. It may not be the most efficient method but is it going to be so bad that it could cause the servos to twitch?

I will likely sort that out anyway, any energy savings will be beneficial so I will take your advise but could that be causing my problems?

Hi,
It would be better to have 5V to the 5V pin if you can.
You need 7V or higher on the Vin pin because it is supplying a bog standard linear regulator.
They need at least 2V higher input voltage compared to output voltage to accomplish reliable and stable regulation.
So feeding 5V to the 5V pin will take some strain of your UNO.

Tom... :grinning: :+1: :coffee: :australia:
PS, I'm off to bed, 12:34am here, :sleeping: :sleeping: :sleeping: :sleeping: :sleeping: :sleeping:

Tanks Tom, I will give that a go and let you know how i get on. Sleep well!