Multiple devices on Serail port

Just starting my first Arduino project - Remote control boat (How to make a smartphone controlled boat || Arduino Uno || HC-05 || Beginnertopro.in).

I have downloaded code from the internet and uploaded it to the arduino but the motors do not turn. So much for plug and play.

I have configured the buttons on the android remote control software to send F, B, L, R, and S as appropriate.

The problem I have is I do not see how to troubleshoot to make sure that the arduino is in fact receiving the correct input from the remote.

I tried connecting a computer serial port (RX) to the Arduino (Serial TX) port, using Putty to receive the data from the arduino and I do not get anything)

I am not a C programmer but do have some experience with VB and they way I read the code below the arduino should send "Forward Move" out on its serial TX port when it receives the "F".

void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data & store into data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n");
if(data=='F'){
front();
}else if(data=='B'){
back();
}else if(data=='L'){
left();
}else if(data=='R'){
right();
}else if(data=='S'){
Break();
}

}
}

void front(){
Serial.println("Forward Move");
digitalWrite(lm2,HIGH);
digitalWrite(rm2,HIGH);
digitalWrite(lm1,LOW);
digitalWrite(rm1,LOW);

}

I get nothing out of the arduino. If I connect my computer serial port in parralel with the arduino serial port RX and the HC-05 Bluetooth Module putty does display data but it is not F, B, L, R, and S respectively.

With my past experience with serial communicaitos it looks like there is a data rate mismatch between the computer and the arduino/BT Module. From what I have found the default data rate for the HC-05 is 38400. I have tried that as well as 9600 and 19200 and get similar results but different characters displayed in putty so I thought that maybe I cannot connect both the PC serail port and the arduino to the HC-05 but thought I would ask here.

It is much easier to develop a project like that if you use SofwareSerial to create a separate serial port for the HC-05, Then you can use Serial to view debug messages on the Arduino Serial Monitor.

You could also try using the Serial Monitor to send the data that would normally come from the phone - i.e. to take the HC-05 out of the picture temporarily.

I don't know that the Arduino system has ever claimed that projects are "plug 'n play" :slight_smile:

...R

@OP

The following steps may help you to trouble shoot your system:

1. Build your UNO + HC05 + SM Circuit as follows:
hc5-3.png

2. Upload the following sketch.

#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX-pin of UNO connects TX of HC05

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  if (Serial.available() > 0)
  {
    byte x = Serial.read();  //receive character from SM
    SUART.print((char)x);         //send character to Phone
  }
  if (SUART.available() > 0) 
  {
    byte y = SUART.read(); //receive character from Phone
    Serial.print((char)y);      //send character to SM
  }
}

3. Check that there happens information exchange between SM and Android Smart Phone via UNO.

hc5-3.png

On some of the examples I see resistors in line with the bluetooth RX and some do not. Some have 1k ad 2K resistors and Golam's has 2.2 and 4.7. Why the differences? I do not have resistors.

The resistors reduce the rx input voltage to Bluetooth module to the required 3.3 volts. The absolute value of the resistors isn’t as important as the ratio which needs to be 1:2.

2k2 and 4k7 would produce 3.4 volts rather than the desired 3.3 which you get with 1k and 2k. The issue is that 1k and 2k are only available in 1% tolerance resistors. 2k2 and 4k7 are more common 5% tolerance values.

RockB:
On some of the examples I see resistors in line with the bluetooth RX and some do not. Some have 1k ad 2K resistors and Golam's has 2.2 and 4.7. Why the differences? I do not have resistors.

According to HC05's specification, the RX-pin of the BT is not 5V tolerant; it is a ~= 3.3V tolerant pin; therefore, the 5V logic signal coming into this point from the UNO must be scaled down to ~= 3.3V by a suitable voltage divider.

Voltage at RX-pin of BT = 5*(R1/(R1+R2)) Volt.

Thanks @WattsThat for excellent presentation in Post#4.

Finally getting back to this project. I have scaled it all the way back to just a simple serial communications sketch at this point.

I have the arduino pins 12 & 13 connected to pins 2 & 3 of a USB to serial. I have Putty running on the laptop listening on the COM port. When I turn on the arduino I start getting gibberish across the putty window.

Putty is configured for: 9600, 8,n,1 and flow control set to XON/XOFF

Based on my experience with serial communications in the past it looks like an incorrect data rate setting but I have tried all the common data rates (even though the sketch should be configuring the data rate for 9600) but the symptoms persist.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12,13); // RX, TX

void setup() {

mySerial.begin(9600); // Set the data rate for the SoftwareSerial port
mySerial.println("Comms up"); // Send string out to DB9 to confirm communications are up.
}

// run over and over
// Take the input from the HC-05 and send it to the PC
// Take the input from the PC and send it to the HC-05

void loop() {
mySerial.write("Test ");

}

I would look at Martyn Currey's tutorial
http://www.martyncurrey.com/hc-05-zg-b23090w-bluetooth-2-0-edr-modules/#more-5681

You have your connections messed up.

.

I went back and put the HC-05 on the Smart Serial port and the PC on the serial.

I think my issue was mySerial.write instead of println.

This is working

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8,9); // RX, TX
char data = 0; //Variable for storing received data
const int lm1=7;
const int lm2=6;
const int rm1=5;
const int rm2=4;

void setup()
{
Serial.begin(9600); // set up Serial library at 9600 bps
mySerial.begin(9600); // Set the data rate for the SoftwareSerial port
Serial.println("PC Comms Up"); // Print Line to PC to confirm communications with PC are up
pinMode(lm1,OUTPUT);
pinMode(lm2,OUTPUT);
pinMode(rm1,OUTPUT);
pinMode(rm2,OUTPUT);
}

void loop()
{
if(mySerial.available() > 0)
{
data = mySerial.read(); //Read the incoming data & store into data
Serial.println(data); //Print Value inside data in Serial monitor

if(data=='F'){
front();
}else if(data=='B'){
back();
}else if(data=='L'){
left();
}else if(data=='R'){
right();
}else if(data=='S'){
Break();
}

}
}
void front(){
Serial.println("Forward Move");
digitalWrite(lm2,HIGH);
digitalWrite(rm2,HIGH);
digitalWrite(lm1,LOW);
digitalWrite(rm1,LOW);

}
void back(){
Serial.println("Back Move");
digitalWrite(lm1,HIGH);
digitalWrite(rm1,HIGH);
digitalWrite(lm2,LOW);
digitalWrite(rm2,LOW);
}
void left(){
Serial.println("Left Move");
digitalWrite(rm2,HIGH);
digitalWrite(rm1,LOW);
digitalWrite(lm1,HIGH);
digitalWrite(lm2,LOW);
}
void right(){
Serial.println("Right Move");
digitalWrite(lm2,HIGH);
digitalWrite(lm1,LOW);
digitalWrite(rm1,HIGH);
digitalWrite(rm2,LOW);
}
void Break(){

Serial.println("Break");
digitalWrite(lm2,LOW);
digitalWrite(lm1,LOW);
digitalWrite(rm1,LOW);
digitalWrite(rm2,LOW);
}

OK, about time you learned how to post code here.

You need to go and read the forum instructions so that you can go back and modify each of your posts (not re-post them) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon. In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.

It is inappropriate to attach it as a ".ino" file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

I think you have uses the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code", it can be quite garbled and is always more difficult.

Also tidy up your blank space. Do use blank lines, but only between functional blocks.