Ex 8

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Experiment: 8

TO INTERFACE BLUETOOTH WITH ARDUINO / RASPBERRY PI AND WRITE A


PROGRAM TO TURN LED ON/OFF WHEN ‘1’/’0’ IS RECEIVED FROM SMART PHONE
USING BLUETOOTH.

Aim:

To interface Bluetooth with Arduino / Raspberry Pi and write a program to send sensor data
to smart phone using Bluetooth.
Apparatus:
o Arduino Uno board
o Arduino cable
o LED
o HC-05 Bluetooth Module
o Jumper cables
o Smart phone
Description:
o HC-05 is a Bluetooth module which is designed for wireless communication. This module
can be used in a master or slave configuration.
Pin Description

Bluetooth serial modules allow all serial enabled devices to communicate with each
other using Bluetooth.
It has 6 pins,
1. Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN
pin is set to high, then this module will work in command mode. Otherwise by
default it is in data mode. The default baud rate of HC-05 in command mode is
38400bps and 9600 in data mode.
HC-05 module has two modes,
1. Data mode: Exchange of data between devices.
2. Command mode: It uses AT commands which are used to change setting of HC-
05. To send these commands to module serial (USART) port is used.
2. VCC: Connect 5 V or 3.3 V to this Pin.
3. GND: Ground Pin of module.
4. XD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted
out serially on TXD pin)
5. RXD: Receive data serially (received data will be transmitted wirelessly by
Bluetooth module).
6. State: It tells whether module is connected or not.
 HC-05 module Information
HC-05 has red LED which indicates connection status, whether the Bluetooth is
connected or not. Before connecting to HC-05 module this red LED blinks continuously in
a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows
down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as
well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has
3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift
transmit level of HC-05 module. But we need to shift the transmit voltage level from
microcontroller to RX of HC-05 module.
Circuit Diagram:
Program:

char input_data;
String inputString="";

void setup() // run once, when the sketch starts


{
Serial.begin(9600); // set the baud rate to 9600, same should be of your Serial Monitor
pinMode(13, OUTPUT);
}

void loop()
{
if(Serial.available()){
while(Serial.available())
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ input_data = Serial.read() ; } // clear the serial buffer
if(inputString == "a"){ //in case of 'a' turn the LED on
digitalWrite(13, HIGH);
}else if(inputString == "b"){ //incase of 'b' turn the LED off
digitalWrite(13, LOW);
}
inputString = "";
}
} Procedure:

1. Connect the Circuit carefully as per Circuit Diagram.


2. Open the Arduino Software.
3. Search for “Adafruit_SSD1306” on the Search box and install the Adafruit_SSD1306
library from Adafruit.
4. After installing the Adafruit_SSD1306 library from Adafruit, type “GFX” in the search
box, Scroll down to find the library by Adafruit and install it.
5. After installing the libraries, restart your Arduino IDE.
6. Click new file & type program as per manual.
7. Save the program and after dump the program in Arduino kit by using the cable.
8. Install Arduino Bluetooth controller app in smart phone.
9. Pair with the Bluetooth.
10. Goto switch mode.
11. Setup the switch with your own “On” “Off” commands.
12. Check the Arduino outputs.
Result:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy