Arduino Temperature Thing with calibrated cup of tea

Arduino Temperature Thing with calibrated cup of tea

At work we had need for a multiple temperature logging device. Using one of my cheap Chinese Arduino Uno clones, some DS18B20 one wire Waterproof Temperature Transducers (like these ones), a cheap Ethernet / SD card shield (like this), and a DS1307 RTC (Real Time clock) (link).

The DS1307 RTC is connected using SDA and SCL to A4 and A5 on the Arduino, and the DS18B20 Temperature sensors are all connected to A0.

Arduino Temperature Thing schematic

Arduino Temperature Thing schematic

Arduino Temperature Thing with Ethernet Shield and SD card.

Arduino Temperature Thing with Ethernet Shield and SD card.

The Wago 261 connectors are just something we had laying around at work, and to be fair they are quite an awesome way of making semi permanent connections that are easy to take apart.

The S18B20 Temperature sensors have a pull up 4k7 resistor between the Data cables (Yellow) and the 5V line.

If you have the code set up for more Temperature sensors than you have attached, the last sensors value will just be repeated.

There is no way to know which sensor will be which before you power them all up, hence the little flags of paper on each sensors lead (and the calibration cup of tea).

/*
Data logger thing, written in Arduino by Skippy - http://philipmcgaw.co.uk || //skippy.org.uk

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.

updates
2015-03-23 - Initial version.
*/

// Things to Use
// Required for the SD Card
#include <SPI.h>
#include <SD.h>

// required for the RTC
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>                // A basic DS1307 library that returns time as a time_t

// Include the One Wire Sensors parts
#include <OneWire.h>
#include <DallasTemperature.h>

// Variables

int sensorNumber = 4;                    // number of sensors
#define oneWireBus A0                    // Data wire is plugged into A0 on the Arduino
#define LED 13                            // On Board LED
const int chipSelect = 4;                // On the Ethernet Shield, CS is pin 4. Note that even if it's not used as the CS pin, the hardware CS pin (10 on most Arduino boards, 53 on the Mega) must be left as an output or the SD library functions will not work.

int loopNumber = 0;
int sensorTemp = 0;
String dataString = "";
int time;
int date;

// Other Set-up

OneWire oneWire(oneWireBus);            // Set-up a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire);    // Pass our oneWire reference to Dallas Temperature.

// And off we go…

void setup(void)
{
pinMode(LED, OUTPUT);                    // initialize the LED pin as an output.
Serial.begin(9600);                        // start serial port
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
delay(200);

Serial.print(sensorNumber);
Serial.println(" Channel Data Logger");

Serial.print("Initializing SD card…");

pinMode(chipSelect, OUTPUT);            // make sure that the default chip select pin is set to output, even if you don't use it.

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present");    // don't do anything more:
return;
}

Serial.println("card initialized.");
Serial.println("Date&Time,\tSecs,\t1,\t2,\t3,\t4,\t5,\t6,");

sensors.begin();                        // Start up the sensor library
}

void loop(void)
{

digitalWrite(LED, HIGH);                // turn the LED on
tmElements_t tm;                        // grabs the time

if (RTC.read(tm))
{
// Adds the time to the dataString
dataString += (tm.Hour);
dataString += ":";
dataString += (tm.Minute);
dataString += ":";
dataString += (tm.Second);
dataString += ",\t";
}
else
{
if (RTC.chipPresent())
{
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
}
else
{
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}

dataString += (millis()/1000);            // add the seconds elapsed since power-up to the string
dataString += ",\t";

sensors.requestTemperatures();            // request all temperatures on Bus

// read all sensors and append to the string:
for (loopNumber = 0; loopNumber < sensorNumber; loopNumber++)
{
sensorTemp = sensors.getTempCByIndex(loopNumber);
dataString += sensorTemp;
if (loopNumber < sensorNumber)
{
dataString += ",\t";
}
}

digitalWrite(LED, LOW);                 // Turn the LED off

// open the file. NB only one file can be open at a time, so you have to close this one before opening another.
File dataFile = SD.open("datalog.csv", FILE_WRITE);
// if the file is available, write to it:
if (dataFile)
{
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else
{
Serial.println("error opening datalog.csv");
}

dataString = "";                        // empty the string
}