Arduino Sensor Connection and Data Export to a smart phone

This is the program that uses the bluetooth module to send over random numbers to the app. I tried combining this code to the program above and doing things like replacing the (float)random 265 to the sensor-value variables, but it just doesn't want to send anything else to the mobile app."

//BLE CODE LINKhttps://www.aranacorp.com/en/arduino-and-bluetooth-module-hc-06/

#include <SoftwareSerial.h>

SoftwareSerial hc06(2,3);

String cmd="";

float sensor_val=0;

void setup(){

//Initialize Serial Monitor

Serial.begin(9600);

//Initialize Bluetooth Serial Port

hc06.begin(9600);

}

void loop(){

//Read data from HC06

while(hc06.available()>0){

cmd+=(char)hc06.read();

}

//Select function with cmd

if(cmd!=""){

Serial.print("Command recieved : ");

Serial.println(cmd);

// We expect ON or OFF from bluetooth

if(cmd=="ON"){

Serial.println("Function is on");

}else if(cmd=="OFF"){

Serial.println("Function is off");

}else{

Serial.println("Function is off by default");

}

cmd=""; //reset cmd

}

// Simulate sensor measurement

sensor_val=(float)random(256); // random number between 0 and 255

//Write sensor data to HC06

hc06.print(sensor_val);

delay(100);

}

This might be what you want to do but probably isn't, so you might like to make up your mind as to what baud rate you really need.

That programme is used for receiving data from HC-06, which is not what I understand your intention to be. Why don't you just connect HC-06 to hardware serial and thereby send to the app the exact same data as you send to the serial monitor, or alternatively, retain the software serial and include

hc-06.println(ladedah);

in the loop. That is just three lines added to the main code - which I assume works, sort of, although I wont guess for how long. All those Strings might eventually give you grief.

HC-06 is not a BLE device.

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