Temperature and Humidity Data Logger From Arduino to Android Phone With SD Card Module Via Bluetooth

412

10

2

Posted

Introduction: Temperature and Humidity Data Logger From Arduino to Android Phone With SD Card Module Via Bluetooth

Hello All, This is my first Instructable ever, Hope i help the maker community as i have been benefited with it.

Often we use sensors in our projects but finding a way to collect the data, store it and transfer it Phones or other devices immediately and wireless were not a ready made process. This Instructable will guide you through

  • Acquiring Data from Sensor (DHT 11) - temperature and humidity sensor.
  • Storing the acquired data in SD card with SD card module.
  • Transferring the data wireless using Bluetooth to a custom made Android App.
  • Storing the received sensor values as text file (.txt file).

Step 1: Component List

Let's get down to gather the troops to make this awesome project.

  • Arduino Uno (any other arduino also will be suitable)
  • micro SD card module.
  • SD card module (the one i am using is 8 GB, it is advised to use >=32 GB)
  • HC05 - Bluetooth module
  • DHT11 (Temperature and Humidity Sensor)
  • Bunch of jumpers.
  • Android Phone

Step 2: Connections:

Putting together and connecting components is halfway done for the project. The products mentioned are easily available in most retail electronic stores and online sites like Amazon.

Arduino - HC05 connection(Bluetooth):

  • +5V - Vcc
  • Gnd - Gnd
  • Pin 0 - Tx
  • Pin 1 - Rx

Arduino - SDcard module connection:

  • +5V - Vcc
  • Gnd - Gnd
  • Pin 11 - MOSI (Master Out Slave In)
  • Pin 12 - MISO (Master In Slave Out)
  • Pin 13 - SCk (Clock synchronous)
  • Pin 4 - CS (Chip Select)

Arduino - HC05 connection(Bluetooth):

  • +5V - Vcc
  • Gnd - Gnd
  • Pin A0 - Signal

Step 3: Procedure

Connect all the parts as mentioned in the previous step, With this we can write code in the Arduino Ide to reach our goal.

The second part of our project is to have an Android app toreceive the sensor values , display the values and store it in a file in the mobile. I have used Thunkable to make the Android Application and also have provided the apk and aia for it.

Step 4: Arduino Code:

The Arduino Code has been given and explained below.

The arduino code is mostly self explanatory with SD card library and DHT11 library. The bluetooth uses hardware serial which is pin0 and pin1 of the arduino hence bluetooth transfer happens with the Serial print() functions which uses up the I2C protocol and the SD card module uses up the SPI protocol for communicating with it.

/*

* SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN) * *HC 05 module connection: ** TX - pin 0 (default)[can be changed if Softwareserial is being used ] ** RX - pin 1 (default) [can be changed if Softwareserial is being used ]

*/

#include #include #include

File myFile; dht DHT; #define DHT11_PIN A0

void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println("Type,\tStatus,\tHumidity(%),\tTemperature(C)"); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } DHTAcq(); sdCardWrite("test3.txt"); sdCardRead("test3.txt");

}

void DHTAcq() { Serial.println("DHT11, \t"); int chk = DHT.read11(DHT11_PIN); Serial.print(DHT.humidity, 1); Serial.print(",\t"); Serial.print(DHT.temperature, 1); delay(2000); }

void sdCardWrite(String fileNameStr ) { Serial.println("Initializing SD card"); if (!SD.begin(4)) { Serial.println( "Initilization failed."); return; } Serial.println("Initilization done!"); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open(fileNameStr, FILE_WRITE); // if the file opened okay, write to it: if (myFile) { myFile.println("DHT11, \t"); int chk = DHT.read11(DHT11_PIN); myFile.print(DHT.humidity, 1); myFile.print(",\t"); myFile.print(DHT.temperature, 1); myFile.close(); Serial.println("done!"); delay(200); /*Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); // close the file: myFile.close(); Serial.println("done."); */ } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } }

void sdCardRead(String fileName) { // re-open the file for reading: myFile = SD.open(fileName); if (myFile) { Serial.println("test.txt:"); // read from the file until there's nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } }

void loop() { // nothing happens after setup //Serial.println("test 1.. 2.. 3"); //delay(1000); }

Step 5: Android App:

The Android app has been made with Thunkable application with drag and drop programming. It will log the data on to the label on the screen and once the Store Data button is pressed on the location AppInventor/Data with the filename that has been given the code.


The project can be extended to have offline storage of whatever the sensor data we want to by replacing with desired sensor modules and the app can be extended to retrieve the data from the storage and manipulate to suit the application.

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Spotless Contest

      Spotless Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    2 Comments