Skip to content

Instantly share code, notes, and snippets.

@delasign
Created March 30, 2024 14:36
Show Gist options
  • Save delasign/0082c620887a09d84c25091e297db46c to your computer and use it in GitHub Desktop.
Save delasign/0082c620887a09d84c25091e297db46c to your computer and use it in GitHub Desktop.
Sample Low Pass Filter Code
float alpha = 0.95; // Filter constant, higher value means more filtering
float prevValue = 0.0; // Previous filtered value
float filteredValue;
void setup() {
Serial.begin(9600);
}
void loop() {
float rawValue = analogRead(A0); // Read the raw analog input
// Apply the low-pass filter
filteredValue = rawValue * (1 - alpha) + prevValue * alpha;
prevValue = filteredValue;
// Print the filtered value
Serial.println(filteredValue);
delay(10); // Delay to control the sampling rate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment