Need very fast help!!!!!

Hello, I have problem with my project. I build robot with 2DC motor, arduino uno and shield and BT module.
When I connect with the phone to BT robot and send commands to the Arduino controller, engines do not respond.
However, when I use a simple command engine management, they work.
I have been using the software RocketBOT phone (Samsung S3).
Meybe the error is in program code?

#include <SoftwareSerial.h>
#include <Servo.h>
#define rxPin 5
#define txPin 6
// Sukuriamas naujas servo objektas
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
Servo leftServo;  // Kairysis variklis
Servo rightServo;  // Dešinysis variklis
int qualifier;
int dataByte;


void setup()  
{
  // Apra6omi tx, rx iš?jimai:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  //SoftwareSerial aprašymas
  mySerial.begin(9600);
  Serial.begin(9600);
  mySerial.begin(9600);   // BT modulis
  leftServo.attach(21);   
  leftServo.write(90);   // variklio stabdis
  rightServo.attach(22);              
  rightServo.write(90);  // variklio stabdis
}
void loop() // Vykdymas be pristabdym?
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
  if(mySerial.available()>1)
  {
    qualifier=mySerial.read();
    dataByte=mySerial.read();
 
    mySerial.print("qualifier = ");
    mySerial.println(qualifier);
    mySerial.print("dataByte = ");
    mySerial.println(dataByte);
 
    if ( qualifier == 68)
    {
      if (dataByte == 1)
      {
        forward();
      }
      if (dataByte == 2)
      { 
        left();
      }
      if (dataByte == 3) 
      {
        right();
      }
      if (dataByte == 4)
      {
        backward();
      }
      if (dataByte == 5)
      {
        stop();
      }
    }
  }
}
 
void stop(){
  leftServo.write(90);               // stop
  rightServo.write(90);              // stop
}
 
void forward(){
  leftServo.write(0);              // Važiuoja ? priek?
  rightServo.write(120);         
}
 
void backward(){
  leftServo.write(180);                // Važiuoja atgal
  rightServo.write(60);             
}
 
void left(){
  leftServo.write(140);                // ? kair?
  rightServo.write(100);              
}
 
void right(){
  leftServo.write(40);              // ? dešin? 
  rightServo.write(80);           
}

No need to declair mySerial.begin twice. Same in your loop function.

mySerial.begin(9600);
Serial.begin(9600);
**mySerial.begin(9600); **

.
.
.
if (mySerial.available())
...
if(mySerial.available()>1)

And this can be made into a case statement.

if (dataByte == 1)
{
forward();
}
if (dataByte == 2)
{
left();
}
if (dataByte == 3)
{
right();
}
if (dataByte == 4)
{
backward();
}
if (dataByte == 5)
{
stop();
}

Other than that, what are you sending from the android and what are you receiving?

My BT connect to the phone. But not responding to commands.

Can you explain what you expect this

if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
 if(mySerial.available()>1)
  {
    qualifier=mySerial.read();

to do?

I can't see how you would ever be able to read "qualifier"

But not responding to commands

I understand that, that's why I asked what are you sending from the android and what are you receiving? I'm assuming you have an android phone, am I correct, or is it an IPhone?

AWOL:
Can you explain what you expect this

if (mySerial.available())

Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
  if(mySerial.available()>1)
  {


to do?

I use Arduino UNO R3, UNO have only one serial. Because, i connect to the board BT module, I need one more serial.
This command checks the BT connection.Would I be wrong?

I asked you to explain what you were doing, not how you were doing it.
The number of serial interfaces is immaterial; I don't see how you could ever get anything into "qualifier"

if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
if(mySerial.available()>1)
{

All you need is this,

if (Serial.available()) // from USB
    mySerial.write(Serial.read());
  if(mySerial.available()>1) // from Bluetooth
  {

HazardsMind:

But not responding to commands

I understand that, that's why I asked what are you sending from the android and what are you receiving? I'm assuming you have an android phone, am I correct, or is it an IPhone?

I use RocketBOT program, and Samsung galaxy S3 smartphone.
Arduino and android connect. But i dont have data to RocketBot.

HazardsMind:

if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
if(mySerial.available()>1)
{

All you need is this,

if (Serial.available()) // from USB

mySerial.write(Serial.read());
  if(mySerial.available()>1) // from Bluetooth
  {

Now, the Arduino cant connect to the phone.

HazardsMind:

But not responding to commands

I understand that, that's why I asked what are you sending from the android and what are you receiving? I'm assuming you have an android phone, am I correct, or is it an IPhone?

I fix some problem, BT connect to the smartphone. When i press "forward" i have receive data:
qualifier = 68
dataByte = 1
But robot dont go forward.

First: For right now, get rid of everything, but if (mySerial.available())
** Serial.write(mySerial.read());** and see what do you get from the phone. You wont be able to do anything correctly, if you don't know what your getting.

Second:

if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
if(mySerial.available()>1)
{

This does NOT connect the BT module to the phone. This just checks to see if there is any data available to be read.

I fix some problem, BT connect to the smartphone. When i press "forward" i have receive data:
qualifier = 68
dataByte = 1
But robot dont go forward.

Ok great, now you have something to show. So now my question is how are the servos powered?

I'll try again.

  if (mySerial.available())  // is there something to read?
    Serial.write(mySerial.read()); // yes, so read it. It is no longer available to read.
  if (Serial.available())
    mySerial.write(Serial.read());
  if(mySerial.available()>1)  // a few microseconds later: is there anything to read? given that it takes over a millisecond to send a character at 
9660, it doesn't seem likely.
  {
    qualifier=mySerial.read();

Why don't you read the character into a variable BEFORE echoing it?

HazardsMind:
First: For right now, get rid of everything, but if (mySerial.available())
** Serial.write(mySerial.read());** and see what do you get from the phone. You wont be able to do anything correctly, if you don't know what your getting.

Second:

if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
if(mySerial.available()>1)
{

This does NOT connect the BT module to the phone. This just checks to see if there is any data available to be read.

I change it, now connect ok, and send data to the device. But robot dont go.
Maybe can solve this problem?

HazardsMind:
First: For right now, get rid of everything, but if (mySerial.available())
** Serial.write(mySerial.read());** and see what do you get from the phone. You wont be able to do anything correctly, if you don't know what your getting.

Second:

if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
if(mySerial.available()>1)
{

This does NOT connect the BT module to the phone. This just checks to see if there is any data available to be read.

I fix some problem, BT connect to the smartphone. When i press "forward" i have receive data:
qualifier = 68
dataByte = 1
But robot dont go forward.

Ok great, now you have something to show. So now my question is how are the servos powered?

I use the battery is 9V. It is powered by two motors and bt module. Maybe I need more power?

I use the battery is 9V. It is powered by two motors and bt module. Maybe I need more power?

9 Volt batteries are horrible for an Arduino project. Also please tell me you are not putting 9V directly into the BT module and servos, the Arduino is fine, it can handle 9V, but not the BT and servos.

HazardsMind:

I use the battery is 9V. It is powered by two motors and bt module. Maybe I need more power?

9 Volt batteries are horrible for an Arduino project. Also please tell me you are not putting 9V directly into the BT module and servos, the Arduino is fine, it can handle 9V, but not the BT and servos.

Everything seems to be about as


Baterry connect to the motor control shield. BT module connect to into the shield.

HazardsMind:

I use the battery is 9V. It is powered by two motors and bt module. Maybe I need more power?

9 Volt batteries are horrible for an Arduino project. Also please tell me you are not putting 9V directly into the BT module and servos, the Arduino is fine, it can handle 9V, but not the BT and servos.

What you need to do to engines and BT module for proper energy, and everything is functioning?

You didn't mention you were using a motor shield, that's why I ask how everything was powered.

Also what is "a simple command engine management"

  leftServo.attach(21);   
  leftServo.write(90);   // variklio stabdis
  rightServo.attach(22);              
  rightServo.write(90);  // variklio stabdis

How many GPIO pins are there on an UNO?

Mark