Info

GarageBox.Org adalah laman teknologi dan perkara yang kami minati yang disampaikan mengikut perspektif kami sendiri dalam Bahasa Melayu. Jika ada idea baru yang masih belum diterbitkan di internet, kami akan sampaikannya dalam Bahasa Inggeris. Sebarang pertanyaan dan permintaan, sila hubungi kami di webmaster[a]garagebox.org .


 

GarageBox.Org is a website about technology and anything we like to do according to our perspective in Malay. If we have a new idea that still not publish in the internet, we will publish it in English. Any inquiry & request, please email us at webmaster[a]garagebox.org .

Temperature & Humidity monitor. PDF Print E-mail
Written by Mr Garage   
Tuesday, 21 February 2012 22:52

 

I have designed and wrote a program to monitor temperature and humidity 2 months ago. It took me another a month to publish it. Why? Because I can not find any suitable circuit sketch for Arduino. And lazy. Hehhe.

So, what I can give to the other people about my latest project is only in short description. Any problem/questions, just ask me in comment down below using Facebook.

Objective: Build a system using Arduino to monitor temperature and humidity and save it in memory card.

 

 

Part:

 

1.Arduino (whatever you have. Mine, not the latest one).

2.Arduino RTC (real time clock) v1.1. To read date/time.

3.Humidity & temperature sensor DHT11

4.SD card reader/write from LC studio, www.lcsoft.net

5.SD card

6.Some wire jumpers, if needed. I need a lot of them.

 

 

Design:

Just view it from here.

Program?

#include <SD.h>
#include "RTClib.h"
#include <Wire.h>
#include <string.h>
#include <dht11.h>
#include <stdlib.h>
RTC_DS1307 RTC;
int delaytime= 3000;
dht11 DHT11;
#define DHT11PIN 2
File myFile;
void setup()
{
  Serial.begin(9600);
  Wire.begin(); //Important for RTClib.h
  RTC.begin();
  
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // RTC.adjust(DateTime(__DATE__, __TIME__));
    return;
  }
  
 Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(10, OUTPUT);
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

void loop()
{
  openFile();
  writeFile();
  closeFile();
  delay(delaytime);
}
void openFile(){
  char filename[] = "00000000.CSV";
  DateTime now = RTC.now();
  filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
  filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
  filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
  filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
  filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
  filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
  filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
  filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()
  
  //Check file name exist?
  if (SD.exists(filename)) {
    Serial.println("exists.");
    myFile = SD.open(filename, FILE_WRITE);
  }
  else {
    Serial.println("doesn't exist.");
    Serial.println("Creating new file");
    myFile = SD.open(filename, FILE_WRITE); 
  }
}
void writeFile(){
  DateTime now = RTC.now();
  myFile.print(now.year(),DEC);
  myFile.print("/");
  myFile.print(now.month(),DEC);
  myFile.print("/");
  myFile.print(now.day(),DEC);
  myFile.print(" ");
  myFile.print(now.hour(),DEC);
  myFile.print(":");
  myFile.print(now.minute(),DEC);
  myFile.print(":");
  myFile.print(now.second(),DEC);
  myFile.print(",");
  DHT11.read(DHT11PIN);
  myFile.print((float)DHT11.temperature, 2);
  Serial.println((float)DHT11.temperature, 2);
  myFile.println((float)DHT11.humidity, 2);
  Serial.println((float)DHT11.humidity, 2);
}
void closeFile(){
    myFile.close(); 
}

 

 

The output in SD card must Date/Time; Temperature ; Humidity.

Last Updated on Tuesday, 21 February 2012 23:12
 
You may send a trackback for this article by using the following Trackback link
Trackbacks provided by Trackback for Joomla




 
Twitter Digg Delicious Stumbleupon 

Custom Search