y=mx+c Doubt

I am in a final stage of my project i want to convert the voltage into refractive index using the slope that i've obtained is plotted on excel sheet.

I used the code below

float Intercept = 4.0927; // -->refer for calibration Value
float Slope = -0.4589;     // -->refer for calibration value

float val = 0.0;            //variable to store the value coming from the sensor                           
float Bit = 1023.0;         //set value for amount of bits
float volt = 0.0;           //set value to store calculated voltage
float SensorData;           //float RI=0;

const int SensorPin = A0;
void setup() {

    pinMode(A0, INPUT);
   Serial.begin(9600);

}

void loop()
{
  float Time;                                // Read and store Sensor  data
  val = analogRead(A0);
  volt = val * (5.0 / 1023.0); //equation to convert incoming value to voltage
  float SensorReading= volt*Slope + Intercept; //converts voltage to sensor reading
Serial.print("Refractive Index is:");
Serial.println(SensorReading);

 
  
}

Instead of 0 i get a wrong output. I Think there is problem in my code

Refractive Index is:2.24

Refractive Index is:2.24

Refractive Index is:2.24

Why should it be zero?

If volts are zero I would expect 4.0927

What is connected to the input? If it is floating you could get anything.

The only way to get 0 is if the input voltage is 8.92 V, which is unlikely.

If the output is 2.24, the voltage must be about 4 V.

Print the value of voltage

  float Time;                                // Read and store Sensor  data

No, it does not. If you are going to have useless comments, they MUST be correct useless comments.

Time is measure in milliseconds or microseconds. Integer values, NOT floats.

  float SensorReading= volt*Slope + Intercept;

Nonsense. The sensor did NOT read that value. Meaningful names ARE important.

PaulS:

  float Time;                                // Read and store Sensor  data

No, it does not. If you are going to have useless comments, they MUST be correct useless comments.

Time is measure in milliseconds or microseconds. Integer values, NOT floats.

  float SensorReading= volt*Slope + Intercept;

Nonsense. The sensor did NOT read that value. Meaningful names ARE important.

Sir can you please debug my program. i am a noob in arduino programming

i am a noob in arduino programming

Even a noob can use decent names.

float c = 4.0927; 
float m = -0.4589;
float val = 0.0;     
float Bit = 1023.0;
float volt = 0.0;    

const int SensorPin = A0;
void setup() {

    pinMode(A0, INPUT);
   Serial.begin(9600);
}

void loop()
{
 
  val = analogRead(A0);
  volt = val*(5.0 / 1023.0); //equation to convert incoming value to voltage
  float y= (volt*m + c); //converts voltage to sensor reading
Serial.print("Refractive Index is:");
Serial.println(y);
delay (500);
 
  
}

am sorry you mean my username?
it's short form of my full name

am sorry you mean my username?

No. Your user name is not the issue. Your variable names are.

const int SensorPin = A0;
void setup() {

    pinMode(A0, INPUT);

Why bother assigning a meaningful name for the pin, when you don't then use the name?

  float y= (volt*m + c); //converts voltage to sensor reading

No, it does not. It converts voltage to a coordinate on a 2D plane. That location might mean something, but val was the sensor reading.

The parentheses are useless.

Serial.print("Refractive Index is:");
Serial.println(y);

Now, here's a silly idea. Why not call the variable refractiveIndex and make the useless comment read // Convert voltage to refractive index?