Need to sample voltage readings and compare two values.

I am a arduino beginner. Now I have a project: I need to sample voltage data from a sensor via Pin A0. At the same time, I need to compare the consecutive two data:
if there is a data jump between the two data, Pin 13 will output HIGH; otherwise the Pin 13 will output LOW. My code is as the following, but a error "varuabke-suzed object 'voltageValue' may not initialized" happens. I really don't know why. How to code it?

void loop(){
  //read the input on analog pin A0;
  int i;
  int voltageValue[i];
  float voltage[i];
  for(i=0;;i++){
    int voltageValue[i]= analogRead(A0);
    float voltage[i] = voltageValue[i] * (5.0 / 1023.0);
    float deltaVoltage = voltage[i+1]-voltage[i];
    if (deltaVoltage>=0.5||deltaVoltage<=-0.5){
      digitalWrite(led,HIGH);
    }
    else{
      digitalWrite(led,LOW);
    }
    // Serial.println("voltage = ");
    Serial.println(voltage[i]);
  }

}

Moderator edit: code tags make things very much clearer.

Moderator edit: Proper indenting helps too. (Nick Gammon)

Hi,
I will have a quick look at your code.
However, you would get a much better response if you read the "Read this before posting a programming question" sticky post at the top of the forum.

Before many people will bother answering they might like to think that you have bothered to go through the basic
steps.

The first thing you should do is post ALL your code for the sketch and use CODE tags. Its much easier to read. Also, how do you expect anyone else to compile your code fragment - I've just tried and it will not compile.
Then post your code formatted. Its much easier to read.

Having forced you to read that,

  • you have declared a global variable thus:
    int VoltageValue;

You then redeclared another (local) variable with the same name:
int VoltageValue = blah...;

The language and compiler both think you have asked for 2 separate variables, and you are using one of them (probably the first one)
somewhere in the code you have not shown, wrongly.

Please go back and look at the guidelines, then post again

Ask yourself "what is the value of i ?"

Thank you for your suggestion, I will post again with following the rules.

Posting the actual error message also helps.

Read up on how a for loop works, yours go on forever and never stop.
Don't use an array just use two values, newValue and oldValue.
Declair oldValue outside a function to make it global and give it a value of -1.
In setup read the analogue input into oldValue.
As the last thing in the loop make oldValue equal to newValue.
Loop will run hundreds of times a second so any LED on will only last a tiny fraction of a second, use a delay to keep it on or long enough to see.

I need help on the following program:

int oldValue = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(3,OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:

if (sensorValue != oldValue){
Serial.print("sensorValue : ");
Serial.print(sensorValue);
Serial.print("\t");

delay(1000);
oldValue = sensorValue;
Serial.print("oldValue : ");
Serial.println(oldValue);

}
if(sensorValue>oldValue)
{
digitalWrite(3,LOW);
delay(100);
digitalWrite(3,HIGH);
delay(1000);

}

if(sensorValue<oldValue)
{
digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);
delay(1000);

}
delay(1000);
}

arvind01010,

It looks like your if statements do not make logical sense. As written the bottom two can never be met.