Skip to content

Instantly share code, notes, and snippets.

@beydogan
Created May 28, 2014 20:23
Show Gist options
  • Save beydogan/b4226dda3a95f80cb358 to your computer and use it in GitHub Desktop.
Save beydogan/b4226dda3a95f80cb358 to your computer and use it in GitHub Desktop.
getSensorValues ACS712 - not working
void getSensorValues(){
unsigned long currentAcc = 0;
unsigned int count = 0;
unsigned long prevMicros = micros() - sampleInterval ;
while (count < numSamples)
{
if (micros() - prevMicros >= sampleInterval)
{
int adc_raw = analogRead(0) - adc_zero;
currentAcc += (unsigned long)(adc_raw * adc_raw);
++count;
prevMicros += sampleInterval;
}
}
float rms = sqrt((float)currentAcc/(float)numSamples) * (75.7576 / 1024.0);
mySerial.println(rms);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment