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 is designed to capture voltage data from a piezo sensor and log this data to a file on an SD card. The piezo sensor is interfaced with an Arduino Nano microcontroller, which reads the sensor's voltage and writes the data to the SD card using a Micro SD Card Module. The data logging occurs at a rate of 10 samples per second. The Arduino Nano communicates with the SD card module via the SPI (Serial Peripheral Interface) 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 reads voltage data from a piezo sensor connected to A0
 * and stores the data in a file on an SD card. The SD card module is connected
 * to the Arduino Nano via SPI interface. The Arduino reads the piezo sensor
 * voltage 10 times per second and logs the data to the SD card.
 */

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

const int piezoPin = A0; // Pin connected to the piezo sensor
const int chipSelect = A6; // Pin connected to the SD card module's CS pin

File dataFile;

void setup() {
  Serial.begin(9600);
  pinMode(piezoPin, INPUT);
  if (!SD.begin(chipSelect)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialized.");
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (!dataFile) {
    Serial.println("Error opening datalog.txt");
  }
}

void loop() {
  int sensorValue = analogRead(piezoPin);
  if (dataFile) {
    dataFile.println(sensorValue);
    dataFile.flush();
  } else {
    Serial.println("Error writing to datalog.txt");
  }
  delay(100); // Delay for 100 milliseconds (10 readings per second)
}

The code is written for an Arduino Nano and is responsible for initializing the SD card, reading the voltage from the piezo sensor, and logging the data to a file named "datalog.txt" on the SD card. The setup() function initializes the serial communication, sets up the piezo sensor pin as an input, and prepares the SD card for data logging. The loop() function reads the sensor value and writes it to the SD card every 100 milliseconds.