SOLVED
In the Arduino code I was required to change
BTserial.print(10)
to
BTserial.print(“10”)
Also I needed to have both Read and Write information as STRINGS rather than BYTES.
I also required using both the standard Bluetooth Client AND the BluetoothLE extension. Using the Bluetooth client allows for a setting to be changed to set read/write strings as UTF-8.
If anyone has the same issues, feel free to PM me for more information.
Hello all, I have a wee issue that is causing me some grief, and unfortunately my Google-Fu is failing me.
I have built a small relay control module with a HM-10 BLE and a NANO, to control three relays via an app on my phone.
I can connect, disconnect, and control all three relays as well as I could hope, however I am seemingly unable to send any information back from the NANO to the app for feedback.
So, This part works fine.
i.e. ‘turn on relay 1’ → ‘relay 1 turns on’
However this part does not.
i.e. ‘relay 1 has turned on, send value to app’ → ‘receive value, change indication to ON’
Does anyone have an idea where I have gone wrong? As shown in the code below I have tried using Print, Write, and Println commands to send the value. All three have no effect.
Also would anyone be able to tell me how the data is likely to be sent over the bluetooth, as binary, string, byte, bit, UTF-8, UTF-16 etc.
Any hints or advice would be greatly appreciated.
Regards.
My arduino code is as follows
//BLUETOOTH RX,8 TX,9
//MUST HAVE ARDUINO_TX TO BT_RX THROUGH A VOLTAGE DIVIDER!!!!!
// TX_100OHM_RX_200OHM_GND
//
//RELAY 1 - PIN 4
//RELAY 2 - PIN 5
//RELAY 3 - PIN 6
#include "Arduino.h"
#include <SoftwareSerial.h>
#define r1 4
#define r2 5
#define r3 6
SoftwareSerial BTserial(8, 9); // RX , TX
byte LEDpin = 8;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
digitalWrite(r1, LOW);
digitalWrite(r2, LOW);
digitalWrite(r3, LOW);
Serial.begin(9600);
Serial.println("Set up complete");
BTserial.begin(9600);
delay(100);
}
void loop()
{
if (BTserial.available() > 0)
{
delay(500);
char data = (char) BTserial.read();
switch (data)
{
case '0':
Serial.println("R1 OFF");
BTserial.print (10);
digitalWrite(r1, LOW);
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
break;
case '1':
Serial.println("R1 ON");
BTserial.print (11);
digitalWrite(r1, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
break;
case '2':
Serial.println("R2 OFF");
BTserial.write(12);
digitalWrite(r2, LOW);
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
break;
case '3':
Serial.println("R2 ON");
BTserial.write(13);
digitalWrite(r2, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
break;
case '4':
Serial.println("R3 OFF");
BTserial.println(14);
digitalWrite(r3, LOW);
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
break;
case '5':
Serial.println("R3 ON");
BTserial.println(15);
digitalWrite(r3, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
break;
default:
Serial.print("NOT RECOGNISED: ");
Serial.println(data);
BTserial.print("Error!");
}
}
}
Bluetooth_Relay.ino (2.48 KB)