Hi,
This is my first arduino project so apologies if i’m missing something basic.
The project is going to read in two frequencies, then perform a calculation on the two frequencies to get another number.
I’ve found the freqmeasure library (FreqMeasure Library, for Measuring Frequencies in the 0.1 to 1000 Hz range, or RPM Tachometer Applications) perfect for my needs, but the input can only be mapped to pin 8, so it only allows one input.I need two inputs for my project. Is there someway of getting the same input without pin 8 or is there a component i can buy to replicate pin 8.
I have found this library; Frequency counter
quite helpful for projects like this. You can use 2 inputs (using the 2 interrupt pins) with the code implemented either using the interrupts or polling the counter in the loop.
Works well, you can have it measure Hz directly from the library (in whole numbers) if you're measuring a relatively high frequency, or using a floating point variable and calculate the frequency from the period of pulses if you need a fractional Hz result (if you need to detect small changes in low frequencies).
My project measures the RPM of 2 different shafts, which are relatively low, so I use the fractional option.
Uses a bit more memory that way due to the floating point calculation so if you're reading higher frequencies, the built in counter.hertz() function is better.
Here is some example code using the above library to calculate 2 different frequencies (and convert to RPM). Using floating point and a fractional frequency.
This is just the frequency parts pulled out of a bigger sketch so this is untested stand alone.
Alternately, you might use a relay (SPDT or DPDT) to switch the line that's connected to pin 8. You'll need a transistor to drive it:
This assumes you can read one frequency and then read the other sometime after that - i.e., you don't need to read both at exactly the same time. And that you can wait for the relay to settle (a few hundred ms) before you read.
I'll fool around with pulseIn tomorrow and see if i can get some results.
Hi plank,
Here's an easy way to play around with pulseIn(). The sketch measures the Arduino PWM frequency and the length of the HIGH and LOW pulses for each PWM value. Try it out - you only need one wire!
Tom
// PWM analysis, Tom Fangrow, July 8, 2012
// connect a wire from digital pin 2 to digital pin 3
long hi, lo, x;
void setup() {
pinMode(3, OUTPUT);
Serial.begin(9600);
}
void loop() {
for(x=1; x<255; x++) { // for all useful values
analogWrite(3, x); // output PWM on pin 3
hi = pulseIn(2, HIGH); // measure HIGH pulse
lo = pulseIn(2, LOW); // measure LOW pulse
Serial.print("PWM: "); // PWM value (1-254)
Serial.print(x);
Serial.print(", HI: "); // signal at 5 volts
Serial.print(hi); // for 'hi' microseconds
Serial.print(", LO: "); // signal at 0 volts
Serial.print(lo); // for 'lo' microseconds
Serial.print(", Freq: "); // PWM frequency
Serial.print(1000000/(hi + lo));
Serial.println(" Hz"); // in pulses per second
}
}
Ok please forgive me, i am very noobish ... i actually need to ask a question but not sure how to start it as a topic like he did up there..
i need a simple program where i can read a frequency, no need to display it.
ill read it if its above 500hz an led light up,
and if its below 500hz another led from another pin light up.. of course i am not going to ask u guys to do this for me but i will try my self in the cod below... please forgive my obvious syntax error.
pseudo code- #include <FreqMeasure.h>
int led1=13;
int led2=9;
void setup() {
FreqMeasure.begin();
PinMode(led1,OUTPUT);
PinMode(led2,OUTPUT);
}
if (FreqMeasure.available()< 500)
DigitalWrite(led1,HIGH);
else
DigitalWrite(led2,HIGH);
end
NOOB4101:
hahaha i like how you guys didnt answer my question ,, so how can i fix that code.
If you want help fixing a problem with your code you need to post your actual code - in its entirety - that demonstrates the problem. If the problem is a compilation error then you need to also post the actual output from the compiler.