Memakai Module SD CARD Arduino Untuk Menyimpan Log Data
Super Admin 23-12-2020 3,051 Tutorial
Kali ini mau share bagaimana cara menyimpan log data dari sebuah sensor DS3231 ataupun sensor lainya sesuai selera saja.. :D berikut code nya
Pemasangan module sdcard ke arduino
ARDUINO UNO PIN |
MICROSD CARD MODULE PIN |
GND | GND |
5V | VCC |
12 | MISO |
11 | MOSI |
13 | SCK |
4 | CS |
#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
File myFile;
DS3231 rtc(SDA, SCL);
int pinCS = 10; // Pin 10 on Arduino Uno
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
rtc.begin();
}
void loop() {
Serial.print(rtc.getTimeStr());
Serial.print(",");
Serial.println(int(rtc.getTemp()));
myFile = SD.open("log.txt", FILE_WRITE);
if (myFile) {
myFile.print(rtc.getTimeStr());
myFile.print(",");
myFile.println(int(rtc.getTemp()));
myFile.close(); // close the file
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
delay(3000);
}