Skip to content

Instantly share code, notes, and snippets.

@greed9
Last active May 20, 2025 16:59
Show Gist options
  • Save greed9/4599b491a3924aae751ba3781b42c9af to your computer and use it in GitHub Desktop.
Save greed9/4599b491a3924aae751ba3781b42c9af to your computer and use it in GitHub Desktop.
Arduino Starter sketch for Tach
// Read and process hall effect sensor for use as tach
// See https://www.allelcoelec.com/blog/A3144-Hall-Effect-Sensor-Pinout,Alternatives,and-Applications.html for hookup
#define HALL_EFFECT_PIN 2
int sensor_value = 0 ; // output from hall sensor, low for detect
void setup() {
// put your setup code here, to run once
Serial.begin( 115200 ) ;
pinMode( HALL_EFFECT_PIN, INPUT) ;
}
// See: https://sepwww.stanford.edu/sep/prof/pvi/zp/paper_html/node2.html#_prog:copy for theory
float leakyIntegrator( int new_sample, float rho )
{
// Type your code for the leaky integrator here -- see image in slides
float output_value = 0.0 ;
return output_value ;
}
// Utility routine to hack the automatic scaling off for the plot
void plotSpeed (float max_value, float sensorValue)
{
Serial.print(0); // To freeze the lower limit
Serial.print(" ");
Serial.print(max_value); // To freeze the upper limit
Serial.print(" ");
Serial.println(sensorValue); // To send all three 'data' points to the plotter
}
// loop reading sensor and processing each 1/10 second
void loop() {
sensor_value = digitalRead( HALL_EFFECT_PIN ) ;
sensor_value = !sensor_value ; // flip value of sensor output to get a 1 when triggered
float result = leakyIntegrator( sensor_value, 0.85) ; // integrate. rho must be float value <1.0
plotSpeed( 10, result) ; // show the plot
delay ( 100 ) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment