Is this work for frequency counter

oh my god
have some problems with the motor today, the program could not be tested .

i have a question about the LCD
now i am using "lcd.clear();" to clear the previous speed
so the speed keep blinking.
however, i would like to keep the the number. When no speed, it will return to zero. If there is a speed, it will have a speed showing,

it maybe confused that you guys don't know what i am talking about
if you have question, ask me please.

Thanks a lot!

now i am using "lcd.clear();" to clear the previous speed
so the speed keep blinking

You only need to call clear if the value has changed.

You only need to call clear if the value has changed.

call clear ?
what is it like actually ?

i have to go home, i will be talking later, thanks

what is it like actually ?

"lcd.clear()" only needs to be called if the value you are about to write to the LCD is different to the value that you last wrote to it.
That will eliminate some of the blinking.

lcd.clear()" only needs to be called if the value you are about to write to the LCD is different to the value that you last wrote to it.
That will eliminate some of the blinking.

Yes
umm
but now i would like to do this, that is
when a value shown like this "40.0"
the second is , "50.0"
however, the 40.0 is changed to 50 by jumping, not clearing the 40, and print 50

like a timer

For that, you just need to use the cursor positioning methods.
Have you got the frequency measurement working properly?

Have you got the frequency measurement working properly?

about that, it is night time now in Hong Kong, so i gotta try this tomorrow
today, there is a problem with the motor, it is smoking, help me god.
i hope there is other motor to replace it.

i will keep you guys informed, and thanks again
i love you guys ;D

Oh my god...
it keeps showing nothing to me
just 0.00 :frowning:

the current code is here

#define frqPin = 1;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
long timeStart, timeStop;
void setup() {
  pinMode(1, INPUT);
  lcd.begin(16, 2);
  Serial.begin(9600);
  
 
}

void loop()
{
  
pulseIn(1, LOW); // Wait for pin to go LOW
unsigned long t1 = pulseIn(1, HIGH);// Time how long it takes to go HIGH again
unsigned long t2 = pulseIn(1, LOW); // and how long it takes to go low again.
 double t = t1 + t2;
         double f = 1000000.0/t;
           double w = 2 * 3.14 * f;
           double v = w * 2 * 3.14 * 0.01666667;
           double s = w * 0.05;
         lcd.println(s);
          delay(1000);   
          lcd.clear();
}

Ah , i saw that i forgot to cancel the long timestart and stop
will it afftect the pulse in funtion ?

HELP :frowning:

#define frqPin = 1;

Wuh?

it keeps showing nothing to me just 0.00

What are the values of t1 and t2?

i've tried
#define and int

they are still showing zero :frowning:

And what are the values of t1 and t2? (which do not BTW, need to have global scope)

you mean, the t1 and t2 are needed to be defined, before recording the time taken for frequency calculation ?

Have you tried setting up a PWM output, and feeding it into your input?
(I'm assuming you don't have any other sort of function generator)

Have you checked your wiring?
have you really got your input on the serial Tx pin@?

Ignore the comment about scope for t1 and t2.

Have you tried setting up a PWM output,

i haven't tried this one
but how to do this ?

Have you checked your wiring?

sensor one wire to ----- diode ---- resistor ---- pin 1 arduino
sensor other wire to the ground of the arduino

You've got it on digital pin 1?
Why?
It's the serial Tx.

You've got it on digital pin 1?
Why?
It's the serial Tx.

the pin could not be used as a normal digital pin ?

You've got a "Serial.begin" in your sketch - I assume you'd want to use it at some point.

Try this:

#define FREQ_PIN 2

void setup() {
  pinMode(FREQ_PIN, INPUT);
  Serial.begin(9600);
  analogWrite (3, 128); //start a roughly 50% duty cycle on digital pin 3
}

void loop()
{
    while (digitalRead (FREQ_PIN) == LOW)
        {}
    unsigned long t1 = pulseIn(FREQ_PIN, HIGH);// Time how long it takes to go HIGH again
    unsigned long t2 = pulseIn(FREQ_PIN, LOW); // and how long it takes to go low again.
    
    Serial.println (t1);
    Serial.println (t2);
    delay(1000);
}

Jumper pin 2 to pin 3, and run the serial monitor.

You've got a "Serial.begin" in your sketch - I assume you'd want to use it at some point.

ah , i am sorry
i thought this code is needed in every script.
i didn't want to use the serial print.

#define FREQ_PIN 2

void setup() {
  pinMode(FREQ_PIN, INPUT);
  Serial.begin(9600);
  analogWrite (3, 128); //start a roughly 50% duty cycle on digital pin 3
}

void loop()
{
      while (digitalRead (FREQ_PIN) = LOW)
        {}
    unsigned long t1 = pulseIn(FREQ_PIN, HIGH);// Time how long it takes to go HIGH again
    unsigned long t2 = pulseIn(FREQ_PIN, LOW); // and how long it takes to go low again.

    Serial.println (t1);
    Serial.println (t2);
      delay(1000);
}

what is the analogWrite for ?

and, i saw that there is a code on the arduino page, "unsigned long duration;"
it is necessary being written in the code for using unsigned long t1 or t2 ?

Remove the analogWrite

You also don't need :
while (digitalRead (FREQ_PIN) = LOW)
{}
so remove those lines.

What do you see on the serial monitor for t1 and t2?

The analogWrite is there to provide a known signal.

I suggest you keep things simple until you familiarise yourself with the code and get the pulseIn functionality working. So it may be better at first to use serial rather than the LCD code.

You can add the LCD code and conversion from period to frequency after you confirm you are able to measure the pulses.

If you are using a standard arduino board its best to stay away from the pins used by the serial port, so frqPin is set to pin 2

oh, theoretically, the t1 and t2 can be measured ?
today, i found out that, about the voltage output range
the higher output is around 2.5 - 4.6V
the lower output is around 1.6 - 2.4V

if the lower output could not reach to 0V, the pulse can still be measured?