Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Htime; //integer for storing high time
- int Ltime; //integer for storing low time
- float Ttime; // integer for storing total time of a cycle
- float frequency; //storing frequency
- void setup() {
- pinMode(8, INPUT_PULLUP);
- Serial.begin(9600);
- }
- void loop() {
- Serial.println("Frequency of signal");
- Htime = pulseIn(8, HIGH); //read high time
- Ltime = pulseIn(8, LOW); //read low time
- Ttime = Htime + Ltime;
- frequency = 1000000 / Ttime; //getting frequency with Ttime is in Micro seconds
- Serial.print(frequency);
- Serial.println(" Hz");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement