Hello,
I have a project with Arduino MEGA + Bluetooth HC-05 + Servo motors MG90S + VUmeter KA-2284 and Dfplayer. MEGA has outputs to 4 servo motors. I send data from my Android phone's bluetooth. I supply 5 V to whole system from an external 5V-2A DC adaptor.
When I send a command to a servo, it carries it out than the bluetooth gets disconnected and I cannot send any more command to the system until I reconnect the bluetooth.
Note : I programmatically attach the servo of related function, then I detach this servo after the task is completed.
Any comments ?
Inadequate power supply. Power the motors separately with an adapter that can provide 4.8 to 6V at more than 3 Amperes, as required by 4 SG-90 servos. Don't forget to connect the grounds.
The general rule of thumb for servos is to provide at least 1 Ampere per small servo (SG-90) and at least 2.5 Amperes per large servo (MG996R).
Hi Jreminton,
Thanks for your response. A few years ago, I had made a robot arm with 5 servos and used the same adaptor 5V-2A. At the beginning, I had difficulties to find a bigger adaptor but I had solved the problem by attaching and detaching the servos.
The problem you describe is typical of an inadequate power supply. However, it certainly can be due to other causes.
For help on this forum, people expect to see a wiring diagram (hand drawn is preferred, with pins and connections clearly labeled), links to the components, and the code, posted using code tags.
Here is a wiring diagram (this project is a talking robot head).
And the code
//---EB_robot_kafa_göz_çene MEGA---
#include <DFPlayerMini_Fast.h>
#include <Servo.h>
DFPlayerMini_Fast Ses_calar;
String Gelen_mesaj, Lisan, Gelen_bilgi;
//-----------------------------------------------------------------------------------------------
Servo Servo_cene_8;
Servo Servo_goz_aki_saga_sola_9;
Servo Servo_goz_kapagi_ac_kapa_10;
Servo Servo_goz_aki_asagi_yukari_11;
//==============================================================
void setup()
{
Serial.begin(9600);
Serial2.begin(9600); //Ses çalar modülü
Serial3.begin(9600); // Bluetooth
delay(2000);
while (!Serial2) { ; } // Ses çaları aktif hale getirmek
Serial.println("EB ses kumandalı çene hareketli robot kafa MEGA");
//--------------------------------------------------------------
delay(2000);
if (!Ses_calar.begin(Serial2))
{
Serial.println(F("Başlatılamıyor:"));
Serial.println(F("1.Lütfen bağlantınızı kontrol ediniz!"));
Serial.println(F("2.SD kartı takınız!"));
while(true){delay(0);}
}
Serial.println(F("Ses çalar bağlandı"));
//pinMode(7, INPUT);
}
//==============================================================
void loop()
{
if (Serial3.available() > 0)
{
Gelen_mesaj=Serial3.readString();
Lisan = Gelen_mesaj.substring(0,3);
Gelen_bilgi = Gelen_mesaj.substring(4,Gelen_mesaj.length());
Serial.println(Gelen_bilgi);
//--------------------------------------------------
if (Lisan == "TUR"){Turkce();}
else if (Lisan == "FRA"){Fransizca();}
else if (Lisan == "ENG"){Ingilizce();}
}
//-----------Lip synch--------------------------------
int Ses_seviyesi = -1;
Servo_cene_8.attach(8);
if(analogRead(2) < 341) Ses_seviyesi += 561;
if(analogRead(4) < 341) Ses_seviyesi += 561;
if(analogRead(6) < 341) Ses_seviyesi += 561;
if(Ses_seviyesi > 0)
{
Servo_cene_8.writeMicroseconds(Ses_seviyesi);
delay(100);
Servo_cene_8.write(125);
}
//-----------Hareket sensörü--------------------------------
}
//==============================================================
void Turkce()
{
if (Gelen_bilgi=="Merhaba") {Ses_calar.playFromMP3Folder(32);}
else if (Gelen_bilgi=="nasılsın") {Ses_calar.playFromMP3Folder(63);}
else if (Gelen_bilgi=="Sence zaman akıyor mu") {Ses_calar.playFromMP3Folder(64);}
else if (Gelen_bilgi=="Sence zaman ve mekan nedir") {Ses_calar.playFromMP3Folder(65);}
else {Ses_calar.playFromMP3Folder(199);} //Mesajınız anlaşılamamıştır
} // Türkçe son
//-------------------------------------------------------------------------------------------------------
// ---------------------------------------------FRANSIZCA------------------------------------------------
void Fransizca()
{
if (Gelen_bilgi == "où habites-tu") {Ses_calar.playFromMP3Folder(401);} // J'habite à Troie
else if (Gelen_bilgi == "quelle est ta devise") {Ses_calar.playFromMP3Folder(404);} // Tout est pour le mieux dans le meilleur des mondes
else if (Gelen_bilgi == "que penses-tu de l'espace et du temps")
else {Ses_calar.playFromMP3Folder(599);} // Désolée, je n'ai pas compris votre message
} // Fransızca son
//-------------------------------------------------------------------------------------------------------
void Ingilizce()
{
if (Gelen_bilgi == "hello") {Ses_calar.playFromMP3Folder(201);} // Hello
else if (Gelen_bilgi == "what is your name") {Ses_calar.playFromMP3Folder(202);} // My name is
else if (Gelen_bilgi == "how are you")
else {Ses_calar.playFromMP3Folder(399);} // Sorry I couldn't understand your message
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void Servo_test_09()
{
for (int k=1; k<=5; k++)
{
for (int j=0; j<= 180; j++)
{
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(10); Servo_goz_aki_saga_sola_9.detach();
}
for (int j=180; j>= 0; j--)
{
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(10); Servo_goz_aki_saga_sola_9.detach();
}
}
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(90);
}
//-------------------------------------------------------------------------------------------------------
void Servo_test_10()
{
for (int k=1; k<=5; k++)
{
for (int j=0; j<= 180; j++)
{
Servo_goz_kapagi_ac_kapa_10.attach(10); Servo_goz_kapagi_ac_kapa_10.write(j); delay(10); Servo_goz_kapagi_ac_kapa_10.detach();
}
for (int j=180; j>= 0; j--)
{
Servo_goz_kapagi_ac_kapa_10.attach(10); Servo_goz_kapagi_ac_kapa_10.write(j); delay(10); Servo_goz_kapagi_ac_kapa_10.detach();
}
}
Servo_goz_kapagi_ac_kapa_10.attach(10); Servo_goz_kapagi_ac_kapa_10.write(90);
}
//-------------------------------------------------------------------------------------------------------
void Servo_test_11()
{
for (int k=1; k<=5; k++)
{
for (int j=0; j<= 180; j++)
{
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(j); delay(10); Servo_goz_aki_asagi_yukari_11.detach();
}
for (int j=180; j>= 0; j--)
{
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(j); delay(10); Servo_goz_aki_asagi_yukari_11.detach();
}
}
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(90);
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void Gozunu_ac()
{
for (int j=30; j<= 150; j++)
{
Servo_goz_kapagi_ac_kapa_10.attach(10); Servo_goz_kapagi_ac_kapa_10.write(j); delay(10); //Servo_goz_kapagi_ac_kapa_10.detach();
}
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_ac_kapat()
{
Serial.println("Tamam geldi");
Gozunu_ac();
delay(100);
//Gozunu_kapat();
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void Gozunu_sag_sol_ortala()
{
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(70); delay(100); Servo_goz_aki_saga_sola_9.detach();
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_saga_cevir()
{
for (int j=110; j>= 50; j--)
{
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(20); Servo_goz_aki_saga_sola_9.detach();
}
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_sola_cevir()
{
for (int j=50; j<= 110; j++)
{
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(20); Servo_goz_aki_saga_sola_9.detach();
}
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_saga_sola_cevir()
{
Gozunu_sola_cevir();
Gozunu_saga_cevir();
Gozunu_sag_sol_ortala();
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void Gozunu_asagi_yukari_ortala()
{
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(90); delay(100); Servo_goz_aki_asagi_yukari_11.detach();
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_yukari_cevir()
{
for (int j=110; j>= 50; j--)
{
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(j); delay(20); Servo_goz_aki_asagi_yukari_11.detach();
}
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_asagi_cevir()
{
for (int j=50; j<= 110; j++)
{
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(j); delay(20); Servo_goz_aki_asagi_yukari_11.detach();
}
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_asagi_yukari_cevir()
{
Gozunu_asagi_cevir();
Gozunu_yukari_cevir();
Gozunu_asagi_yukari_ortala();
}
//-------------------------------------------------------------------------------------------------------
void Gozunu_dort_dondur()
{
for (int j=110; j>= 50; j--){Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(20); Servo_goz_aki_saga_sola_9.detach();} //M9=50
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(90); delay(100); Servo_goz_aki_asagi_yukari_11.detach(); // Motor11 yatayda //M11=90
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(70); delay(100); Servo_goz_aki_saga_sola_9.detach(); //M9=70
for (int j=110; j>= 50; j--){Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(j); delay(20); Servo_goz_aki_asagi_yukari_11.detach();} //M11=50
for (int j=50; j<= 110; j++){Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(20); Servo_goz_aki_saga_sola_9.detach();} //M9=110
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(90); delay(100); Servo_goz_aki_asagi_yukari_11.detach(); //M11=90
Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(70); delay(100); Servo_goz_aki_saga_sola_9.detach(); //M9=70
for (int j=50; j<= 110; j++){Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(j); delay(20); Servo_goz_aki_asagi_yukari_11.detach();} //M11=110
for (int j=110; j>= 50; j--){Servo_goz_aki_saga_sola_9.attach(9); Servo_goz_aki_saga_sola_9.write(j); delay(20); Servo_goz_aki_saga_sola_9.detach();} //M9=50
Servo_goz_aki_asagi_yukari_11.attach(11); Servo_goz_aki_asagi_yukari_11.write(90); delay(100); Servo_goz_aki_asagi_yukari_11.detach(); // Motor11 yatayda //M11=90
Gozunu_sag_sol_ortala();
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
void Agzini_ac()
{
for (int j=140; j>= 90; j--)
{
Servo_cene_8.attach(8); Servo_cene_8.write(j); delay(20); Servo_cene_8.detach();
}
}
//------------------------------------------------------------------------------------------------------- ,
void Agzini_kapat()
{
for (int j=90; j<= 140; j++)
{
Servo_cene_8.attach(8); Servo_cene_8.write(j); delay(20); Servo_cene_8.detach();
}
}
//-------------------------------------------------------------------------------------------------------
void Agzini_ac_kapat()
{
for (int i=1; i<= 5; i++)
{
Agzini_ac();
Agzini_kapat();
}
}
According to your schematic the 5v is going to Vin. Vin then goes through the regulator.
The specs for the Mega say that Vin should be 7-12 volts.
Hi Cattledog,
Thanks for your response. In fact, MEGA is working normally, i.e. when I send a string from my mobile phone, I hear an audio message that is read from the DfPlayer. Bluetooth never disconnects.
The problem occurs when the string that I send requires a servo to turn. The first attempt is OK, the servo turns but Bluetooth disconnects immediately.
Anyway, I am now thinking to supply 9V through the Vin of MEGA and supply other components by dividing this voltage with resistors in accordance with voltage limits of each of them.
system
Closed
July 27, 2025, 5:20pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.