element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Need help with a data logger
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 400 subscribers
  • Views 194 views
  • Users 0 members are here
Related

Need help with a data logger

Former Member
Former Member over 13 years ago

Hi: I have been working trying to built a data logger, I want to record the date and time when a device was turn on and off. I currently have the Arduino Uno with the data logger card (SD 4Gb card) configured and it stores data, I have connected a 12 volt device through a voltage regulator tha supplies an output of 5 volts and it starts recording the information when this is connected to a digital input on the Arduino (digital input 7). After the device is off it stops recording and when it is on it starts recording again. The problem that I have is that records for certain time and then it stops even though the device is on again, also in some cases it stores garbage.

 

I dont know what causes this, but any help is very well apreciated.

 

Regards

CarlosH.

 

 

Here is the code that I am using:

 

/* Programa para detectar un voltaje y Grabar con Tiempo y Hora la Actividad hasta que se el voltaje sea cero
*/
//Rutina para mandar llamar las librerias
#include "Wire.h"
#include <SD.h>
#define DS1307_ADDRESS 0x68


// Definicion de la variable del puerto Analogo para lectura del disparador
int Arranque = 7;
int chipSelect = 8;
int CS_pin = 10;

void setup ()
{
  // habilitar el puerto serial para ver pantalla
Serial.begin(9600);
          Serial.print("Initializing SD card...");
  // Poner el pin de la tarjeta como salida
pinMode(CS_pin, OUTPUT);
       
        Wire.begin();

// poner el pin 0 como entrada Analoga
pinMode(Arranque, INPUT);

if (!SD.begin(chipSelect))
{
  Serial.println("");     
  Serial.println("Card Failed");
       
        return;
}
        Serial.println("");
        Serial.println("Card Ready");

}

  

void loop()
{       
    

  if (digitalRead(Arranque) == HIGH)
  {
    printDate();
  }
 
  else
 
  if (digitalRead(Arranque) == LOW)
{
  Serial.println ("Motor Apagado ");
        }

}

byte bcdToDec(byte val) 
{
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}

void printDate()
{
// Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

  //Formato de la fecha y hora  3/1/11 23:59:59
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

// String para grabar info a archivo
   String dataString = String(month) + "/" + String (monthDay) + "/" + String (year) + " " + String (hour) + ":" + String (minute) + ":" + String (second);
// Apertura y Nombre del archivo
   File dataFile = SD.open("datalog.txt", FILE_WRITE);
  
   if (dataFile)
    {dataFile.println(dataString);
    dataFile.close();}
   
   }

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube