i am trying to make an app that controls Arduino for a project I working on but I am having problems with the Bluetooth module. I have never used Bluetooth with Arduino before so I decided to try turning an LED on and off. but even after I connect my phone to the hm-10 module every command I send does not seem to be received by the module.
I used the same wiring as every youtube tutorial and article I saw, they are essentially all the same.
this is the code I used
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(9, 10);
int LED = 13;
int Data;
void setup() {
Bluetooth.begin(9600);
Serial.begin(9600);
Serial.println("Waiting for command...");
Bluetooth.println("Send 1 to turn on the LED. Send 0 to turn Off");
pinMode(LED, OUTPUT);
}
void loop() {
if(Bluetooth.available()){
Data=Bluetooth.read();
if(Data == '1'){
digitalWrite(13, HIGH);
Serial.println("LED On");
Bluetooth.println("LED On");
}
else if(Data=='0'){
digitalWrite(LED, 0);
Serial.println("LED Off");
Bluetooth.println("LED On D13 Off");
}
else{;}
}
}
This is a screenshot from my phone. It is connect the light on the module stopped flashing, and it sent instructions to my phone, but when i send the number 1 to turn on the led, it does nothing.
//https://forum.arduino.cc/t/bluetooth-connectivity-not-working-hm-10/1263617
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(9, 10);
int LED = 13;
void setup()
{
Bluetooth.begin(9600);
Serial.begin(9600);
Serial.println("Waiting for command...");
Bluetooth.println("Send 1 to turn LED ON - Send 0 to turn LED OFF");
pinMode(LED, OUTPUT);
}
void loop()
{
if (Bluetooth.available())
{
switch (Bluetooth.read())
{
case '1':
digitalWrite(13, HIGH);
Serial.println("LED ON");
Bluetooth.println("LED ON");
break;
case '0':
digitalWrite(LED, LOW);
Serial.println("LED OFF");
Bluetooth.println("LED OFF");
break;
case '\r':
Bluetooth.println("Send 1 to turn LED ON - Send 0 to turn LED OFF");
break;
}
}
}
The wiring is fine, i have rx connected to 9 and tx connected to 10. The phone app is set to CR. it is connecting, when i use the serial monitor for the data inputs it sends the LED ON or LED OFF messages.