Determining the frequency.

Hello everyone.
i am doing a project that calculating the frequency from a speed sensor, the sensor is generating 10V AC, i’ve converted it to 4-5V DC half-wave.

Now i would like to use the Atmega168 to find out the frequency, first i need to convert the analog to digital, then calculate it.

i tried to write a script, but there is something wrong, could anyone help me? i vey appreciate it.

 const int sensorPin = 0;

int analogPin = 0;  
int sensorValue = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Start measuring");
}

void loop()
{
   while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);
     // start with input low
  if (digitalRead(frqPin == 0) {
    // wait until pin goes high
    while (digitalRead(frqPin) == 0) {}
    // get the time when input goes high
    timeStart = micros();
    // wait until input goes low again
    while (digitalRead(frqPin) == 1) {}
    // wait until input goes high again
    while (digitalRead(frqPin) == 0) {}
    // take the actual time in microseconds
    timeStop = micros();
    // the timedifference is the the time between two rising
    // edges of the input pin (= 1 period)
    timeStart = timeStop-timeStart;
    // normally the result is > 0, otherwise the
    // function micros() had an overflow (every 70 min)
    // the discard this measuring (or correct the value)
    if (timeStart > 0) {
      // calculate frequency
      // 1000000 microseconds/second, f = 1/t
      double f = 1000000.0/timeStart;
      // report the measured frequency
      SerialPrintln(f);
   }
  }
}
}
if (digitalRead(frqPin == 0) {

You do not have matching ( and ) in this statement. You need a ) after frqPin.

if (digitalRead(frqPin[glow])[/glow] == 0) {

i tried to write a script, but there is something wrong, could anyone help me? i vey appreciate it.

It would be much easier to help you if you described what is wrong. Does the code not compile? If not, what error messages do you get?

If it compiles, does it produce no results? The wrong results?

By the way, it appears as though you are trying to re-invent the pulseIn function.

it shows me this

In function 'void loop()': error: 'frqPin' was not declared in this scop

By the way, it appears as though you are trying to re-invent the pulseIn function

what do you mean by the re-invent the pulseIn function

In function 'void loop()': error: 'frqPin' was not declared in this scop

Where did you declare the variable frqPin? Where did you assign it a value?

what do you mean by the re-invent the pulseIn function

The Arduino IDE provides a function called pulseIn that returns the length of time required for the specified pin to go HIGH, go LOW, or change state. That is what you are trying to write code to do.

Where did you declare the variable frqPin? Where did you assign it a value?

i should change it to "while (digitalRead(frqPin) > 0) )" ? i am new in programming actually. So some standards of writing code that i don't know, if i would like to find the frequency from the analog input of which is connecting to the speed sensor, the frqPin is needed to be defined? like define frqPin 0 ?

You have a variable, analogPin, defined, but it is never used. Is this supposed to be named frqPin?

Every variable needs to be defined, with a type and name. Every variable should be given an initial value.

i should change it to "while (digitalRead(frqPin) > 0) )" ?

No. That still does not assign a type or value to frqPin.

You have a variable, analogPin, defined, but it is never used. Is this supposed to be named frqPin?

Every variable needs to be defined, with a type and name. Every variable should be given an initial value.

umm, i am trying to use the ADC in arduino that could help me to find the frequency, if i want to do this, what the code should be?

The thing that has a frequency that you are trying to measure is connected to sensorPin, isn't it?

Look at the documentation for pulseIn: http://arduino.cc/en/Reference/PulseIn

Pass sensorPin to pulseIn, along with HIGH or LOW. The output will be the length of time it took for the transition to occur.

The thing that has a frequency that you are trying to measure is connected to sensorPin, isn’t it?

YES

i am trying to use the ADC in arduino that could help me to find the frequency, if i want to do this, what the code should be?

Is the signal on this pin digital or analogue? What is the expected frequency range?