Hi everyone,
I'm currently working on a simple project where I use a DC motor (controlled by a H-Bridge) to rotate samples. I want to add a DHT sensor and a SD card reader to the project to monitor temperature and moisture. I thought that would be simple but since I have added these two, I'm unable to rotate the DC motor!
When I remove everything related to the SD card, the motor and temperature reading work fine. (Which I think also proves the wiring of the motor is not at fault). But, if I leave only the parts relative to the SD card and the motor, the motor won't rotate anymore...
List of used material: Arduino Uno ; 12V DC motor ; DHT22 sensor ; DFRobot MicroSD module; H-Bridge
Here is the simple piece of code I use:
#include <SD.h>
// SD card:
const int SDCARD = 4;
// Motor:
const int MOTOR_SPEED = 10;
const int MOTOR_DIR1 = 11; // direction 1
const int MOTOR_DIR2 = 12; // direction 2
/////////////////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode(MOTOR_SPEED, OUTPUT);
pinMode(MOTOR_DIR2, OUTPUT);
pinMode(MOTOR_DIR1, OUTPUT);
// SD card initialization (copy-pasted from some tutorial: https://www.arduino.cc/en/Tutorial/Datalogger):
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(SDCARD)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}
/////////////////////////////////////////////
void loop() {
digitalWrite(MOTOR_SPEED, HIGH);
digitalWrite(MOTOR_DIR1, HIGH);
digitalWrite(MOTOR_DIR2, LOW);
Serial.println("reading main loop now...");
}
The serial monitor returns the following:
Initializing SD card...card initialized.
reading main loop now...
reading main loop now...
[...]
But the motor does not rotate... If I ever comment the piece of code initializing the SD card, the motor rotates.
I can't understand what's going on. If someone has any idea, it would be much appreciated.
Thanks!
EDIT: Forgot to mention that the SD is connected via the ICSP pins (except for the SS one on digital 4)
SOLUTION: The error was that the ISCP-1 and ISCP-4 (which I used to wire the SD card reader) actually correspond to digital 12 and 11 respectively (which I used to wire the motor).