1
\$\begingroup\$

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);
}
\$\endgroup\$
1
  • \$\begingroup\$ It appears the SD initialization routine is not returning. Usually there is a time delay involved, and that may not be working right. What sort of test did you to individually test the read and write? Can you post the code from that test? \$\endgroup\$ Commented Aug 13, 2012 at 3:48

1 Answer 1

2
\$\begingroup\$

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).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.