Devices & Components
Arduino Uno Rev3
DHT11 Temperature & Humidity Sensor (3 pins)
Breadboard (generic)
Through Hole Resistor, 1 kohm
Grove - RTC
HC-05 Bluetooth Module
Through Hole Resistor, 2 kohm
Memory Socket, SD Card
Software & Tools
Arduino IDE
Project description
Code
Bluetooth & SD Temperature and Humidity logger
arduino
1#include <SPI.h> 2#include <SD.h> 3#include <DHT.h> 4#include <RTClib.h> 5#define 6 DHTPIN 2 7#define DHTTYPE DHT11 8DHT dht(DHTPIN, DHTTYPE); 9const int chipSelect 10 = 4; 11#include <SoftwareSerial.h> 12SoftwareSerial SerialBT(9, 10); 13File 14 myFile; 15RTC_DS1307 rtc; 16void setup() { 17 dht.begin(); 18 Serial.begin(9600); 19 20 SerialBT.begin(9600); 21 //SerialBT.println("Bluetooth connection is established"); 22 23 while(!Serial); 24 if(! rtc.begin()) { 25 Serial.println("Couldn't 26 find RTC"); 27 while (1); 28 } 29 else { 30 rtc.adjust(DateTime(F(__DATE__), 31 F(__TIME__))); 32 } 33 if(! rtc.isrunning()) { 34 Serial.println("RTC 35 is NOT running!"); 36 } 37 Serial.print("Initializing SD card..."); 38 39 if(!SD.begin(chipSelect)) { 40 Serial.println("initialization failed!"); 41 42 return; 43 } 44 Serial.println("initialization done."); 45 myFile=SD.open("DATA.txt", 46 FILE_WRITE); 47 if (myFile) { 48 Serial.println("File opened ok"); 49 // 50 print the headings for our data 51 myFile.println("Date,Time,Temperature ºC,Humidity 52 %"); 53 } 54 myFile.close(); 55} 56void loggingTime() { 57 DateTime now 58 = rtc.now(); 59 myFile = SD.open("DATA.txt", FILE_WRITE); 60 if (myFile) { 61 62 myFile.print(now.year(), DEC); 63 myFile.print('/'); 64 myFile.print(now.month(), 65 DEC); 66 myFile.print('/'); 67 myFile.print(now.day(), DEC); 68 myFile.print(','); 69 70 myFile.print(now.hour(), DEC); 71 myFile.print(':'); 72 myFile.print(now.minute(), 73 DEC); 74 myFile.print(':'); 75 myFile.print(now.second(), DEC); 76 myFile.print(","); 77 78 } 79 myFile.close(); 80 delay(1000); 81} 82void logging() { 83 float 84 t = dht.readTemperature(); 85 SerialBT.print(t); 86 Serial.print(t); 87 88 SerialBT.print(","); 89 Serial.print(","); 90 float h = dht.readHumidity(); 91 92 SerialBT.println(h); 93 Serial.println(h); 94 myFile = SD.open("DATA.txt", 95 FILE_WRITE); 96 if (myFile) { 97 myFile.print(t); 98 myFile.print(","); 99 100 myFile.println(h); 101 } 102 myFile.close(); 103} 104void loop() { 105 //loggingTime(); 106 107 logging(); 108 delay(600000); // 600000 = 10 minutes 109}
Bluetooth & SD Temperature and Humidity logger
arduino
1#include <SPI.h> 2#include <SD.h> 3#include <DHT.h> 4#include <RTClib.h> 5#define DHTPIN 2 6#define DHTTYPE DHT11 7DHT dht(DHTPIN, DHTTYPE); 8const int chipSelect = 4; 9#include <SoftwareSerial.h> 10SoftwareSerial SerialBT(9, 10); 11File myFile; 12RTC_DS1307 rtc; 13void setup() { 14 dht.begin(); 15 Serial.begin(9600); 16 SerialBT.begin(9600); 17 //SerialBT.println("Bluetooth connection is established"); 18 while(!Serial); 19 if(! rtc.begin()) { 20 Serial.println("Couldn't find RTC"); 21 while (1); 22 } 23 else { 24 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 25 } 26 if(! rtc.isrunning()) { 27 Serial.println("RTC is NOT running!"); 28 } 29 Serial.print("Initializing SD card..."); 30 if(!SD.begin(chipSelect)) { 31 Serial.println("initialization failed!"); 32 return; 33 } 34 Serial.println("initialization done."); 35 myFile=SD.open("DATA.txt", FILE_WRITE); 36 if (myFile) { 37 Serial.println("File opened ok"); 38 // print the headings for our data 39 myFile.println("Date,Time,Temperature ºC,Humidity %"); 40 } 41 myFile.close(); 42} 43void loggingTime() { 44 DateTime now = rtc.now(); 45 myFile = SD.open("DATA.txt", FILE_WRITE); 46 if (myFile) { 47 myFile.print(now.year(), DEC); 48 myFile.print('/'); 49 myFile.print(now.month(), DEC); 50 myFile.print('/'); 51 myFile.print(now.day(), DEC); 52 myFile.print(','); 53 myFile.print(now.hour(), DEC); 54 myFile.print(':'); 55 myFile.print(now.minute(), DEC); 56 myFile.print(':'); 57 myFile.print(now.second(), DEC); 58 myFile.print(","); 59 } 60 myFile.close(); 61 delay(1000); 62} 63void logging() { 64 float t = dht.readTemperature(); 65 SerialBT.print(t); 66 Serial.print(t); 67 SerialBT.print(","); 68 Serial.print(","); 69 float h = dht.readHumidity(); 70 SerialBT.println(h); 71 Serial.println(h); 72 myFile = SD.open("DATA.txt", FILE_WRITE); 73 if (myFile) { 74 myFile.print(t); 75 myFile.print(","); 76 myFile.println(h); 77 } 78 myFile.close(); 79} 80void loop() { 81 //loggingTime(); 82 logging(); 83 delay(600000); // 600000 = 10 minutes 84}
Downloadable files
Prototype
Prototype

Data collected
Data collected

Breadboard
Breadboard

Data collected
Data collected

Prototype
Prototype

Breadboard
Breadboard

Schematics
Schematics

Comments
Only logged in users can leave comments