I need help with reading data from two analog sensors, Logging to SD Card

Hi all, I am doing a project in which i am trying to read two analog sensors, time stamp the data and log the data onto Adafruit data logging shield with SD card connected to Arduino Uno.

I am having a hell of trouble with it. I have followed the examples on here where it shows how to read three sensors but to no avail. Any help will be very much appreciated,

Many thanks in advance

here is my code;

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

void setup () {
#ifdef AVR
 Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due

 if (! rtc.isrunning()) {
   Serial.println("RTC is NOT running!");


void loop () {
   DateTime now = rtc.now();
   Serial.print(now.year(), DEC);
   Serial.print(now.month(), DEC);
   Serial.print(now.day(), DEC);
   Serial.print(' ');
   Serial.print(now.hour(), DEC);
   Serial.print(now.minute(), DEC);
   Serial.print(now.second(), DEC);
 // the pins on which i connected the sensors
 int analogValue2 = analogRead(A2);
 int analogValue3 = analogRead(A3);
// Specifying which sensor is which and calculating the maximum output voltage it should produce 

                   float Tvoltage2 = analogValue2 * (5.0/1023.0);
                   float Dvoltage3 = analogValue3 * (5.0/1023.0);

  //Printing a text and the Raw voltage value of temperature sensor to the serial monitor

  Serial.println(" ***** Temperature *****"); 
  Serial.print(Tvoltage2); Serial.println(" volts =");  // now print out the temperature
 //converting from 10 mv per degree with 500 mV offset to degrees ((voltage - 500mV)
  float temperatureC = ((Tvoltage2-0.5)/0.01);  
  Serial.print(temperatureC); Serial.println(" degrees C");   Serial.println(); 
  // these line print to the serial monitor photocell readings in volt
  Serial.println(" ***** Photodiode *****"); Serial.print(Dvoltage3); Serial.println(" volts ");


You need to learn how to put your code in its own window as seen in other posts. This can be done by placing     [code] and [/code]  around the code. This makes it easier for others to read.

Break your problem down to small sections.

Read one sensor and print the analogue reading. Then do your calculation and print the result.

You need to confirm what is happening at each point in your program. If you are not getting the result you expect, you only have a small section of code to fix.

Once you have the first sensor working on its own, you then have the code for the second sensor as well and it can be added.



I do get the results i am expecting when i run the code, the problem i have here is i don't know how to log the results onto an SD Card.

Thanks for showing me how to put my code into a separate window.

my question still remains unanswered any help will be appreciated.

I would start by using the SD library which comes packaged with the Arduino IDE. You will include it in your sketch along with the Wire library and RTClib. There are examples given in the IDE under file->examples->SD. When you get some familiarity with that, I would download the SdFat library and work with that.