Writing A Sensor Value In The SD Card Using Arduino

Introduction

 
In this article, we are going to see how to write ultrasonic sensor values on the SD Card using the SD Card module. This is applicable to every SD Card. The text or value is written in .txt file format and the text or value to be read is to be written in the .txt file.
 
The SD Card module follows the commands as per the direction of Arduino UNO. The ultrasonic sensor calculates the distance and this value is written in my file folder on my SD Card. This system will be very useful in writing any  sensor data on the SD Card.
 
Requirements
  1. Arduino UNO (1Nos.)
  2. SD card module(Nos.1)
  3. Connecting wires(few)
  4. Ultrasonic sensor
  5. Arduino Software
  6. SD card
Circuit diagram
 
IoT
  • 10th Pin of Arduino to Trigger of the ultra sonic sensor
  • 9th Pin of Arduino to Echo Pin of the ultrasonic sensor
  • CS pin to 4th pin
  • SCK pin to 13th pin
  • MOSI pin to 12th Pin
  • MISO pin to 11th pin. 
Steps to follow:
 
Step 1
 
Open Arduino following the perfect circuit connection.
 
IoT
 
Step 2
 
Include header file in the coding.
 
IoT
 
Step 3
Initialize the elements which are to be used.
 
IoT
 
Step 4
 
Coding to get the distance from the ultrasonic sensor is given.
 
IoT
 
Step 5
 
Coding to write the required sensor value in the SD card using the SD card Module. Here we create a file name “My file ” and in that we print the sensor value in the .txt format and we close the file.
 
IoT
 
Step 6
 
Compile and upload the code to Arduino UNO. This system follows master and slave method between Arduino and SD card module. The Arduino acts as a master as it is sending commands.
 
IoT
 
Step 7
 
The output or distance will be seen in the Serial Monitor and it is also printed in the SD card module
 

Summary

 
In this article we saw how to work with ultrasonic sensor and SD card module. We saw how to print the ultrasonic sensor value in the SD card by creating and closing the file.