Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect Unity Game with [ Arduino + Bluetooth module (HC‐05) ] Or ESP32

I want to connect my Unity 3D Game with Micro-controller Like Arduino through Bluetooth and for that I'm using a (HC‐05) Bluetooth module.

And for that there is one plugin named Arduino Bluetooth Plugin Link in the asset Store. And Charge is 19$.

Is there any other way to do this by just using free functionality and Coding?

like image 414
Srushti Khunt Avatar asked Jul 20 '20 07:07

Srushti Khunt


People also ask

Why HC-05 Bluetooth module is used?

HC-05 Bluetooth Module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup. Its communication is via serial communication which makes an easy way to interface with controller or PC.

How do I connect Bluetooth in unity?

Head to Edit > Project Settings > Player. In the Inspector, open up the tab Publishing Settings. Under the Capabilities section, make sure that Bluetooth is enabled.


1 Answers

You can definitely do it by coding it yourself.

I can't aid you with the C# part but I've written code to send data over the HC-06 module for arduino and communicated with an Android app via bluetooth and bluetooth low energy.

At the end of the day is very similar to Socket programming.

So for the C# part this user has a basic working C# BT communication example

And for the Arduino side I have used this sketch:


/**************************************************
 * 
 * Using the BUILT-IN Serial.
 * 
 * CONFIGURATION:
 * 
 *          ARDUINO NANO - HC-06
 *    YELLOW     TX         RX
 *    GREEN      RX         TX
 *    RED        3V3        VCC
 *    BLACK      GND        GND
 * 
 **************************************************/
void setup() {
  // Init the Built-In Serial.
  Serial.begin(9600);
}
void loop() {
  // Send the message
  Serial.println("MISSATGE PER UN LINUX!!!");

  delay(2000);
  
}

With this wiring: Wiring

This image of the module may also be useful to you, so you can see the pinout: Pinout HC-06

So after pairing the arduino with my laptop and listening to incomming messages by using the command

$ cat /dev/rfcomm0

I started seeing the output on my console:

Console output

So instead of sending a String you can send whatever you read from your Arduino inputs and then re-parse it on your C# side.

I hope I was helpful; Good luck!!!

like image 136
Some random IT boy Avatar answered Oct 02 '22 02:10

Some random IT boy