#include SoftwareSerial BTSerial(2, 3); // RX | TX int x = 15; // logic 1, 248 code int y = 0; // logic 0, 128 code void setup() { pinMode(2, INPUT); pinMode(3, OUTPUT); Serial.begin(115200); // CHANGING RATE FORM 38400 to 115200; Serial.println("Enter AT Commands:"); BTSerial.begin(38400); // HC-06 default speed in AT command mode } void send1() { BTSerial.write(x); delay(10); } void send0() { BTSerial.write(y); delay(10); } void print_float(float num) { union { float input; int output; } data; data.input = num; for (int i = 31; i >= 0; i--) { Serial.print((data.output >> i) & 1); if (i % 4 == 0) { Serial.print(" "); // Add a space every 4 bits for readability } } Serial.println(); } void send_float(float num) { union { float input; int output; } data; data.input = num; for (int i = 31; i >= 0; i--) { if ((data.output >> i) & 1) { send1(); } else { send0(); } } } void loop() { ////////////////////////// SEND ////////////////////////// // send_float(5.632); // print_float(5.632); // delay(1000); ///////////////////////////////////////////////////////////// ////////////////////////// RECEIVE ////////////////////////// //The code below allows for commands and messages to be sent from HC-06 -> COMPUTER (serial monitor) union { float flt; unsigned long integer; } data; data.integer = 0; for (int i = 0; i<32; i++) { while (not (BTSerial.available())) { delay(1); } int val = int(BTSerial.read()); if (val > 192) { val = 0; } else { val = 1; } data.integer = ((data.integer << 1) | val); } Serial.println(data.flt); delay(10); /////////////////////////////////////////////////////////////////////////// //////////////////////////// OLD //////////////////////////////////////// //The code below allows for commands and messages to be sent from COMPUTER (serial monitor) -> HC-06 // if (Serial.available()) { // Keep reading from Arduino Serial Monitor // BTSerial.write(Serial.read()); // and send to HC-06 // } // if (BTSerial.available()) { // Keep reading from HC-06 and send to Arduino // Serial.write((BTSerial.read())); // Serial Monitor // } // delay(10); ///////////////////////////////////////////////////////////////////////// }