According to the writings I took from sonoku.com, Logging data (logging data) is an automated process of collecting and recording data from sensors for archiving purposes or analytical purposes. Sensors are used to convert physical quantities into electrical signals that can be measured automatically and eventually delivered to a computer or microprocessor for processing.
In this project, the Arduino UNO will read the temperature with 2 LM35 sensors and the result of the readings will be displayed to the LCD and stored in the SD card. The type of sensor used is LM35 with a temperature range of 0 ° C - 100 ° C. In order for stored data to know the time and date it is required RTC module (Real Time Clock). In the SD card itself, the sensor readings are stored in a text file (* .txt). As for reading data on SD card simply press Button 1 automatically Arduino read the contents of SD Card (text file) then the data is sent serially. LCD is used to display the process so it is easier to monitor whether the tool is not.
Hardware Requirement
- Arduino Uno Board
- 2 Pieces of LM35 Temperature Sensor
- LCD 16*2
- PC / Laptop
- RTC DS1307 Module
- Push Button
- SD Card
- SD Card Module for Arduino
- Power supply +5 Volt
- Jumper
Block Diagram
Schematic
Arduino - LCD Wiring
Arduino - SD Card Adapter / Module Wiring
Arduino - LM35 Wiring
Arduino - RTC Wiring
Source Code/Sketch
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#define DS1307_ADDRESS 0x68
byte zero = 0x00;
File myFile;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int adc;
int suhu1, suhu2;
int waktu;
byte second ,minute,hour, weekDay;
byte monthDay,month,year;
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
Wire.begin();
//===========================CS SD card
pinMode(10, OUTPUT);
//===========================Tombol
pinMode(8, INPUT);
digitalWrite(8, 1);
//===========================Inisialisasi SD card
lcd.clear();
lcd.print(" Inisialisasi");
lcd.setCursor(0,1);
lcd.print(" SD card..");
Serial.println("Inisialisasi SD card..");
delay(1000);
if (!SD.begin(10)) {
lcd.setCursor(0,1);
lcd.print(" SD card Gagal! ");
Serial.print(" SD card Gagal! ");
while(1);
}
lcd.setCursor(0,1);
lcd.print("SD card Berhasil ");
Serial.println("SD card Berhasil ");
delay(2000);
lcd.clear();
}
void loop(){
//========================Baca ADC
adc = analogRead(A0);
suhu1 = (adc*5)/10;
adc = analogRead(A1);
suhu2 = (adc*5)/10;
//========================baca RTC
bacaRTC();
//========================Display LCD
lcd.setCursor(0,0);
lcd.print("S1:");
lcd.print(suhu1);
lcd.print("C S2:");
lcd.print(suhu2);
lcd.print("C ");
lcd.setCursor(0,1);
lcd.print("Jam:");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
lcd.print(" ");
waktu++;
//============================simpan data setelah 10detik
if (waktu==10){
myFile = SD.open("data1.txt", FILE_WRITE);
if (myFile) {
lcd.clear();
lcd.print("Simpan data....");
lcd.setCursor(0,1);
lcd.print("file->data1.txt");
myFile.print("Suhu 1=");
myFile.print(suhu1);
myFile.print("C, Suhu 2=");
myFile.print(suhu2);
myFile.print("C ");
bacaRTC();
myFile.print(monthDay);
myFile.print("/");
myFile.print(month);
myFile.print("/");
myFile.print(year);
myFile.print(" ");
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.println(second);
myFile.close();
}
else {
lcd.clear();
lcd.print("error opening");
lcd.setCursor(0,1);
lcd.print(" data1.txt");
delay(2000);
}
waktu=0;
delay(2000);
lcd.clear();
}
//=========================tombol 1 baca isi file data1.txt
if(digitalRead(8)==0){
myFile = SD.open("data1.txt");
if (myFile) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Send data SD card");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
delay(1000);
}
else {
lcd.clear();
lcd.print("error opening");
lcd.setCursor(0,1);
lcd.print(" data1.txt");
}
delay(500);
}
delay(1000);
}
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}
void bacaRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111);
weekDay = bcdToDec(Wire.read());
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
#include <SD.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#define DS1307_ADDRESS 0x68
byte zero = 0x00;
File myFile;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int adc;
int suhu1, suhu2;
int waktu;
byte second ,minute,hour, weekDay;
byte monthDay,month,year;
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
Wire.begin();
//===========================CS SD card
pinMode(10, OUTPUT);
//===========================Tombol
pinMode(8, INPUT);
digitalWrite(8, 1);
//===========================Inisialisasi SD card
lcd.clear();
lcd.print(" Inisialisasi");
lcd.setCursor(0,1);
lcd.print(" SD card..");
Serial.println("Inisialisasi SD card..");
delay(1000);
if (!SD.begin(10)) {
lcd.setCursor(0,1);
lcd.print(" SD card Gagal! ");
Serial.print(" SD card Gagal! ");
while(1);
}
lcd.setCursor(0,1);
lcd.print("SD card Berhasil ");
Serial.println("SD card Berhasil ");
delay(2000);
lcd.clear();
}
void loop(){
//========================Baca ADC
adc = analogRead(A0);
suhu1 = (adc*5)/10;
adc = analogRead(A1);
suhu2 = (adc*5)/10;
//========================baca RTC
bacaRTC();
//========================Display LCD
lcd.setCursor(0,0);
lcd.print("S1:");
lcd.print(suhu1);
lcd.print("C S2:");
lcd.print(suhu2);
lcd.print("C ");
lcd.setCursor(0,1);
lcd.print("Jam:");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
lcd.print(" ");
waktu++;
//============================simpan data setelah 10detik
if (waktu==10){
myFile = SD.open("data1.txt", FILE_WRITE);
if (myFile) {
lcd.clear();
lcd.print("Simpan data....");
lcd.setCursor(0,1);
lcd.print("file->data1.txt");
myFile.print("Suhu 1=");
myFile.print(suhu1);
myFile.print("C, Suhu 2=");
myFile.print(suhu2);
myFile.print("C ");
bacaRTC();
myFile.print(monthDay);
myFile.print("/");
myFile.print(month);
myFile.print("/");
myFile.print(year);
myFile.print(" ");
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.println(second);
myFile.close();
}
else {
lcd.clear();
lcd.print("error opening");
lcd.setCursor(0,1);
lcd.print(" data1.txt");
delay(2000);
}
waktu=0;
delay(2000);
lcd.clear();
}
//=========================tombol 1 baca isi file data1.txt
if(digitalRead(8)==0){
myFile = SD.open("data1.txt");
if (myFile) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Send data SD card");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
delay(1000);
}
else {
lcd.clear();
lcd.print("error opening");
lcd.setCursor(0,1);
lcd.print(" data1.txt");
}
delay(500);
}
delay(1000);
}
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}
void bacaRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111);
weekDay = bcdToDec(Wire.read());
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
How it Works
1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.
3. Add some library if needed
4. Compile and upload the script program above to your arduino.5. First initial LCD display, it show if the SD Card connected or not
6. If SD Card is connected succesfully
8. The temperature value and real time clock will show simultaneosly
9. Each 5 second it will upload the value data of temperature into the SD Card which also equpped
with real time data
10. To read the data from arduino immediately, just press the button.
11. To read the log of data, just open the SD Card from your laptop. The data will be indicated with name : DATA1.txt,, so you can open it with notepad apps on your device.
**Suhu (In Indonesian Lang) --> Temperature
Video untuk Project II - 8. Data Logger of 2 Temperature Sensor based On Arduino
Required file
No comments:
Post a Comment