Problems with Servo motor mg90s with ardino uno

I connected an 7.5v lithium battery with 5v voltage regulator to one servo motor and connected the signal wite to ardino pin 10 and connected an ground wire to gnd in ardino.

For your info:
I am using
Ardino UNO smd
Lm7805 5v regulator
Breadboard
Lithium battery of 7.5v
Mg90s Servo motor

So please kindly help me with this

the above mentioned was basic step of my project, let me provide you with the entire project.
I have 4 ldr and we run servo motor with the difference between the intensity in LDR's, which controls the horizontal and vertical servo motors.

let me provide you the entire code

// C++ code
//
#include <Servo.h>

Servo servohori; //horizontal servo(BOTTOM SERVO)
int servoh = 0; //assign servo at 0 degree
int servohLimitHigh = 180; //maximum range of servo is 180 degree(it is variable you can also change)
int servohLimitLow = 10;   //minimum range of servo is 10 degree(it is variable you can also change)

Servo servoverti; //vertical servo(TOP SERVO) 
int servov = 0; 
int servovLimitHigh = 180;
int servovLimitLow = 10;

int ldrtopr = 1; //top right LDR A1 pin
int ldrtopl = 2; //top left LDR A2 pin

int ldrbotr = 0; // bottom right LDR A0 pin
int ldrbotl = 3; // bottom left LDR A3 pin


 void setup () 
 {
  servohori.attach(10); //horizontal servo connected to arduino pin 10
  servohori.write(0);
  
  servoverti.attach(9); //vertical servo connected to arduino pin 9
  servoverti.write(0);
  delay(500); //delay
  Serial.begin(9600);
 }

void loop()
{
  servoh = servohori.read();
  servov = servoverti.read();
  
  
  int topl = analogRead(ldrtopl); //read analog values from top left LDR
  int topr = analogRead(ldrtopr); //read analog values from top right LDR
  int botl = analogRead(ldrbotl); //read analog values from bottom left LDR
  int botr = analogRead(ldrbotr); //read analog values from bottom right LDR
    
  // Print LDR values to Serial Monitor
  Serial.print(topl);
  Serial.print(",");
  Serial.print(topr);
  Serial.print(",");
  Serial.print(botl);
  Serial.print(",");
  Serial.println(botr);

  int avgtop = (topl + topr) / 2; //average of top LDRs
  int avgbot = (botl + botr) / 2; //average of bottom LDRs
  int avgleft = (topl + botl) / 2; //average of left LDRs
  int avgright = (topr + botr) / 2; //average of right LDRs

  if (avgtop < avgbot)
  {
    servoverti.write(servov -1);
    if (servov > servovLimitHigh) 
     { 
      servov = servovLimitHigh;
     }
    delay(8);
  }
  else if (avgbot < avgtop)
  {
    servoverti.write(servov +1);
    if (servov < servovLimitLow)
  {
    servov = servovLimitLow;
  }
    delay(8);
  }
  else 
  {
    servoverti.write(servov);
  }
  
  if (avgleft > avgright)
  {
    servohori.write(servoh -1);
    if (servoh > servohLimitHigh)
    {
    servoh = servohLimitHigh;
    }
    delay(8);
  }
  else if (avgright > avgleft)
  {
    servohori.write(servoh +1);
    if (servoh < servohLimitLow)
     {
     servoh = servohLimitLow;
     }
    delay(8);
  }
  else 
  {
    servohori.write(servoh); // write means run servo
  }
  delay(50);
}

Libraries? i dont know im new

Is it 9V or 7.5V?
You need to:

  1. post your sketch code using the code button.
    image
  2. say what the problem is
  3. post a schematic or photo of your wiring

Sorry that was 7.5v. and here is the schematic

my problem is the servo motors are not working

Does the servo sweep example work?

1 Like

For two MG90S servos, the servo power supply must be able to supply 4.8 to 6V at 2 Amperes (one Ampere per servo).

Breadboards cannot handle motor or servo currents, so either solder the power connections, or use suitable connectors on a servo power distribution PCB.

1 Like

Your picture doesn’t provide enough detail. Could you post an annotated schematic? Additionally, I don’t have the parts shown in your picture, so please include links to technical documentation for each component. Links to Amazon or similar marketplaces typically don’t provide sufficient technical information, as they are primarily sales ads. Technical datasheets or manufacturer-provided documentation would be much more helpful.

No, it is not working

Then you may have a wiring error or a bad connection somewhere.
Sometimes the cheap breadboards do not make good connections.

Also the LM7805 work best with an input of at least 7.5V and a small capacitor on the input and output. If your battery is a 2S lipo then it is only 7.4V and you may have problems

C1 can be a 0.1uF or larger ceramic. C1 can be a 0.22uF or larger ceramic

Thank you very much for your suggestion. It worked perfectly.

Glad it worked.
Now have fun!