Date time

Hola!!! Estoy haciendo unas pruebas en las que me gustaría añadir un temporizador a mi programa de envío de paquetes para cuando yo no esté poder dejarlo funcionando y cuando vuelva ver qué ha ocurrido en cada momento. He probado el siguiente programa:

Lo compilo correctamente pero cuando le doy a 'Serial Monitor' no aparece ningun resultado.

Alguien me podría indicar a qué se debe?

Gracias!!! L.

You need to set the clock before it shows the time.

If you add the following as the last line in setup, the clock will start from Jan 1 2009 when the sketch starts:

There is program (included in the download) using the Processing language that you can run on your home computer that can set the time over the serial port.

Thank you very much!!!

Ahora intentaré cambiar el día y hora!!!! Gracias por tu ayuda!!



Te agradecería me dijeras como instalaste la librería DateTime en el compilador de Arduino.

Es verdad, en el sitio que mencionas hay un código. ¿Y que hiciste con ese código? ¿Donde? ¿Bajo que formato?

Yo lo tenía instalado pero sin querer lo borré. :-/

De antemano, gracias.


no recuerdo tener que instalar ninguna librería… tan sólo introduje el siguiente código:
// DateTime.pde
// example sketch for the DateTime library

#include <DateTime.h>
#include <DateTimeStrings.h>

#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message

void setup(){
pinMode(13,OUTPUT); // we flash the LED each second
DateTime.sync (1233768500);

void loop(){
unsigned long prevtime;
if( getPCtime()) { // try to get time sync from pc
Serial.print("Clock synced at: ");

if(DateTime.available()) { // update clocks if time has been synced
digitalWrite(13,LOW); // first flash the LED
prevtime =;
while( prevtime == ) // wait for the second to rollover
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock

// send our time to any app at the other end of the serial port
Serial.print( TIME_HEADER,BYTE); // this is the header for the current time
Serial.println(analogRead(2)); // lee el sensor que hay en el pin 2


boolean getPCtime() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
if( == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char c=;
if( c >= ‘0’ && c <= ‘9’){
pctime = (10 * pctime) + (c - ‘0’) ; // convert digits to a number
DateTime.sync(pctime); // Sync Arduino clock to the time received on the serial port
return true; // return true if time message received on the serial port
return false; //if no message return false

void digitalClockDisplay(){
// digital clock display of current date and time
Serial.print(" “);
Serial.print(” “);
Serial.print(” ");

void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10)

en arduino y me funcionaba…
espero que te sirva de algo!!


no recuerdo tener que instalar ninguna librería... tan sólo introduje el siguiente código

The DateTime library code does need to be installed in the library directory. To install it, download the code from here:

Unzip the contents into the folder named ARDUINO/hardware/libraries. This should create a new folder named DateTime.

Hello all guys of the Arduino Forum…

Dear all,

At this point, I am in a deep crisis (you may be laughing). I don´t know if I should laugh or cry, though…

Only 2 out of 7 small sketches I prepared, one for each sensor, worked out. This is a mere 28.5%. Not very good.

The ones that worked were fuel tank level and one fuel flow meter.

I checked the signals at the car end of the connecting wires: they are all working and sending signals.

So, come to the conclusion that I must start over again, this time, on a protoboard. No more soldering until all is working and almost final.
Soldering from the beginning is a bad idea, because you cannot modify things easily and quickly, on the run.

I have a new startegy, to be followed in ten phases. I publish my experience here, because some newbies may take advantage of it.

  1. Check every one digital and analog pin of the Arduino board, before any further intent.
    For that, I need a couple of testing sketches, very simple and short. I cannot see other way.

Once Arduino has been evaluated on its health,

  1. Get every single signal of the car (or whatever) on the protoboard, where you can check voltages. I good idea is to input them to a PC-based osciloscope (free), for analysis.

  2. Prepare voltage dividers for every signal that is over 5 VDC. Eventually, prepare a signal amplifier if the signal is too weak for Arduino to process.

  3. Prepare 7 sketches, one for every signal, very simple, just to put the signal into Arduino. Once it is recognized by Arduino, you can process it. There are many data processing functions, that may help.

  4. Process each signal, according to its nature. Sample, smooth, calculate moving averages, map, constrain, etc., everything usefull to improve signal and convert it into information. Bring the computer to the car and solve the details there. Start with one analog and one digital signal to gain scope on how to manage them. You can use your math models at this stage.

  5. Consolidate a “final” processing sketch for each signal, save it with a very clear name that you can recall later, without confussion.

  6. Begin to work with time, means, results screens, etc. In my case, time is needed to calculate distance travelled, as my odometer is analog, very old.

  7. Begin to program a final sketch where all signals are integrated. Starting with one signal and add one at a time, testing all is working ok. After all intermediate values prove to be ok, program final “to be shown results”, as to take advantage of the project.

  8. Calibrate all signals.

  9. Eventually, make a pcb where I can solder (at last) all necessary pieces efficiently and securely. Maybe use a Arduino shield. Assamble and test again in the car.

The stategy sound good to me… any improvement ideas from your experience?

  1. Make some fancy staff, such as put the thing into a box, add some buttons for multiple display pages, or such.

At present I am on stage 1, having trouble from the beggining: the test sketch that comes with the Arduino 16, do not work for me as it is supposed to.

This is it:

 * Button
 * by DojoDave <>
 * Turns on and off a light emitting diode(LED) connected to digital  
 * pin 13, when pressing a pushbutton attached to pin 7. 
int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for a pushbutton)
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare pushbutton as input

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH); // turn LED ON

It should turn off the LED everytime I press the button. It doesn´t. Instead, when I plug the button the LED turn off, no matter if I press the button or not.

The bad thing of this routine is that it hasn´t any circuit diagram to know where and how to connect the button!

Does anyone know about a routine that can be used to check Arduino board? Maybe there is such a routine already made somewhere? Anyone knows?

Conversely, would someone bring here a couple of very simple routines to check Arduino?

I have a potentiometer, resistors, capacitors, buttons, a small motor, and the led of the Arduino board to use for this purpose.



Gracias Lorena por tu ayuda. Trataré de aprovecharla. No es fácil toparse con una chica e este medio y menos que hable español! Sabes bastante más que yo, por lo que veo en tu sketch. ¡Es bueno saber de tu existencia! Nuevamente, gracias.


A mi me pasaba lo mismo. Pero descubrí un ícono en el compilador Arduino, arriba, a la derecha, que si se pulsa aparecen los resultados en la ventana negra inferior del compilador.

Ojalá te sirva.


Oldbeaver, many of the arduino tutorials have recently had diagrams and more description added.

See here for the help with the button tutorial:

Mem, thank you much for the info.

I will explore more often the references.



I tested all Arduino pins as inputs, in order to see why I am having trouble processing signals of some sensors. Here is what I discover.

After testing all analog pins of Arduino Diecimila, I got the folowing results:

[u]Analog Pins/u Pin 0: 0 to 1023 value range, normal. Pin 1: 0 to 1019 value, but with a completely different curve. Pin 2: 0 to 1023 value, equal to pin 0. Pin 3: 0 to 1023 value, similar to pins 0 and 2. Pin 4: 0 to 8 value range, different to all other pins. !!!!!!!!!!!! Pin 5: 0 to 1023 value range, similar to pins 0, 2 and 3.

Conclussion: not all pins are equal. One should test this before wiring. Accordingly, signals must be processed individually.

[u]Digital Pins/u

Pins 0 and 1 used to communicate with computer. Pin 3: work. Pin 4: work Pin 5: work Pin 6-12 Used by LCD screen Pin 13: work Pin 14: used by LCD screen Pin 15: work, but interfere with pin 13 ? Pin 16: GND

So I have the necessary pins I need, but must be cautious at the time of connecting sensors. Values in analog pins convert ohms values of pot into a 10th of the value.

Are this results normal? What is the experience of other Forum members?

Old Beaver


I have been trying to use this sketch but nothing happens it dont write anything out, is that because it doesnt get any time from the PC?


there is a later version of the library that you may want to try that is slightly easier to get going :

The discussion thread for that library is here: