to put the "difference between sequential reading data" into if loop

hi everyone

i read the analog value from my sensor and see the data ,which is taken by every 1000 ms.

i want to write a code regarding to calculating the difference between every two values(sequential) then

will enter next step if the difference between two values is higher than 3 .

i couldnt imagine how i use "if statement" and how i show the difference between two sequential data on code.

my code:

const int peak = 3;

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  Serial.println("Is the sensor placed? ");
  Serial.println("type y or n ");
  Serial.println("CLEARDATA");
  Serial.print("LABEL,Time,peak of current");
}

// the loop routine runs over and over again forever:
void loop() {
  
    char Input = Serial.read();
    
 
      // User selected yes
      if(Input == 'y')
      {
        for(int i=1; i<=100 ; i=i+1)
        {
          
          
  // read the input on analog pin 0:
  int sensorValue = analogRead(A1);
  int row=0;
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5/1023.0);
  float current = (1000*voltage)/46.7 ;
  float ms = (current-3.9)*19.6/15.7 ;
  
  // print out the value you read: 
  
  if (ms < peak ){//  the difference between two ms values ?
      
  Serial.print("DATA,TIME, ");
  Serial.print(current);
  
  row ++;
  
  current ++;
  
  i=0;
  
  }
 
  delay(1000);
}
}
}

Your code is very difficult to follow because it is not indented properly. Use the AutoFormat option in the IDE.

If you want to compare the new reading with the previous reading you must (obviously) save the previous reading - you don't seem to do that anywhere.

I don't understand why you have a complex calculation

float current = (1000*voltage)/46.7 ;

and then a few lines later you have

current ++;

especially as that updated value is never used

...R

i use float calculation in order to convert voltage value to current value then i linearized the current

values realted to conductivity range.

my problem is how can i get difference between two sequential ms values then put into if or other statement for entering other loop.

how can compare the new reading with previous reading ?

crea123:
how can compare the new reading with previous reading ?

I thought I covered that in paragraph 2 of Reply #1

i use float calculation in order to convert voltage value to current value then i linearized the current values realted to conductivity range.

That does not deal with my comment about current ++;

...R