Electronic – arduino – SD Card initialize problem

arduinosd

I use a SainSmart UNO with LCD4884 and HC-SR04 Distance sensor and an Arduino Shield Plus SD (SD-card module with RTC-DS1307) to measure the water level of a well. The calculation and LCD4884 display works well. But as soon as I initialize the SD card, the program does not work. I've also tested the "SD Arduino Shield Plus" individually and the read and write and it works on an SD card without problems. I got a short program, where the same effect occurs when the line "SD.begin" fits. What can be the cause?

#include
const int input = 13;
const int output = 12;
unsigned int duration, inches;

void setup() {
    Serial.begin(9600);
    // SD.begin(10); <- When I use this line paste like this, it does not measure the distance.
}

void loop() {
    pinMode(output, OUTPUT);
    digitalWrite(output, LOW);
    delayMicroseconds(2);
    digitalWrite(output, HIGH);
    delayMicroseconds(5);
    digitalWrite(output, LOW);
    pinMode(input, INPUT);
    duration = pulseIn(input, HIGH);
    inches = duration / 74 / 2;
    Serial.println(inches);
    delay(1000);
}

Best Answer

I believe that the SD card shield is already using pins 12 and 13 for the SPI interface. You won't be able to use both the distance sensor and the SD card on those pins (and even just connecting the two shields as-is could cause problems).