Iot 9
Iot 9
Aim: Real Time application of controlling actuators through Bluetooth application using Arduino.
Components Required:
8 Male/Male Jumper Wires 1
HC-05 Bluetooth Module 1
(5 mm) LED: Red
1 Arduino UNO
1 Resistor 1k ohm
CODE:
#include<SoftwareSerial.h>
SoftwareSerial bluetoothSerial(10, 11); // Tx pin of the bluetooth module
must be connected to Rx pin on arduino
// Rx pin of the bluetooth module
must be connected to Tx pin on arduino
const int led1=2;
const int led2=3;
const int led3=4;
String inputString;
String buttonId;
int buttonState=0;
int pinNum=0;
void setup(){
//set the digital pins
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
//start communication with bluetooth module
bluetoothSerial.begin(9600);
//set all pins to off as default to start with
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}
<p>void loop(){<br> if( bluetoothSerial.available()){
while( bluetoothSerial.available()){
char inChar = (char) bluetoothSerial.read(); //read the input
inputString += inChar; //make a string of the characters
coming in serial
inputString = ""; //reset the input data for the next time
}</p><p style="margin-left: 40px;"> //get pin number and then convert the
string to an int</p><p style="margin-left: 60px;"> pinNum =
buttonId.substring(1).toInt();
digitalWrite( pinNum,buttonState);
}</p><p> }</p>
How to pair Arduino Bluetooth Module with iPhone
and Andriod
Step 1: Power the Bluetooth and configure it as a Peripheral role
Step 2: Search LightBlue in the App Store and install it
Step 3: Launch the app, and connect to “HM-13-BLE”
Step 4: Touch on properties and hit “listen for notifications” to enable data receiving
There’s a “Hex” key on the top right under properties to change data format as well
Step 5: Hit “Write new value” and write some words to start sending data to the PC
With the serial terminal, you can transfer data from the PC to iPhone as well: