Update

One new tab added. Open in browser view if it is not visible. (25/08/2022 08:48)

Bluetooth Module HC 05 + 8051

HC-05 is a Bluetooth device used for wireless communication. It works on serial communication (UART). It is a 6 pin module.







1) Bluetooth.h


// TRANSMIT DATA FROM 8051 TO MOBILE
// AND FROM MOBILE CONTROL LED ON 8051
// USING BLUETOOTH MODULE HC-05
#include<reg51.h>
void bt_init()
{
SCON=0x50;
TMOD=0x20;
TH1=0xFD;// 9600 BR
TR1=1; 

}
void bt_tx(char a)
{
SBUF=a;
while(TI==0);
TI=0;
}
void bt_rx()
{
while(RI==0);
RI=0;
return SBUF;
}


2) Ledcontrol.c

#include "bluetooth.h"
//CONTROL LED USING BT
sbit led=P2^0;
void main()
{
led=1;
bt_init();
while(1)
{
if(bt_rx()=='a') led=0;
if(bt_rx()=='b') led=1;
}
}

No comments: