Mee_n_Mac:
Typically a few mA is right. If you look at the datasheet you’ll see they spec the zener voltage (and other things) w/a current of 5 mA. So that’s a good value to aim for. (Hmmmm, that number looks familiar … :mrgreen: )http://www.mouser.com/ds/2/302/NZX_SER-42904.pdf
As for the zener circuit, a more complete description would include the input resistance of the Arduino IO pin and would look like;
[attachment=0]zener-circuit.gif[/attachment]
To look at the above circuit means some current would flow into Rarduino instead of the Zener, and in fact, that’s what happens. But because Rarduino is such a high value and the Zener current doesn’t need to be that exact, you can neglect the small tiny itty bitty current that flows into the Arduino (in this instance) and model the circuit as shown before.So if V1 (tach output) can be 15v and Vz = 5v and the voltage across the resistor (R) is 10v. If you want 5 mA then R = 2000 ohms. Lower voltages reduce the current but so long as it’s 2 mA or so, the Zener will be happy.
As the frequency of the pulses increase the time between them decreases. There are multiple ways to measure that interval. I mentioned one. There are others. Your choice. The (real) Arduino forum is full of answers to questions you never even imagined. :mrgreen:
Would this code work perfectly? Only thing I would need to add is the code for the bar graph LED’s correct? Also is Serial.println() similar to System.out.println() in java, where the Serial is the output and the command follows?
Code:
// Frequency counter sketch, for measuring frequencies low enough to execute an interrupt for each cycle
// Connect the frequency source to the INT0 pin (digital pin 2 on an Arduino Uno)
volatile unsigned long firstPulseTime;
volatile unsigned long lastPulseTime;
volatile unsigned long numPulses;
void isr()
{
unsigned long now = micros();
if (numPulses == 1)
{
firstPulseTime = now;
}
else
{
lastPulseTime = now;
}
++numPulses;
}
void setup()
{
Serial.begin(19200); // this is here so that we can print the result
pinMode(3, OUTPUT); // put a PWM signal on pin 3, then we can connect pin 3 to pin 2 to test the counter
analogWrite(3, 128);
}
// Measure the frequency over the specified sample time in milliseconds, returning the frequency in Hz
float readFrequency(unsigned int sampleTime)
{
numPulses = 0; // prime the system to start a new reading
attachInterrupt(0, isr, RISING); // enable the interrupt
delay(sampleTime);
detachInterrupt(0);
return (numPulses < 3) ? 0 : (1000000.0 * (float)(numPulses - 2))/(float)(lastPulseTime - firstPulseTime);
}
void loop()
{
float freq = readFrequency(1000);
Serial.println(freq);
delay(1000);
}
Also just realized I said I was going to use a MEGA for this project, when in fact this project gets an UNO, while the other one gets a MEGA.