--> Project V - 10. Write Data on The SD Card based on Arduino | basic arduino tutorial

Thursday, August 17, 2017

Project V - 10. Write Data on The SD Card based on Arduino

| Thursday, August 17, 2017
Write Data on The SD Card


SD Card or Secure Digital is a memory card format that can store files / data. This time we try to save a text file to SD card using Arduino, file name to be saved is "data1.txt".

Hardware Requirement
  • Arduino Uno Board
  • SD Card
  • Computer / Laptop
  • MicroSD Card Adapter / Module for Arduino
  • LCD 16*2
  • Power supply +5 Volt
  • Jumper

 MicroSD Card Adapter | Source                            SD Card | Source


Block Diagram



Schematic

Arduino - LCD Wiring



Arduino - SD Card Module


Source Code/Sketch

#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>
File myFile;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
lcd.begin(16, 2);
pinMode(10, OUTPUT);
lcd.clear();
lcd.print(" Inisialisasi");
lcd.setCursor(0,1);
lcd.print(" SD card..");
delay(1000);
if (!SD.begin(10)) {
lcd.setCursor(0,1);
lcd.print(" SD card Gagal! ");
delay(2000);
while(1);
}
lcd.setCursor(0,1);
lcd.print("SD card Berhasil ");
delay(2000);
}
void loop() {
//===================Simpan data ke sd Card
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("Test simpan file text pada SD Card");
myFile.close();
delay(2000);
lcd.setCursor(0,1);
lcd.print(" Berhasil... ");
}
else {
lcd.clear();
lcd.print("error buka file");
lcd.setCursor(0,1);
lcd.print(" data1.txt");
}
delay(1000);
while(1);
}

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 



4. If SD Card can be initialized


5. Next program save file with name data1.txt, display on LCD as follows


6. Saving done


7. To see the data, just open the card from your laptop / PC. Use notepad apps to open it.





Video for Project V - 10. Write Data on The SD Card based on Arduino




Required file

Related Posts

No comments:

Post a Comment