I need to work with SD card and TCRT5000 sensor
(Reflective Optical Sensor with Transistor Output) and save data from sensor to file. So I select Arduino Uno
and added to it a SD card shield(from LC STUDIO) and a TCRT5000 sensor
but it isn't working.
My circuit and code is here:
#include <SPI.h>
#include <SD.h>
const int chipSelect = 10;
void setup() {
Serial.begin(9600);
pinMode(chipSelect, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
while(true);
}
Serial.println("card initialized.");
File dataFile = SD.open("test.txt", FILE_WRITE);
dataFile.close();
dataFile = SD.open("test.txt", FILE_WRITE);
if(dataFile){
dataFile.println("Start:");
}else{
Serial.println("Error in creating file.");
while(true);
}
}
void loop() {
float value = analogRead(A3);
File dataFile = SD.open("test.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(value);
Serial.println(value);
dataFile.close();
}else{
Serial.println("Error in opening file.");
}
delay(5);
}
When TCRT5000
isn't connected SD card working without any problem.
I think it is related to current and supply current. Any idea?
TCRT5000
from circuit without any change in wiring?