hi all in the forum here is what im trying to program. i have an optical sensor which its inside a black case outside the case im shooting a potholed pointer(those you use in presentations) so when a the flying wheel pass, more specifically one tooth pass through the middle and block the light of the led the arduino reads it and start a count of the RPM..... for example if i use a teeth wheel(not sure yet about how many teeth id be using) for every 40 times the sensor goes low will be a spin in..........
im not good at programming so im almost an ignorant in this......
this is a code so very basic i wrote when using other examples.... but if you help me adding stuff for faster counts and filters would be good.... but im not sure if this code works i havent tested it i just wrote it, using all knowledge i have but this its my limits jejejee
volatile unsigned int rpmcount;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(115200);
attachInterrupt(0, rpmfun, RISING);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
if (rpmcount >= 100) {
rpm = (millis() - timeold) / rpmcount;
const float freqHz = ((float) rpmcount / (float) (micros() - timeold)) * 1000000.0;
const float RPM = freqHz * 60.0;
timeold = micros();
rpmcount = 0;
Serial.println(rpm,DEC);
}
}
void rpmfun()
{
rpmcount++;
}
for reference the sensor its like a optical barrier, if its not very well explained...