I want to feed thousands of analog vibration sensor readings into an array as fast as possible, and then analyze them. Here is my sketch:
const int pSensor1 = A0;
const int aSize=10000;
int a[aSize];
void setup()
{
pinMode(pSensor1, INPUT);
Serial.begin(9600);
}
void loop()
{
for (int i = 0; i < aSize; i++) a[i] = analogRead(pSensor1);
int RMS = 0;
for (int i = 0; i < aSize; i++) RMS += pow(a[i], 2);
RMS = sqrt(RMS/aSize);
Serial.println("Hello");
}
This compiles and runs fine. My problem arises when I try to change the last line to:
Serial.println(RMS);
I get the error:
Arduino: 1.8.12 (Windows 10), Board: "Arduino Nano, ATmega328P"
Sketch uses 3270 bytes (10%) of program storage space. Maximum is 30720 bytes. Global variables use 20188 bytes (985%) of dynamic memory, leaving -18140 bytes for local variables. Maximum is 2048 bytes. data section exceeds available space in board Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint. Error compiling for board Arduino Nano.
Why does attempting to Serial print a single floating point variable use 985% of dynamic memory?