Bluetooth Module
Introduction:
Bluetooth module is a wireless technology standard for exchanging data over short distances from fixed and mobile devices, and building personal area networks (PANs). The range is approximately 10 meters. In this post we will mainly talk about the HC series of bluetooth modules.
Bluetooth serial module is used for converting serial port to Bluetooth. These modules have two modes: master and slaver device. The device named after even number is defined to as slave. But the device named after odd number, users can set the work mode master or slave of the device by AT commands.
There are basically 2 modules which are commonly used: HC 05 and HC 06
- HC-05 is a more capable module that can be set to be either Master or Slave.
- HC-06 is a Slave only device. (It looks physically just like the HC-05).
- These modules run on 3.3V power with 3.3V signal levels, They have no pins and usually solder to a larger board.
- The module has two modes of operation, Command Mode where we can send AT commands to it and Data Mode where it transmits and receives data to another bluetooth module.
Usage:
Bluetooth modules are used to transfer and receive files within a specific range.
Application:
Project for Reference:
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int led1=13;
int led2=12;
int led3=8;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
int ans=mySerial.read(); // returns ASCII values of numbers
if(ans=='1')
{
digitalWrite(led3, LOW);
digitalWrite(led1, HIGH);
}
if(ans=='2')
{digitalWrite(led2, HIGH);
digitalWrite(led1, LOW);
}
if(ans=='3')
{
digitalWrite(led3, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
}
if (Serial.available())
mySerial.write(Serial.read());
}
No comments:
Post a Comment