Problem with arduino, bluetooth module and c++

Hello, i have a problem, i have just bough a bluetooth module, HC-05, i was able to connect it to arduino and i have paired it to my pc, but i want to pilot it by the pc with c++, i need to send by c++ a serial data with bluetooth, how can i do? thank you :slight_smile:

arduino code

#include <SoftwareSerial.h> 
SoftwareSerial mySerial(10, 11); 
void setup()
{
  pinMode(2, OUTPUT);
   mySerial.begin(9600); // setto la comunicazione
   delay(1000);
}


void loop()
{
   while (mySerial.available())
   {
       int state= mySerial.read(); // "state" could be the value that i send by c++
       switch(state)
       {
         case '1': // if recieve 1
         {
  digitalWrite(2, HIGH); // turn on rele
            mySerial.println("Relè 1 ON");
           break;
         }
         case '0': // if recieve 0
         {
  digitalWrite(2, LOW); // turn off relè
           mySerial.println("Relè 1 OFF");
           break;
         }    
                      
       }       
   } 
}

i need to send by c++ a serial data with bluetooth, how can i do?

So in C++ make an instance of type SerialPort and call the write method on it.
Something like:

using System.IO.Ports;
....
myserialPort = new SerialPort(COM3,9600);
myserialPort.Open ();
myserialPort.Write("x");//where x  is what you want to send 
....

For more info see this:

Hope it helps

how i can find the number of the serial port of bluetooth in pc? if i go to the property of the bluetooth module it tell
Port_#0006.Hub_#0003 , what com is? thank you:)

What opeartion system are you running?
In windows you could simply go to device manager and see what COM port you have assigned to the bluetooth under COM Ports