Hello dear friends , I need your help to Read Serial of sensor respect to time

Hello dear friends , In fact I am facing problem with the coding of serial monitor with repect to time , i want to take a values from flex sensor and i want to draw the graph of the data to time in exel .
but i was not able to get time values of the sensor when i attached it to the analog pin 0 (A0). here i attached my code .
and if you could please tell me if i can do this analyzing with processing program , i will be grateful to you
thank you in advance :slight_smile:

void setup ()
{
Serial.begin(9600);
}
void loop ()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(300);

}

mohammadgh95:
i was not able to get time values of the sensor when i attached it to the analog pin 0 (A0)

That is not surprising since your code only reads the voltage on the analog pin. Why did you think there would be time data?

Have you considered saving the value of millis() everytime you take a reading and sending bot the voltage and th millis() value to the PC?

Post a link to the datasheet for the sensor your are trying to use.

...R

thank you Robin2 here i attached my flex sensor data shield .https://www.sparkfun.com/datasheets/Sensors/Flex/flex22.pdf

waiting your reply

Thanks for the datasheet. It seems to be a simple variable resistance - I thought it may have been a more complex device with its own electronics to produce a time signal as well as a flex signal.

What about my other points in Reply #1 ?

...R

 int sensorValue = analogRead(A0);
   Serial.println(sensorValue);
 delay(300);

Do you really want to sample (and record) three times a second (10,800 times an hour) ?

Do you want the readings in respect to time, or do you want the actual time of day?

Your current code is already in respect to time (ever 300 ms). If you change delay(300) to delay(1000), then each reading is one second apart.

mohammadgh95:
i want to draw the graph of the data to time in exel .
but i was not able to get time values of the sensor when i attached it to the analog pin 0 (A0).

This is because the sensor does not create any time values, and you have made no attempt to get them from anywhere else.

The simplest option you have is to send the data to a terminal programme on your PC instead of the serial monitor. RealTerm is one example. This will enable you to record a .CSV file for subsequent transfer to Excel. This is probably a good idea in itself, since you intend to get the data into Excel, and there is no way of doing that with the serial monitor. You can also include time within each line of data. This is done by RealTerm, using the PC clock, not Arduino.

Since your loop time is about 3Hz, you may find you have problems with fractions of a second. If so, one solution to reconsider whether you really need to get the data that frequently.