Hi guys,
I want to make a data logger. i am using 8 probe sensors.
The problem is when i connect 8 sensors and while the operation i disconnect one of them the Arduino still working and give a value for it!.
Also if any problem happen to one of them ( water leakage inside a sensor) all reads become -127 why is that?
i connect all sensors to one digital pin. and this is my code.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SD.h>
#include <SPI.h>
#include <DS1302.h>// RST,DAT,CLK
DS1302 rtc(31, 30, 33 );
File myFile;
int pinCS = 53; // Pin 10 on Arduino Uno// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 10// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);int deviceCount = 0;
float tempC;void setup(void)
{
sensors.begin(); // Start up the library
Serial.begin(9600);if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return; }
rtc.halt(false);
rtc.writeProtect(false);
pinMode(pinCS, OUTPUT);
// SD Card InitializationSerial.print("Locating devices...");
Serial.print("Found ");
deviceCount = sensors.getDeviceCount();
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
sensors.requestTemperatures();
rtc.setTime(2, 36, 00); // Set the time to 12:00:00 (24hr format)
rtc.setDate(22, 12, 2020); // Set the date to August 6th, 2010
}
void loop(void)
{// Send command to all the sensors for temperature conversion
for (int j=0; j<1; j++){
Serial.print(rtc.getDateStr());
Serial.print(",");
Serial.print(rtc.getTimeStr());
Serial.print(",");
if (SD.begin())
{
myFile = SD.open("TestT9.txt", FILE_WRITE);
if (myFile) {
myFile.println(" ");
myFile.print(rtc.getDateStr());
myFile.print(",");
myFile.print(rtc.getTimeStr());
myFile.print(",");
myFile.close(); // close the file
}
else {
Serial.println("error opening test.txt");
}
} else
{
Serial.println("SD card initialization failed");
return; }
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
tempC = sensors.getTempCByIndex(i);
Serial.print(tempC);
Serial.print(" , ");if (SD.begin())
{
myFile = SD.open("TestT9.txt", FILE_WRITE);
if (myFile) {
myFile.print(tempC);
myFile.print(",");
myFile.close(); // close the file
}
else {
Serial.println("error opening test.txt");
}
} else
{
Serial.println("SD card initialization failed");
return; }
}
delay(5000);
}
Serial.println("");
}