DSD tech Bluetooth module 4.0

I am currently trying to learn about using Arduino for projects in the near future.

I bought this Bluetooth module to try to control an Arduino remotely using my phone, It's the "DSD TECH Bluetooth 4.0 BLE Slave UART Serial Module Compatible with iOS Device iPhone for DIY" on amazon.

The problem I am currently facing is that I don't understand how the code for the Bluetooth module or Bluetooth serial monitor works. I am trying to use numbers (or text but I figured numbers were a good spot to start) to set a variable in a program. I have tried a couple different ways but I just get confusing numbers that make no sense to me on the serial monitor(s). Attached are pictured of the serial monitor on my phone and computer. The only inputs I made were on my phone:
0
1
2
ON
None of these changed whether the rest of my code was running or not, my display just showed "0000" the whole time. While the program runs normally it displays the distance the ultrasonic sensor is reading.

I am using an Arduino UNO R3.
I am using an app called Serial Bluetooth on Android because the DSD tech app was not working for me.

I did not include the other section of my code because it is working properly without the serial monitor code

I only included comments on the code involving the Serial monitor and Bluetooth, the rest of the code was working perfectly before I added the serial monitor code.

#include <SoftwareSerial.h> //Include serial software library

#include <TM1637Display.h>

#include <Servo.h>

#define rxPin 0 //Set pin 0 to rx
#define txPin 1 //Set pin 1 to tx

SoftwareSerial mySerial(rxPin, txPin); 
char myChar ; //Create a variable to store serial inputs

#define CLK 5
#define DIO 6

TM1637Display display = TM1637Display(CLK, DIO);

Servo myservo;

int holdYellow = 0;
int periodYellow = 600;
unsigned long time_now = 0;

const int pingPin = 7;
int servoPos = 0;
int leftStor;
int rightStor;

int hold = 0; //Used to hold once serial input is read, in theory should not be needed but tried it anyway

long duration, inches, cm;

void setup() {

  mySerial.begin(9600);
  mySerial.println("Connected Serial Phone");

  Serial.begin(9600);
  Serial.println("Connected Serial PC");

  display.setBrightness(5);

  display.showNumberDecEx(8888);

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

  myservo.attach(12);

  myservo.write(90);

  delay(1000);
}

void loop() {

  if (mySerial.available()) { //If there is input from the serial monitor
    myChar = mySerial.read(); //Set myChar variable to the input of the serial monitor
    mySerial.read(); //Not really sure what this does but serial monitor does not print anything without it
    Serial.println(myChar); //Print myChar for debugging purposes
    Serial.println(mySerial.read()); //Print mySerial.read() for debugging purposes

  if (myChar == 1) { //If myChar is one
    hold = 1; //Set hold to one
  }

  if (myChar == 2){ //If myChar is two
    hold = 0; //Set hold to zero
  }
  }

  if (hold == 1) { //If hold is one, run normal program

    delay(100);

    readUltrasonic();

    display.showNumberDecEx(inches);

    checkSides();

    buzzerTimer();
  }
  else { //If hold is not one
    display.showNumberDec(10000); //Display '0000' on display
  }
}

Another problem I am having is that I cannot upload new code to the Arduino with the Bluetooth module attached. I have to remove the Bluetooth module and plug it back in once the code has uploaded. Not a big deal but just an odd thing I noticed.

Any help is greatly appreciated.
Thank you.

arduinodebug.JPG

arduinodebug.JPG

Good job using code tags and inline images on your first post.

There are several problems to fix.

The reason why the display shows 0000 and the distance sense in not operating is because hold is never getting set to 1 . You are sending and reading ascii chars, not integers. Use single quotes to indicate a char

if (myChar == '1') { //If myChar is one
    hold = 1; //Set hold to one
  }

  if (myChar == '2'){ //If myChar is two
    hold = 0; //Set hold to zero
  }
  }

  if (hold == 1) { //If hold is one, run normal program

Pins 0 and 1 are the hardware serial pins. If you are willing to disconnect the module when you load code and your input is coming from the phone and not the monitor you can leave the module connected to these pins.

Many of the classic bluetooth modules are 5v tolerant on their Rx pin, but I don't know if that is the case with your module. You may want to use a voltage divider or level shifter on that line. There is plenty to be found using Google if you search on "voltage divider bluetooth rx arduino"

Connect module TX to D0 (Arduino RX)
Connect module RX via voltage divide to D1(Arduino TX)

Remove all references to software serial and mySerial. Use Serial.print() and Serial.read().

I just get confusing numbers that make no sense to me on the serial monitor(s).

The 13 and 10 You are seeing are the carriage return('\r') and line feed ('\n') ascii values sent by the phone. You can set up your phone to not send these if you want.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.