Hi,
I started with Arduino half a year ago, I am still quit new, so please forgive me if I have missed something basic.
My Project
I am playing around with a little RPM counter project to later hopefully use some of the code to make a Liter pro hour meter for my car by connecting it to a flow sensor in place of the infrared rpm sensor.
Foremost I am trying to make an RPM counter that can read low rpm as-well such as 1 rpm
(this in it self is not so hard I just set the the delay to a minute
delay(60000);
) However doing this means that I need to wait a minute to get every other value that is higher than 1 rpm)
the solution to this could be to make more readings pro revolution E.g. 10 readings pro revolution would cut the reading time down to 6 seconds, but this is not an option as the reason I am playing around with this counter is to use it later with a flow sensor where I can't just ad more readings pro rotation/liter flow.
My point:
So what I am asking is if it is possible to change the delay between calculations depending on the frequency of the readings?
I have tried to use the "if" writing code like this:
if (rpm > 5)
delay(12000);
if (rpm > 10)
delay(6000);
This does not seem to affect my delay time or am I doing it wrong.
For refference
the code I am basing it on was borrowed from http://arduinoprojects101.com/arduino-rpm-counter-tachometer/
which was originally based on Chris Palmers project www.instructables.com/id/Arduino-Based-Optical-Tachometer/
I changed it from LCD to TV-output using the libraries of Google Code Archive - Long-term storage for Google Code Project Hosting.
int ledPin = 13; // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
// include the library code:
#include <TVout.h>
#include <fontALL.h>
#include "schematic.h"
#include "TVOlogo.h"
// initialize the library with the numbers of the interface pins
TVout TV;
void rpm_fun()
{
//Each rotation, this interrupt function is run twice, so take that into consideration for
//calculating RPM
//Update count
rpmcount++;
}
void setup()
{
TV.begin(NTSC,120,96);
TV.select_font(font6x8); // intialise the tvout
//Interrupt 0 is digital pin 2, so that is where the IR detector is connected
//Triggers on FALLING (change from HIGH to LOW)
attachInterrupt(0, rpm_fun, FALLING);
//Turn on IR LED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
//Update RPM every second
delay(10000);
//Don't process interrupts during calculations
detachInterrupt(0);
//Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
//happened once per revolution instead of twice. Other multiples could be used
//for multi-bladed propellers or fans
rpm = 1.8*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
if (rpm > 5)
delay(5000);
if (rpm > 10)
delay(1000);
//Print out result to lcd
TV.clear_screen();
TV.println("Liter/Time=");
TV.println(rpm);
//Restart the interrupt processing
attachInterrupt(0, rpm_fun, FALLING);
Thanks