0% found this document useful (0 votes)
30 views6 pages

Iot 9

The document describes an experiment using an Arduino, Bluetooth module, LEDs, and app to control actuators in real-time. The components, code, and steps to pair the Bluetooth module with an iPhone or Android device are outlined. The code establishes Bluetooth communication and uses input strings to control three LEDs by turning them on or off based on input from the paired device.

Uploaded by

Rishabh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views6 pages

Iot 9

The document describes an experiment using an Arduino, Bluetooth module, LEDs, and app to control actuators in real-time. The components, code, and steps to pair the Bluetooth module with an iPhone or Android device are outlined. The code establishes Bluetooth communication and uses input strings to control three LEDs by turning them on or off based on input from the paired device.

Uploaded by

Rishabh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment 9

Student Name: Rishabh kumar UID: 20Bcs7781


Branch: CSE Section/Group: 20BCS_DM-604-B
Semester: 6th Date of Performance:09/05/2023
Subject Name: IOT LAB Subject Code: 20CSP 358

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

Apps and platforms:


1 Arduino IDE
1 MIT App Inventor

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

}</p><p style="margin-left: 20px;"> //if it ends with "/#" it is the


end of the command</p><p> if(inputString.endsWith("/#")){
inputString = inputString.substring(0,inputString.length()-2); //get
rid of the "/#" at the end

for(int i=0;i<inputString.length();i++){ //split to get id and


state</p><p> if(inputString.charAt(i)==','){
buttonId = inputString.substring(0,i); //get the id of the
button</p><p style="margin-left: 20px;"> //get the state of the button
,if its 0 switch it off and if its 1 turn it on</p><p style="margin-left:
20px;"> buttonState = inputString.substring(i+1).toInt();
}

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:

You might also like