The post is about interfacing Arduino with MatLab via Bluetooth module
1). First of all, connect the Arduino with Bluetooth module as per the diagram given below.
Vcc to 5V
GND to GND
RXD to RX
TXD to TX
2). Now you need to upload code to the Arduino board. The code depends on which values you need to send from Arduino or receive to Arduino through MatLab.
Example code for receiving the values from Arduino is
int a1=0;
int a2=0;
int val=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
a1=analogRead(0);
a2=analogRead(1);
if (Serial.available() >0) {
/* whatever is available from the serial is read here */
val = Serial.read();
{
if(val==10)
{
Serial.println(a1);
}
else
if(val==20)
{
Serial.println(a2);
}
}
}
}
Burn this code to the Arduino board.
3). Then pair your Bluetooth device to the computer.
4). Open MatLab and find your Bluetooth device detected as follow
>> instrhwinfo('Bluetooth')
for more information about your device use this
>> instrhwinfo('Bluetooth','HC-05')
create a Bluetooth variable and open it as follow
>>b = Bluetooth('HC-05',1);
>>fopen(b);
After this for getting the two values regularly from Arduino use this code
>>while(1)
fwrite(b,10);
q=fscanf(b,'%d');
fwrite(b,20);
z=fscanf(b,'%d');
end
yes that's all, you will get regular values from Arduino
Remove infinite while loop if you want these values once
>>fwrite(b,10);
>>q=fscanf(b,'%d');
>>fwrite(b,20);
>>z=fscanf(b,'%d');
You can modify this code or make your own code according to your needs.
***if Bluetooth module is not sending and receiving data from Arduino then exchange the tx,rx connections
RXD to RX --> RX to TX
TXD to TX --> TX to RX
***
Thank you for reading.
Ask if any questions in the comments.
//////////////////////////////////////////////////////////////////
My free android apps.
https://play.google.com/store/apps/developer?id=Gaur+Tavm
Thank you.
1). First of all, connect the Arduino with Bluetooth module as per the diagram given below.
Vcc to 5V
GND to GND
RXD to RX
TXD to TX
2). Now you need to upload code to the Arduino board. The code depends on which values you need to send from Arduino or receive to Arduino through MatLab.
Example code for receiving the values from Arduino is
int a1=0;
int a2=0;
int val=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
a1=analogRead(0);
a2=analogRead(1);
if (Serial.available() >0) {
/* whatever is available from the serial is read here */
val = Serial.read();
{
if(val==10)
{
Serial.println(a1);
}
else
if(val==20)
{
Serial.println(a2);
}
}
}
}
Burn this code to the Arduino board.
3). Then pair your Bluetooth device to the computer.
4). Open MatLab and find your Bluetooth device detected as follow
>> instrhwinfo('Bluetooth')
for more information about your device use this
>> instrhwinfo('Bluetooth','HC-05')
create a Bluetooth variable and open it as follow
>>b = Bluetooth('HC-05',1);
>>fopen(b);
After this for getting the two values regularly from Arduino use this code
>>while(1)
fwrite(b,10);
q=fscanf(b,'%d');
fwrite(b,20);
z=fscanf(b,'%d');
end
yes that's all, you will get regular values from Arduino
Remove infinite while loop if you want these values once
>>fwrite(b,10);
>>q=fscanf(b,'%d');
>>fwrite(b,20);
>>z=fscanf(b,'%d');
You can modify this code or make your own code according to your needs.
***if Bluetooth module is not sending and receiving data from Arduino then exchange the tx,rx connections
RXD to RX --> RX to TX
TXD to TX --> TX to RX
***
Thank you for reading.
Ask if any questions in the comments.
//////////////////////////////////////////////////////////////////
My free android apps.
https://play.google.com/store/apps/developer?id=Gaur+Tavm
Thank you.