Comparing Same Sensor Values

I can't find this after searching, forgive me if I missed it but I'm a newb.

Upon reset, the sensor should store it's initial value to a variable and then in the loop, compare the live reading to the initial value.

Where does the first value go? Should it be stored differently? Is this even remotely close?

//Here? int var1 = analogRead(A0);

void setup { //...or here? int var1 = analogRead(A0); }

void loop { // Reading sensor live int var2 = analogRead(A0); // Calculating different for print finalvalue = (var2 - var1) * 0.45; }


You need a global variable to store the first value. You need to read the sensor in setup() and store the value in the global in the global variable. No, the global variable should not be called var1.

Such as...?

int SensorStart = 0;

void setup { SensorStart = analogRead(A0); }

void loop { int SensorLive = analogRead(A0); int Difference = (SensorLive - SensorStart) * 0.045; }

Such as...?

Exactly. Well, almost, anyway. Why multiply the difference by that magic number?


The magic number I keep accidentally putting is a conversion for the sensor value. The sensor is measuring resistance and it is 0.045 per 1 point of change.