0% found this document useful (0 votes)
17 views

Devans Iot p-7

Uploaded by

devanshpatel0144
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Devans Iot p-7

Uploaded by

devanshpatel0144
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Enrollment No : 211240107034 Computer Engineering

Practical – 7

Aim :- To interface Bluetooth with Arduino and write a program to send


sensor data to smart phone using Bluetooth.

➢ Circuit Diagram:-

➢ Code:-

#include <DHT.h>
#include <DHT_U.h>
#include <SoftwareSerial.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE);

Software Serial BTSerial(4, 5);


void setup()
{
String setName = String("AT+NAME=MyBTBee\r\n"); // Setting name as 'MyBTBee'
Serial.begin(9600);
dht.begin();
BTSerial.begin(9600);
BTSerial.print("AT\r\n"); // Check Status delay(500);
while (BTSerial.available())
{

19
Enrollment No : 211240107034 Computer Engineering

Serial.write(BTSerial.read());
}
BTSerial.print(setName); // Send Command to change the name delay(500);
while (BTSerial.available())
{
Serial.write(BTSerial.read());
}
}
void loop()
{
char c;
if (Serial.available())
{
c = Serial.read();
if (c == 't')
readSensor();
}
}
void readSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("\n Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
}

20
Enrollment No : 211240107034 Computer Engineering

➢ Output:-

21

You might also like