Time measurement and writing to memory

Hi. Im new to Arduino and I would like to know is it possible to measure time between two events (two digital inputs) and write down result to memory?

Measure would be triger with Digital input 1, and Stop with Digital input 2.

Measure wold take about 10sec, and this event would be repeted every 30 sec. For about 24 hours.

After I wold like to take the results from arduino and analize it.

Thanks in advance

Best regards to all

Should be rather easy. You could record the time(s) on an SD card, in the EEPROM, and/or send them to the serial monitor.

Here is what you need to consider:

  1. You need to know if digital inputs are active HIGH or active LOW
  2. How much resolution do you need for these measurements? i.e. is a millisecond resolution sufficient? If so you can use the millis() timer to determine these times.

Save the value of millis() to a variable when input becomes triggered
Save the value of millis() to a variable when the stop becomes triggered
Subtract the start value from the stop value and write the result to an SD card

Thanks for your comments.
Milliseconds will be fine.
Inputs will be defined as HIGH.
Is it possible to Help me with program, I need every to write every event as separate number. I do not need to add up to cumulative.


Inputs will be defined as HIGH.

Does that mean normally HIGH or only when activated ?

What have you tried so far ?

Which Arduino board do you have ?

A Arduino Uno has a builtin EEPROM of 1kbyte.
The millis() value is 32 bit, but with a maximum of 10 seconds, only the lowest 16 bits is enough (two bytes).
During 24 hours, every 30 seconds is 2880 recordings of two bytes, that makes 5760 bytes. That will not fit in the 1024 bytes of the EEPROM.

You could add a external EEPROM, they are cheap. They use the I2C interface, but there are libraries for them.
You could also add a shield with a (micro)SD socket or use a Arduino board that has already a microSD socket.
It is also possible to send all the data to the serial monitor and use a computer to store all that data.

The sketch could start recording with a button.
To retrieve the data from the Arduino, a command via the serial monitor could be used. When using a microSD card, you can simply put the microSD card in the computer.

The cheapest MKR board with the MKR MEM Shield is the fastest way to get it working.

An Arduino Uno with this SD Shield from SeeedStudio is also a good choice.

Don't buy just any SD Shield, some do not have a SPI interface and then you need to use software SPI, which can cause troubles. Don't by just any SD module, some are only compatible with a 3.3V Arduino board.

What is the voltage levels of the two signals ? Does the Arduino needs some protection for those signals ? Or are they only contacts that open en close ?