Arduino - Write Variable to SD Card
In this tutorial, we are going to learn how to write variable to Micro SD Card with Arduino. In detail, we will learn:
- Arduino - How to write a string variable to Micro SD Card
- Arduino - How to write a int variable to Micro SD Card
- Arduino - How to write a float variable to Micro SD Card
- Arduino - How to write a char array variable to Micro SD Card
- Arduino - How to write a byte array variable to Micro SD Card
- Arduino - How to write variable as key-value to Micro SD Card
To read the key-value from the Micro SD Card and convert it to int, float, string, See Arduino - Read Config from SD Card

Hardware Required
1 | × | Arduino UNO or Genuino UNO | |
1 | × | USB 2.0 cable type A/B | |
1 | × | Micro SD Card | |
1 | × | Micro SD Card Module | |
1 | × | Jumper Wires | |
1 | × | USB 3.0 SD Card Reader | |
1 | × | (Optional) 9V Power Adapter for Arduino |
About Micro SD Card Module
If you do not know about Micro SD Card Module (pinout, how it works, how to program ...), learn about them in the Arduino - Micro SD Card tutorial.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
If you use an Ethernet shield or any shield that has a Micro SD Card Holder, you do not need to use the Micro SD Card Module. You just need to insert the Micro SD Card to the Micro SD Card Holder on the shield.
Arduino - How to write a variable to a file on Micro SD Card
The below code does:
- Write a int variable to Micro SD Card
- Write a float variable to Micro SD Card
- Write a string variable to Micro SD Card
- Write a char array to Micro SD Card
- Write a byte array to Micro SD Card
Quick Steps
- Make sure that the Micro SD Card is formatted FAT16 or FAT32 (Google for it)
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- See the result on Serial Monitor.
- Detach the Micro SD Card from the Micro SD Card module
- Insert the Micro SD Card to an USB SD Card reader
- Connect the USB SD Card reader to the PC
- Open the arduino.txt file on your PC, it looks like below

Arduino - How to write a key-value to a file on Micro SD Card
Quick Steps
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- See the result on Serial Monitor.
- Detach the Micro SD Card from the Micro SD Card module
- Insert the Micro SD Card to an USB SD Card reader
- Connect the USB SD Card reader to the PC
- Open the arduino.txt file on your PC, it looks like below

Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.