Hi
I am new to programming with the Arduino. I am currently building a robot which is controlled via bluetooth. I am using the Arduino Mega (Chinese Clone). I have connected the HC-05 bluetooth module up using the serial port (tx, rx) but when I change it to serial1(tx1, rx1) it does not communicate at all! I have also tried using ports serial2 and serial3 but I get the same result.
Here is my code:
#include <AFMotor.h>
AF_DCMotor Motor1(1);
AF_DCMotor Motor2(2);
void setup()
{
pinMode( 15, INPUT_PULLUP );
Motor1.setSpeed(255);
Motor2.setSpeed(255);
Serial1.begin(9600);
}
void loop()
{
if (Serial1.available()) {
int c = Serial1.read();
Serial1.print(c);
if (c == '1') {
Motor1.run(FORWARD);
Motor2.run(FORWARD);
}
else if (c == '2') {
Motor1.run(BACKWARD);
Motor2.run(BACKWARD);
}
else if (c == '3') {
Motor1.run(BACKWARD);
Motor2.run(FORWARD);
}
else if (c == '4') {
Motor1.run(FORWARD);
Motor2.run(BACKWARD);
}
else if (c == '5') {
Motor1.run(RELEASE);
Motor2.run(RELEASE);
}
}
}
I have seen other people with the same problem but the advice is to add this line of code in the setup for internal pull-up resistors how ever it does not change anything.
pinMode( 15, INPUT_PULLUP );
The only other idea was to change to TX and RX leads round because some of the clone Arduino's have the TX and RX ports labelled wrong.
If you ave any ideas for why this does not work please let me know as I am completely stuck!
Thanks
James