HELP! ARDUINO UNO R3 DATA LOGGER SKETCH NOT RUNNING

Hello and a very good day to all..
.
I'm a newbie in this area as i just learned about arduino and its capabilities when i started committing in my thesis.

Here i have an Arduino based temperature data logging assembly for my thesis. The assembly consists of:

SETUP:

1.Arduino UNO R3
2.Seeedstudio Solar Charger shield v2.0
3.TinyRTC i2c Module
4.SD-card breakout
5.19 pcs of DS18B20 waterproof thermal sensors[/li]

The sensors are connected in daisy-chain with cat5e cables spanding over 30m. The pullup resistor that i used were 1.3k. The solar charger shield was stacked on the UNO with RTC and sd-card breakout boards mounted on a breadboard and connected to UNO via jumper cables.

External power i used 6v rechargable battery and a 2w 80x180 solar panel.

PROBLEM:

The sketch that i wrote can be executed through the Serial Terminal with the USB connection. But cannot be executed when in standalone mode (external battery, USB unplug). The PWR LED is on. Been scratching my head for a couple of days now. How to get it running when the USB unplugged?

The code to my sketch:

//Project DataLogger Thesis 
//
// 1)Library Used
//--------------------------------------
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
#include <SD.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//---------------------------------------
// 2)Variable Definitions
//---------------------------------------
#define ONE_WIRE_BUS 3 //one wire interface connection : digital pin 3
#define TEMP_PRE 12 //temperature precision , 9-12 bit
File File1;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Sensors Address Array
DeviceAddress s01 = { 0x28, 0x32, 0x57, 0xCD, 0x05, 0x00, 0x00, 0xC8 };

float tempC, tempF;

//SD Card Init...
void setup()
{
  Serial.println("Initializing the SD Card...");
  if(!SD.begin())
  {
    Serial.println("Initialization FAILED!");
    return;
  }
  Serial.println("Initialization COMPLETE...");
  Serial.begin(9600);
  Serial.println("Type any character to start");
  while (!Serial.available());
  {
    Serial.println();
    sensors.begin();
    Serial.println("Initialising Sensors...\n");
    //set sensor resolutions
    sensors.setResolution(s01, TEMP_PRE);

    delay(100);
  } 
  
}

//Retrieving temperatures from sensors
void getTemperature(DeviceAddress deviceAddress)
{
  sensors.requestTemperatures();
  tempC = sensors.getTempC(deviceAddress);
  tempF = DallasTemperature::toFahrenheit(tempC);
}



void loop()
{
  tmElements_t tm;
  File1 = SD.open("TEMPLOG.csv", FILE_WRITE);
  Serial.println("File Opened.");
  Serial.println();
  if (File1)
  {
      if (RTC.read(tm))
      {
        File1.print(tm.Hour);
        Serial.print(tm.Hour);
        File1.write(':');
        Serial.write(':');
        File1.print(tm.Minute);
        Serial.print(tm.Minute);
        File1.write(':');
        Serial.write(':');
        File1.print(tm.Second);
        Serial.print(tm.Second);
        File1.print(",");
        Serial.print(",");
        File1.print(tm.Day);
        Serial.print(tm.Day);
        File1.write('/');
        Serial.write('/');
        File1.print(tm.Month);
        Serial.print(tm.Month);
        File1.write('/');
        Serial.write('/');
        File1.print(tmYearToCalendar(tm.Year));
        Serial.print(tmYearToCalendar(tm.Year));
        File1.print(",");
        Serial.print(",");
      }
      else
      {
        if (RTC.chipPresent())
        {
          Serial.print(" DS1307 not working ");

        }
        else
        {
          Serial.print("DS1307 read error. check connection");

        }
      }
      
      File1.print(" s01 : ");
      File1.print(',');
      Serial.print(" s01 : ");
      getTemperature(s01);
      File1.print(tempC);
      Serial.print(tempC);
      Serial.print(" C");
      File1.write(',');
      Serial.write(',');

      Serial.println();
      Serial.println("Data written");
  }
  File1.close();
  Serial.println("File closed. \n");
  Serial.println("Safe to disconnect card");
  Serial.println();
  delay(10000);
  Serial.println();
  Serial.println("Card in use, do not disconnect!!");

A COUPLE OF TWEAKS AND TRIALS:

  1. i've tried using different battery such as 3.7v 950mAH LiPo and also 9v LiOn, but both turn out to be the same. still no go on the sketch.
  2. i've commented out the while statement;
Serial.println("Type any character to start");
  //while (!Serial.available());
    Serial.println();
    sensors.begin();
    Serial.println("Initialising Sensors...\n");

..also find my self in dissapointment.
3. i've also tried resetting the UNO by pressing the reset button, but still..no initiation.
Hope to be saved from this mystery and get on with my thesis. Thank you all~ :wink:

Without the serial how do you know it is not working?

Light up a few LEDs to show progress through the code.

Opening a file inside the loop function is a bit odd.

It could be that the input RX pin is picking up interference try a 1K pull up to 5V.

thank you for your quick reply

Without the serial how do you know it is not working?

Light up a few LEDs to show progress through the code.

i observed the yellow LED onboard the UNO..when it is working via the USB, there is blinking when the sensors sent over the temperatures..thats how i knew it work.

try a 1K pull up to 5V

it has been suggested that using pullup lower than 1.2k would damage the sensors,,

No not on the sensors but on the Arduino's RX pin.

The RX and TX LEDs are not controlled by the Arduino but by the USB driver in the computer. They will not flash with the USB disconnected.

Thank you again..

So if i were to use the Rx Tx LEDs as an output during the data logging..i should implement the codes in the sketch for the purpose of lighting up the LED when USB is disconnected?

about the resistor, if i used 1.3k would it worked? where i need to place it? in series on the 5v pin?

If you get a USB-TTL cable (aka an FTDI cable) you can connect a PC directly to the Rx Tx pins without using the onboard USB connection. It would allow you to monitor what is happening without the Arduino knowing :slight_smile: The FTDi cable won't cause the Arduino to reset as long as you only connect Rx Tx and GND.

...R

Thank you for the reply and suggestions..

I found out that the sketch did run after all. You guys were right. The RX/TX led is not controlled after the USB unplugged. since i found out the the sketch is running after plugged out USB (by inserting my SD card to my computer and found out there is data written), the use of FTDI cable is unnecessary..but thanks~

So now, i would like to try controlling it to provide a visual confirmation after the USB have been plugged out.

Do i use the sketch example here:

int ledPin = 13; // LED connected to digital pin 13
int inPin = 7;   // pushbutton connected to digital pin 7
int val = 0;     // variable to store the read value

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
}

void loop()
{
  val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);    // sets the LED to the button's value
}

i want it to light up when the data is written on my SD card..so which is the output pin? my sdcard breakout have pins as follows;
besides the GND and VCC

DO (connected to digital pin 12)
CLK (connected to digital pin 13)
DI (connected to digital pin 11)
CS (connected to digital pin 10)

please advice..thank you~

You can not use the LED on pin13 because that is already being used by the SD card.
You will have to add an LED on another pin. You can not control the TX and RX LEDs from the arduino as there is no connection between them.

Thank you for your reply..

So i need to do now is add and external LED on any available digital pin and use that code?

Hello all..

today there's a new problem emerged in my datalogger..

when i run the sketch for 16 sensors..it runs smoothly..the serial monitor screenshot as shown below

BUT, after i add another line of coding in purpose to add another sensor, the sketch becomes haywire and not retrieving data from the sensors like it did previously. The screenshot is shown below,

it seems that adding another sensor in the sketch fails the whole sketch..but why?

any advice..thank you~

You need to post your schematic and the code with the extra line.