HC-06 disconnecting when servos using

I am doing a project with arduino nano and nano shield using 4 servo motors, 1 HC-06, 1 buzzer. I send and receive commands from the phone via Bluetooth, but whenever I use servo motors, the Bluetooth connection is disconnected. I am using 4 pcs 1.5V pen batteries. What must i do?

Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial

Start by posting your code, using code tags when you do, and a schematic of your project. a 'photo of a hand drawn schematic is good enough

Hi, @nemes1s
Welcome to the forum.

Do you have a DMM?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

What are the servos moving and can you post link to specs/data on them?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Kod:

#include <Servo.h>
#include <Oscillator.h>
#include <EEPROM.h>
#include <SerialCommand.h>
SoftwareSerial BTserial = SoftwareSerial(11,10);
SerialCommand SCmd(BTserial);
#include <Otto.h>
Otto Otto;
#define LeftLeg 2
#define RightLeg 3
#define LeftFoot 4
#define RightFoot 5
#define Buzzer  13
#define ECHOPIN 8
#define TRIGPIN 9

const char programID[] = "Otto Bluetooth App Firmware";
const char name_fac = '$';
const char name_fir = '#';
int T = 1000;
int moveId = 0;
int moveSize = 15;
volatile bool buttonPushed=false;
unsigned long previousMillis = 0;
int randomDance = 0;
int randomSteps = 0;
bool obstacleDetected = false;
unsigned long int matrix;
unsigned long timerMillis = 0;
void receiveStop() { sendAck(); Otto.home(); sendFinalAck(); }
void receiveLED() { sendAck(); Otto.home(); unsigned long int matrix; char *arg; char *endstr; arg = SCmd.next(); if (arg != NULL) { matrix = strtoul(arg, &endstr, 2); Otto.putMouth(matrix, false); } else { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } sendFinalAck(); }
void recieveBuzzer() { sendAck(); Otto.home(); bool error = false; int frec; int duration; char *arg; arg = SCmd.next(); if (arg != NULL) frec = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) duration = atoi(arg); else error = true; if (error == true) { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } else Otto._tone(frec, duration, 1); sendFinalAck(); }

void receiveTrims() { 
  sendAck(); 
  Otto.home(); 
  int trim_YL, trim_YR, trim_RL, trim_RR; 
  bool error = false; 
  char *arg; 
  arg = SCmd.next(); 
  if (arg != NULL) trim_YL = atoi(arg); 
  else error = true; 
  arg = SCmd.next(); 
  if (arg != NULL) trim_YR = atoi(arg); 
  else error = true; 
  arg = SCmd.next(); 
  if (arg != NULL) trim_RL = atoi(arg); 
  else error = true; 
  arg = SCmd.next(); 
  if (arg != NULL) trim_RR = atoi(arg); 
  else error = true; 
  if (error == true) { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } 
  else { Otto.setTrims(trim_YL, trim_YR, trim_RL, trim_RR); Otto.saveTrimsOnEEPROM(); } 
  sendFinalAck(); 
}

void receiveServo() { 
  sendAck(); 
  moveId = 30; 
  bool error = false; 
  char *arg; 
  int servo_YL, servo_YR, servo_RL, servo_RR; arg = SCmd.next(); 
  if (arg != NULL) servo_YL = atoi(arg); 
  else error = true; arg = SCmd.next(); 
  if (arg != NULL) servo_YR = atoi(arg); 
  else error = true; arg = SCmd.next(); 
  if (arg != NULL) servo_RL = atoi(arg); 
  else error = true; arg = SCmd.next(); 
  if (arg != NULL) { servo_RR = atoi(arg); } 
  else error = true; 
  if (error == true) { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } 
  else { int servoPos[4] = {servo_YL, servo_YR, servo_RL, servo_RR}; 
  Otto._moveServos(200, servoPos); } 
  sendFinalAck(); 
}


void receiveMovement() { sendAck(); if (Otto.getRestState() == true) Otto.setRestState(false); char *arg; arg = SCmd.next(); if (arg != NULL) moveId = atoi(arg); else { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); moveId = 0; } arg = SCmd.next(); if (arg != NULL) T = atoi(arg); else T = 1000; arg = SCmd.next(); if (arg != NULL) moveSize = atoi(arg); else moveSize = 15; }

void move(int moveId) { 
  bool manualMode = false; 
  switch (moveId) { 
    case 0: Otto.home(); break; 
    case 1: Otto.walk(1, T, 1); break; 
    case 2: Otto.walk(1, T, -1); break; 
    case 3: Otto.turn(1, T, 1); break; 
    case 4: Otto.turn(1, T, -1); break; 
    case 5: Otto.updown(1, T, moveSize); break; 
    case 6: Otto.moonwalker(1, T, moveSize, 1); break; 
    case 7: Otto.moonwalker(1, T, moveSize, -1); break; 
    case 8: Otto.swing(1, T, moveSize); break; 
    case 9: Otto.crusaito(1, T, moveSize, 1); break; 
    case 10: Otto.crusaito(1, T, moveSize, -1); break; 
    case 11: Otto.jump(1, T); break; 
    case 12: Otto.flapping(1, T, moveSize, 1); break; 
    case 13: Otto.flapping(1, T, moveSize, -1); break; 
    case 14: Otto.tiptoeSwing(1, T, moveSize); break; 
    case 15: Otto.bend(1, T, 1); break; 
    case 16: Otto.bend(1, T, -1); break; 
    case 17: Otto.shakeLeg(1, T, 1); break; 
    case 18: Otto.shakeLeg(1, T, -1); break; 
    case 19: Otto.jitter(1, T, moveSize); break; 
    case 20: Otto.ascendingTurn(1, T, moveSize); break; 
    default: manualMode = true; break; } if (!manualMode) sendFinalAck(); 
  }

void receiveGesture() { 
  sendAck(); 
  Otto.home();  
  int gesture = 0; 
  char *arg; 
  arg = SCmd.next(); 
  if (arg != NULL) gesture = atoi(arg); 
  else     delay(2000); 
  switch (gesture) { 
    case 1: Otto.playGesture(OttoHappy); break; 
    case 2: Otto.playGesture(OttoSuperHappy); break; 
    case 3: Otto.playGesture(OttoSad); break; 
    case 4: Otto.playGesture(OttoSleeping); break; 
    case 5: Otto.playGesture(OttoFart); break; 
    case 6: Otto.playGesture(OttoConfused); break; 
    case 7: Otto.playGesture(OttoLove); break; 
    case 8: Otto.playGesture(OttoAngry); break; 
    case 9: Otto.playGesture(OttoFretful); break; 
    case 10: Otto.playGesture(OttoMagic); break; 
    case 11: Otto.playGesture(OttoWave); break; 
    case 12: Otto.playGesture(OttoVictory); break; 
    case 13: Otto.playGesture(OttoFail); break; 
    default: break; } sendFinalAck();  
  }

void receiveSing() { 
  sendAck(); 
  Otto.home(); 
  int sing = 0; 
  char *arg; 
  arg = SCmd.next(); 
  if (arg != NULL) sing = atoi(arg); 
  else     delay(2000); 
  switch (sing) { 
    case 1: Otto.sing(S_connection); break; 
    case 2: Otto.sing(S_disconnection); break; 
    case 3: Otto.sing(S_surprise); break; 
    case 4: Otto.sing(S_OhOoh); break; 
    case 5: Otto.sing(S_OhOoh2); break; 
    case 6: Otto.sing(S_cuddly); break; 
    case 7: Otto.sing(S_sleeping); break; 
    case 8: Otto.sing(S_happy); break; 
    case 9: Otto.sing(S_superHappy); break; 
    case 10: Otto.sing(S_happy_short); break; 
    case 11: Otto.sing(S_sad); break; 
    case 12: Otto.sing(S_confused); break; 
    case 13: Otto.sing(S_fart1); break; 
    case 14: Otto.sing(S_fart2); break; 
    case 15: Otto.sing(S_fart3); break; 
    case 16: Otto.sing(S_mode1); break; 
    case 17: Otto.sing(S_mode2); break; 
    case 18: Otto.sing(S_mode3); break; 
    case 19: Otto.sing(S_buttonPushed); break; 
    default: break; } 
    sendFinalAck(); 
  }

void receiveName() { sendAck(); Otto.home(); char newOttoName[11] = ""; int eeAddress = 5; char *arg; arg = SCmd.next(); if (arg != NULL) { int k = 0; while ((*arg) && (k < 11)) { newOttoName[k] = *arg++; k++; } EEPROM.put(eeAddress, newOttoName); } else { delay(2000); } sendFinalAck(); }
void requestName() { Otto.home(); char actualOttoName[11] = ""; int eeAddress = 5; EEPROM.get(eeAddress, actualOttoName); Serial.print(F("&&")); Serial.print(F("E ")); Serial.print(actualOttoName); Serial.println(F("%%")); Serial.flush(); }
void requestProgramId() { Otto.home(); Serial.print(F("&&")); Serial.print(F("I ")); Serial.print(programID); Serial.println(F("%%")); Serial.flush(); }
void sendAck() { delay(30); Serial.print(F("&&")); Serial.print(F("A")); Serial.println(F("%%")); Serial.flush(); }
void sendFinalAck() { delay(30); Serial.print(F("&&")); Serial.print(F("F")); Serial.println(F("%%")); Serial.flush(); }
void ButtonPushed(){ if(!buttonPushed){ buttonPushed=true; Otto.putMouth(smallSurprise); } }





void setup() {
  Serial.begin(9600);
  BTserial.begin(9600);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer);
  Otto.home();
  SCmd.addCommand("S", receiveStop);
  SCmd.addCommand("L", receiveLED);
  SCmd.addCommand("T", recieveBuzzer);
  SCmd.addCommand("M", receiveMovement);
  SCmd.addCommand("H", receiveGesture);
  SCmd.addCommand("K", receiveSing);
  SCmd.addCommand("C", receiveTrims);
  SCmd.addCommand("G", receiveServo);
  SCmd.addCommand("R", receiveName);
  SCmd.addCommand("E", requestName);
  SCmd.addCommand("I", requestProgramId);
  SCmd.addDefaultHandler(receiveStop);
  Otto.sing(S_connection);
  Otto.home();
  Otto.sing(S_happy);
  delay(200);
  previousMillis = millis();
}

void loop() {
  Otto.home();
  if(BTserial.available()){
    SCmd.readSerial();  
    if (Otto.getRestState()==false){ move(moveId); }
  }
}

void obstacleDetector(){
  digitalWrite(TRIGPIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGPIN, LOW);
  float distance = pulseIn(ECHOPIN, HIGH);
  distance= distance/58;
  Serial.print(distance);
  Serial.println("cm");
  if(distance<15){
    obstacleDetected = true;
    Serial.println ("Obstacle Detected! Avoid collision");
  }
  else{
    obstacleDetected = false;
    Serial.println ("No Obstacle detected! - Keep on walking");
  }
}

HC-06
GCC -> V pin connected
GND -> G pin connected
Rx -> 10 pin connected
Tx -> 11 pin connected

Hi,
With a DMM measure the battery volts and make the fault occur.
Did the battery volts drop?

What spec your servos?

Tom... :smiley: :+1: :coffee: :australia:
PS. The image you supplied is OK, but you need to draw actual electronic schematics to make a diagram that can be easily followed for trouble-shooting.

Your post implies that your project works until the servos are actuated, i.e. it receives a command via Bluetooth OK, but Bluetooth then dies. If so, this suggests an inadequate power supply. No amount of re-drawing is going to fix that, but you might enlighten us on the actual batteries and the ratings of the servos.

Barely adequate! You might need to provide a separate power supply for the servos.

My power supply is:
LR6 AA 1.5 volt alkaline pen battery x 4
Others:
Tower Pro SC90 Micro Servo x 4
HC-06 x 1
Buzzer x 1
HC SR04 x 1

Hi,

Nothing in your reply answers the questions. Try disconnecting the servos and see if Bluetooth keeps going.
If it does, that is further confirmation of inadequate power.

You appear to have a servo shield specifically made for Nano. If so, you might check if it can run with 6xAA, i.e does it have on-board regulators?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.