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.