Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Based Piezo Sensor Data Logger with SD Card Storage

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Piezo Sensor Data Logger with SD Card Storage

Circuit Documentation

Summary of the Circuit

This circuit integrates a piezo sensor with an Arduino Nano microcontroller and a Micro SD Card Module. The piezo sensor is used to detect vibrations and generate a voltage that is read by the Arduino Nano on its analog input. The Arduino Nano processes the signal and logs the voltage data to a text file on the Micro SD card. The SD card module is interfaced with the Arduino Nano via the SPI protocol.

Component List

Piezo Sensor

Arduino Nano

Micro SD Card Module

Wiring Details

Piezo Sensor

Arduino Nano

Micro SD Card Module

Documented Code

/*
 * This Arduino Sketch initializes an SD card module and logs voltage data
 * from a piezo sensor to a text file on the SD card. The piezo sensor is
 * connected to analog pin A0 of the Arduino Nano, and the SD card module
 * is connected via SPI (pins D10, D11, D12, and D13).
 */

#include <SPI.h>
#include <SD.h>

const int piezoPin = A0; // Piezo sensor connected to A0
const int chipSelect = 10; // SD card module CS pin connected to D10

void setup() {
  Serial.begin(9600);
  pinMode(piezoPin, INPUT);
  if (!SD.begin(chipSelect)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialized.");
}

void loop() {
  int sensorValue = analogRead(piezoPin);
  float voltage = sensorValue * (5.0 / 1023.0);
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.print("Voltage: ");
    dataFile.println(voltage);
    dataFile.close();
    Serial.println("Data written to SD card.");
  } else {
    Serial.println("Error opening datalog.txt");
  }
  delay(1000); // Log data every second
}

Filename: sketch.ino

This code initializes the SD card and sets up the Arduino Nano to read the voltage from the piezo sensor. It then logs this data to a file named "datalog.txt" on the SD card. If the SD card cannot be initialized, an error message is printed to the serial monitor. The data logging occurs every second.