 # The Pin 13 can't output High Level

Hi,
I am an arduino beginner. Now I connect a Peizo sensor to the arduino Pin A0 (the Pin A0 will sample the voltage over the senor) ,and hope the Pin 13 will output a High level when I press the sensor. But it can not output the High Level. I don’t know why. the code is as the following:

``````int led =13;
const int N=1000;
float voltageValue[N];
float voltage[N];
int PressStatus;//Pressing flag;
void setup(){
//initialize serial communication at 4800bit per second;
Serial.begin(4800);
pinMode (led,OUTPUT);
}

void loop(){

int i;
for(i=0;i<N;i++){
//read the input on analog pin A0;
voltage[i] = voltageValue[i] * (5.0 / 1023.0);

if (i>0&&voltage[i]-voltage[i-1]>=0.1){
// Serial.println("voltage = ");
PressStatus=1;
digitalWrite(led,HIGH);
}
else {
PressStatus=0;
digitalWrite(led,LOW);
}

Serial.println(voltage[i]);
//Serial.println(Press);
}
}
``````

How much RAM does your board have? How much RAM are you using? ( I can answer the second question, and it is more than 8000 bytes)

I use a Arduino UNO board and I am not sure about the RAM size. Thanks

are there some error for my code?

You're using way more RAM than your board has. Reduce N to something sensible, like 100

"if (voltage_-voltage[i-1]>=0.1)" in a loop with voltage constantly updating would result in a blink that you would probably not even notice._

yeah, It can work after changing the N value. How do you calculate the size? Help, Pls. Thanks

A float takes 4 bytes.

Since you are just using voltage[i-1] and voltage you don't need N to be bigger that 2. Get rid of the for loop and do 'voltage = voltage;' and then 'voltage = analogRead...' and so on.

Thank you so much:)

AWOL: You're using way more RAM than your board has. Reduce N to something sensible, like 100

This is actually very helpful! it worked just fine after changing N! Never though of it! Thanks