hello there, i require some help on my project. it cant seem to work with it. i create the app at mit app inventor and use some coding. i dont know where the my coding is wrong or my connection because a bit confuse with the RX and TX. i used the RX1 and TX1 at pin 19(TX) and pin 18(RX) of Arduino Mega. i dont know how to declare or maybe i did some istake. please, i need help on my final year project.
#include <SoftwareSerial.h>
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);
SoftwareSerial BT(19, 18); //TX, RX respetively
String readdata;
void setup() {
BT.begin(9600);
Serial.begin(9600);
Serial.println("Motor Test!");
motor1.setSpeed(105); //set the speed of the motors, between 0-255
motor2.setSpeed (105);
}
//-----------------------------------------------------------------------//
void loop() {
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
readdata += c; //build the string- "forward", "reverse", "left" and "right"
}
if (readdata.length() > 0) {
Serial.println(readdata);
if(readdata == "Forward")
{
motor1.run(FORWARD);
motor2.run(FORWARD);
delay(100);
}
else if(readdata == "Backward")
{
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(100);
}
else if (readdata == "Right")
{
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay (100);
}
else if ( readdata == "Left")
{
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay (100);
}
else if (readdata == "Stop!")
{
motor1.setSpeed(0);
motor2.setSpeed(0);
delay (100);
}
readdata="";}} //Reset the variable