Go Down

Topic: 2 DC and 6 Servo motor Robot don't work (Read 2039 times) previous topic - next topic

Ogaataa

hello guys, i'm running a robot with arduino uno using 2 DC motors controlling them using a 4-channel relay module
and 6 servo motors -their power source is a direct 12v battery-

the 6 servos are called :
Servo servo1R;
Servo servo2R;
Servo servo3R;
Servo servo1L;
Servo servo2L;
Servo servo3L;

and i want to control them using a HC-05 Bluetooth module and a smartphone . the module works fine when i upload a code to print the values on the serial monitor only.
 but i got no values on the screen when i upload the whole code of the robot. the serial monitor remains white with no values at all.

this is the robot code :

#include <SoftwareSerial.h>
SoftwareSerial HC05 (12,13);  //(TX,RX)
#include <Servo.h>
Servo servo1R;
Servo servo2R;
Servo servo3R;
Servo servo1L;
Servo servo2L;
Servo servo3L;
int x=0;
float pos1R;
float pos2R;
float pos3R;
float pos1L;
float pos2L;
float pos3L;
#define IN1 5
#define IN2 6
#define IN3 9
#define IN4 10

const int servo1RP=119;
const int servo1RN=120;
const int servo2RP=122;
const int servo2RN=121;
const int servo3RP=82; // red button
const int servo3RN=66; // blue button

const int servo1LP=105;
const int servo1LN=99;
const int servo2LP=97;
const int servo2LN=101;
const int servo3LP=89; // yellow button
const int servo3LN=71; // green button
const int FWD=49;
const int FWD1=50;
const int FWD2=56;
const int BK=53;
const int BK1=52;
const int BK2=54;
const int R=51;  //assume IN1,IN2 for the motor on the right
const int L=55;  //assume IN3,IN4 for the motor on the left
const int Stop=48;
void setup() {
  Serial.begin(9600);
  HC05.begin(9600);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  //servo1R.attach(11);
  //servo2R.attach(12);
  //servo3R.attach(13);
  //servo1L.attach(14);
  //servo2L.attach(15);
  //servo3L.attach(16);
}

void loop() {
  if(HC05.available())
  { x=HC05.read();
   Serial.println(x);
   //delay(5);
  }

   
   
   if(x==servo1RP)
   {
    pos1R=pos1R+1;
    //servo1R.write(pos1R);
    //delay(50);
    }
   if(x==servo1RN)
   {
    pos1R=pos1R-1;
    //servo1R.write(pos1R);
    //delay(50);
    }
   
    if(x==servo2RP)
   {
    pos2R=pos2R+1;
    //servo2R.write(pos2R);
    //delay(10);
    }
   if(x==servo2RN)
   {
    pos2R=pos2R-1;
    //servo2R.write(pos2R);
    //delay(10);
    }

    if(x==servo3RP)
   {
    pos3R=pos3R+1;
    //servo3R.write(pos3R);
    //delay(10);
    }
   if(x==servo3RN)
   {
    pos3R=pos3R-1;
    //servo3R.write(pos3R);
    //delay(10);
    }

   
   
   if(x==servo1LP)
   {
    pos1L=pos1L+1;
    //servo1L.write(pos1L);
    //delay(10);
    }
   if(x==servo1LN)
   {
    pos1L=pos1L-1;
    //servo1L.write(pos1L);
    //delay(10);
    }
   
    if(x==servo2LP)
   {
    pos2L=pos2L+1;
    //servo2L.write(pos2L);
    //delay(10);
    }
   if(x==servo2LN)
   {
    pos2L=pos2L-1;
    //servo2L.write(pos2L);
    //delay(10);
    }

    if(x==servo3LP)
   {
    pos3L=pos3L+1;
    //servo3L.write(pos3L);
    //delay(10);
    }
   if(x==servo3LN)
   {
    pos3L=pos3L-1;
   // servo3L.write(pos3L);
    //delay(10);
    }

    if(x==Stop)
   {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,HIGH);
   }
     if(x==FWD || x==FWD1 || x==FWD2)
   {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,LOW);
    }
     if(x==BK || x==BK1 || x==BK2)
   {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,HIGH);
    }
     if(x==R)
   {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,LOW);
    }
     if(x==L)
   {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,HIGH);
    }
 
  else
    {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,HIGH);
     }
 

}

thanks in advance for your help.

AWOL

#1
Sep 20, 2016, 04:23 pm Last Edit: Sep 20, 2016, 04:23 pm by AWOL
What does your solitary debug print tell you? (feel free to share - we're friends here)

What happened to the code tags?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Ogaataa

it tells me nothing , the uploading runs successfully. it seems to be there is no problem with the compiler.

AWOL

Are you saying that the print here
Code: [Select]
  if(HC05.available())
  { x=HC05.read();
   Serial.println(x);
   //delay(5);
  }
doesn't produce anything?
Did it ever?
If not, how did you let the code get so big before deciding to debug it?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Ogaataa

it produces values when i delete the rest of the code. otherwise, it produces nothing at all

jremington

#5
Sep 20, 2016, 07:12 pm Last Edit: Sep 20, 2016, 07:13 pm by jremington
Quote
6 servo motors -their power source is a direct 12v battery-
What servos are you using? Most will be destroyed by connecting to a 12V battery.

Please edit your post and add code tags ("</>" button).

Ogaataa

actually i use a voltage regulators to have 6v instead of 12v

AWOL

As your code stands, if you receive a character, that character is assigned to the variable x, and until another character is received, the action which depends upon x will repeat. You may not want to do this, particularly for the servo position increments and decrements, which appear not to have any end-stops programmed.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Ogaataa

and what can i do to prevent this repeat ????? i need it to stop once i remove my finger of the button

PaulS

Quote
and what can i do to prevent this repeat
After you deal with the received character, set the variable to some other value:
Code: [Select]
x = ' '; // Or whatever value means do nothing

Quote
i need it to stop once i remove my finger of the button
You should NOT be sending a value over and over while you hold a switch down. Send one value when the switch BECOMES pressed. Send another value when the switch BECOMES released.

Start the action when the first value is received.
Stop the action when the second value is received.
The art of getting good answers lies in asking good questions.

AWOL

After you deal with the received character, set the variable to some other value
or put the code that tests and acts on the value read inside the same conditional that reads the serial port.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

MarkT

#11
Sep 26, 2016, 12:59 pm Last Edit: Sep 26, 2016, 12:59 pm by MarkT
actually i use a voltage regulators to have 6v instead of 12v
And your regulators can handle the peak currents from the servos and the backwards
current surges they produce?  No, probably not.

Power servos from a solid 6V supply and see if it makes a difference.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up