top of page

Real Time Temperature Data Logger with Bluetooth

Updated: Jan 2, 2022


Learn here to create Arduino Based temperature data logger. We’ll use the DHT11 to measure temperature and Humidity, the real time clock (RTC) module to take time stamps and the SD card module to save the temperature, Humidity and Heat index data on the SD card, and Bluetooth send temperature data to HTML Java script Gauge display using android application.


Components required

Arduino Nano - 1 no

Micro SD card Module - 1no

Memory Card 16GB (16GB used in this Project)- 1no

DHT 11 - 1 no

DS1307 RTC I²Cmodule - 1 no

Bluetooth HC-05 - 1 no

Jumper wires


Circuit diagram



Micro SD Card Adapter Module

SD cards or Micro SD cards are widely used in various applications, such as data logging, data visualization, and many more. Micro SD Card Adapter modules make it easier for us to access these SD cards with ease. The Micro SD Card Adapter module is an easy-to-use module with an SPI interface and an on-board 3.3V voltage regulator to provide proper supply to the SD card.



The diagram shows the detail connections of SD module with Arduino.

  • MOSI (Master Out Slave In) - pin 11

  • MISO (Master In Slave Out) - pin 12

  • SCK (Clock)- pin 13

  • CS (Chip Select) - pin 10

  • GND-GND

  • VCC-5v or 3.3v.

A Micro SD Card adapter module can be easily connected to an arduino. Since the module communicates via the SPI protocol, we need to connect the MISO, MOSI, SCK, and CS of the module to the MCU’s. Along with the SD card holder, the module has a 3.3V voltage regulator, along with a 74LVC125A Level shifter IC. Data Sheet


Bluetooth HC-05 Module

HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth.

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.


HC-05 Default Settings

  • Default Bluetooth Name: “HC-05”

  • Default Password: 1234 or 0000

  • Default Communication: Slave

  • Default Mode: Data Mode

  • Data Mode Baud Rate: 9600

DHT 11

DHT11 digital temperature and humidity sensor is a calibrated digital signal output of the temperature and humidity combined sensor. It uses a dedicated digital modules capture technology and the temperature and humidity sensor technology to ensure that products with high reliability and excellent long-term stability. Sensor includes a resistive element and a sense of wet NTC temperature measurement devices, and with a high-performance 8-bit micro controller connected. Data Sheet


DHT11 Specifications:

  • Operating Voltage: 3.5V to 5.5V

  • Operating current: 0.3mA (measuring) 60uA (standby)

  • Output: Serial data

  • Temperature Range: 0°C to 50°C

  • Humidity Range: 20% to 90%

  • Resolution: Temperature and Humidity both are 16-bit

  • Accuracy: ±1°C and ±1%

DHT11 Equivalent Temperature Sensors:

DHT22, AM2302, SHT71


DS1307 RTC Module


DS1307 Module is a real-time clock module with 32kHz and has an onboard battery backup. This module provides seconds, minutes, hours, date, week and year with leap-year compensation up to 2100. It is a small size module that’s why it is easy to plug in even on a breadboard. It has the functionality to set in 24 hours and 12 hours. It is a real time clock module so after removing the power also it sore the real-time and whenever power is given, it starts with real time. Module is compatible with microprocessors and Arduino. Data Sheet


Pin Connection to Arduino.

  • SCL – analog pin5

  • SDA – analog pin4

  • Vcc - +5V

  • Gnd - Gnd

Code

To Update the RTC time adjusment using the following the code in Void setup. Unslash the "set DS3231time (x,x,x,x,x,x,x)

// set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,42,21,4,15,12,21);
  

Example:

setDS3231time(30,42,21,4,15,12,21);

30 - Seconds

42- Minute

21- Hours

4-Wednesday

15-date

12-Month

21-Year.


Arduino Nano

The Arduino Nano is another popular Arduino development board very much similar to the Arduino UNO. They use the same Processor (Atmega328p) and hence they both can share the

same program. Data Sheet


Powering you Arduino Nano:

There are total three ways by which you can power your Nano.

USB Jack: Connect the mini USB jack to a phone charger or computer through a cable and it will draw power required for the board to function

Vin Pin: The Vin pin can be supplied with an unregulated 6-12V to power the board. The on-board voltage regulator regulates it to +5V.

+5V Pin: If you have a regulated +5V supply then you can directly provide this o the +5V pin of the Arduino.


Input/output:

There are total 14 digital Pins and 8 Analog pins on your Nano board. The digital pins can be used to interface sensors by using them as input pins or drive loads by using them as output pins. A simple function like pinMode() and digitalWrite() can be used to control their operation. The operating voltage is 0V and 5V for digital pins. The analog pins can measure analog voltage from 0V to 5V using any of the 8 Analog pins using a simple function like analogRead().

These pins apart from serving their purpose, can also be used for special purposes, which are discussed below:

  • Serial Pins 0 (Rx) and 1 (Tx): Rx and Tx pins are used to receive and transmit TTL serial data. They are connected with the corresponding ATmega328P USB to TTL serial chip.

  • External Interrupt Pins 2 and 3: These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value.

  • PWM Pins 3, 5, 6, 9 and 11: These pins provide an 8-bit PWM output by using analogWrite() function.

  • SPI Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): These pins are used for SPI communication.

  • In-built LED Pin 13: This pin is connected with a built-in LED. When pin 13 is HIGH – LED is on and when pin 13 is LOW, it is off.

  • I2C A4 (SDA) and A5 (SCA): Used for IIC communication using Wire library.

  • AREF: Used to provide reference voltage for analog inputs with analogReference() function.

  • Reset Pin: Making this pin LOW, resets the micro controller.


Installing adafruit Library

To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries.


DHT11: you need to Download and install the DHT11 library.

DS1307: you need to Download and install the RTC library.

Adafruit Unified Sensor Download and install the sensor library.

Adafruit BusIO Download and install the signal library.


After installing the required libraries, copy the following code to your Arduino IDE.



Arduino Code

/*

SD card test


This example shows how use the utility libraries on which the'

SD library is based in order to get info about your SD card.

Very useful for testing a card when you're not sure whether its working or not.


The circuit:

SD card attached to SPI bus as follows:

** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila

** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila

** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila

** CS - depends on your SD card shield or module.

Pin 10 used here for consistency with other Arduino examples


*/

// include the SD library:


#include <SPI.h> // Include SPI library (needed for the SD card)

#include <SD.h> // Include SD library

#include <RTClib.h> // for the RTC


File dataFile;



// REQUIRES the following Arduino libraries:

// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor


#include "DHT.h"


#define DHTPIN 2 // Digital pin connected to the DHT sensor

// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --

// Pin 15 can work but DHT must be disconnected during program upload.


// Uncomment whatever type you're using!

#define DHTTYPE DHT11 // DHT 11

//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

//#define DHTTYPE DHT21 // DHT 21 (AM2301)


// Connect pin 1 (on the left) of the sensor to +5V

// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1

// to 3.3V instead of 5V!

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)

// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)

// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor


// Initialize DHT sensor.

// Note that older versions of this library took an optional third parameter to

// tweak the timings for faster processors. This parameter is no longer needed

// as the current DHT reading algorithm adjusts itself to work on faster procs.

DHT dht(DHTPIN, DHTTYPE);

// Real Time Clock

RTC_DS1307 rtc;


void setup() {

Serial.begin(9600);

// set the initial time here:

// DS3231 seconds, minutes, hours, day, date, month, year

// setDS3231time(30,42,21,4,15,12,21);


Serial.println(F("DHTxx test!"));

dht.begin();


// setup for the RTC

while(!Serial); // for Leonardo/Micro/Zero

if(! rtc.begin()) {

Serial.println("Couldn't find RTC");

while (1);

}

else {

// following line sets the RTC to the date & time this sketch was compiled

rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

}

if(! rtc.isrunning()) {

Serial.println("RTC is NOT running!");

}

while (!Serial); // wait for serial port to connect. Needed for native USB port only

Serial.print("Initializing SD card...");

if (!SD.begin()) {

Serial.println("initialization failed!");

while (1);

}

Serial.println("initialization done.");

delay(2000);

}



void loop() {

// Wait a few seconds between measurements.

delay(2000);


// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

float h = dht.readHumidity();

// Read temperature as Celsius (the default)

float t = dht.readTemperature();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);


// Check if any reads failed and exit early (to try again).

if (isnan(h) || isnan(t) || isnan(f)) {

Serial.println(F("Failed to read from DHT sensor!"));

return;

}


// Compute heat index in Fahrenheit (the default)

float hif = dht.computeHeatIndex(f, h);

// Compute heat index in Celsius (isFahreheit = false)

float hic = dht.computeHeatIndex(t, h, false);


dataFile = SD.open("DHT11Log.txt", FILE_WRITE);

DateTime now = rtc.now();


if (dataFile) {


// Serial.print(F("Humidity: "));

Serial.print(h);

Serial.print("|");

// Serial.print(F("% Temperature: "));

Serial.print(t);

Serial.print("|");

// Serial.print(F("°C "));

// Serial.print(f);

// Serial.print(F("°F Heat index: "));

Serial.print(hic);

Serial.print("|");

// Serial.print(F("°C "));

Serial.print(hif);

Serial.print("\n");

delay(15000);

// Serial.println(F("°F"));

// Write data to SD card file (DHT11Log.txt)


dataFile.print(now.year(), DEC);

dataFile.print('/');

dataFile.print(now.month(), DEC);

dataFile.print('/');

dataFile.print(now.day(), DEC);

dataFile.print(',');

dataFile.print(now.hour(), DEC);

dataFile.print(':');

dataFile.print(now.minute(), DEC);

dataFile.print(':');

dataFile.print(now.second(), DEC);

dataFile.print(",");

dataFile.print(F("Humidity: "));

dataFile.print(h);

dataFile.print(F("% Temperature: "));

dataFile.print(t);

dataFile.print(F("°C "));

dataFile.print(f);

dataFile.print(F("°F Heat index: "));

dataFile.print(hic);

dataFile.print(F("°C "));

dataFile.print(hif);

dataFile.println(F("°F"));

dataFile.close();

}


// if the file didn't open, print an error:

else

Serial.println("error opening DHT11Log.txt");

}


Serial Monitor

After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and see the Temerature, Humidity and Heat index vaule in Serial monitor at every 15 second.


SD Card

First Power off the arduino nano and remove SD card from module and connect to the PC using SD card reader. The SD card contains DHT11log.txt file, the txt file have Temperature data with Time stamp.


Android application


First open Mobile application and select Bluetooth image button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234).


Subscribe and Download code.

offline App Download (Gauge work without internet)




MIT BLOCK

MIT app inventor Block image for android application development.

















Amcharts

Here to used amChart Gauge for Temperature and Humididty data visualization.

Refer below demo HTML code for Gauges.


Html code for angular gauge


<!-- Styles -->

<style>

width: 100%;

height: 500px;

}

</style>


<!-- Resources -->

<script src="https://cdn.amcharts.com/lib/5/index.js"></script>

<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>

<script src="https://cdn.amcharts.com/lib/5/radar.js"></script>

<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>


<!-- Chart code -->

<script>

am5.ready(function() {


// Create root element

// https://www.amcharts.com/docs/v5/getting-started/#Root_element

var root = am5.Root.new("chartdiv");


// Set themes

// https://www.amcharts.com/docs/v5/concepts/themes/

root.setThemes([

am5themes_Animated.new(root)

]);


// Create chart

// https://www.amcharts.com/docs/v5/charts/radar-chart/

var chart = root.container.children.push(

am5radar.RadarChart.new(root, {

panX: false,

panY: false,

startAngle: 180,

endAngle: 360

})

);


chart.getNumberFormatter().set("numberFormat", "#'%'");


// Create axis and its renderer

// https://www.amcharts.com/docs/v5/charts/radar-chart/gauge-charts/#Axes

var axisRenderer = am5radar.AxisRendererCircular.new(root, {

innerRadius: -40

});


axisRenderer.grid.template.setAll({

stroke: root.interfaceColors.get("background"),

visible: true,

strokeOpacity: 0.8

});


var xAxis = chart.xAxes.push(

am5xy.ValueAxis.new(root, {

maxDeviation: 0,

min: 0,

max: 100,

strictMinMax: true,

renderer: axisRenderer

})

);


// Add clock hand

// https://www.amcharts.com/docs/v5/charts/radar-chart/gauge-charts/#Clock_hands

var axisDataItem = xAxis.makeDataItem({});


var clockHand = am5radar.ClockHand.new(root, {

pinRadius: 50,

radius: am5.percent(100),

innerRadius: 50,

bottomWidth: 0,

topWidth: 0

});


clockHand.pin.setAll({

fillOpacity: 0,

strokeOpacity: 0.5,

stroke: am5.color(0x000000),

strokeWidth: 1,

strokeDasharray: [2, 2]

});

clockHand.hand.setAll({

fillOpacity: 0,

strokeOpacity: 0.5,

stroke: am5.color(0x000000),

strokeWidth: 0.5

});


var bullet = axisDataItem.set(

"bullet",

am5xy.AxisBullet.new(root, {

sprite: clockHand

})

);


xAxis.createAxisRange(axisDataItem);


var label = chart.radarContainer.children.push(

am5.Label.new(root, {

centerX: am5.percent(50),

textAlign: "center",

centerY: am5.percent(50),

fontSize: "1.5em"

})

);


axisDataItem.set("value", 50);

bullet.get("sprite").on("rotation", function () {

var value = axisDataItem.get("value");

label.set("text", Math.round(value).toString() + "%");

});


setInterval(function () {

var value = Math.round(Math.random() * 100);


axisDataItem.animate({

key: "value",

to: value,

duration: 500,

easing: am5.ease.out(am5.ease.cubic)

});


axisRange0.animate({

key: "endValue",

to: value,

duration: 500,

easing: am5.ease.out(am5.ease.cubic)

});


axisRange1.animate({

key: "value",

to: value,

duration: 500,

easing: am5.ease.out(am5.ease.cubic)

});

}, 2000);


chart.bulletsContainer.set("mask", undefined);


var colorSet = am5.ColorSet.new(root, {});


var axisRange0 = xAxis.createAxisRange(

xAxis.makeDataItem({

above: true,

value: 0,

endValue: 50

})

);


axisRange0.get("axisFill").setAll({

visible: true,

fill: colorSet.getIndex(0)

});


axisRange0.get("label").setAll({

forceHidden: true

});


var axisRange1 = xAxis.createAxisRange(

xAxis.makeDataItem({

above: true,

value: 50,

endValue: 100

})

);


axisRange1.get("axisFill").setAll({

visible: true,

fill: colorSet.getIndex(4)

});


axisRange1.get("label").setAll({

forceHidden: true

});


// Make stuff animate on load

chart.appear(1000, 100);


}); // end am5.ready()

</script>


<!-- HTML -->

<div id="chartdiv"></div>

bottom of page