pulseIn() function is not Working

Hi, I simply want to display the OUTPUT that I get from the pulseIn() function. But it just prints zeros.

unsigned long duration;
void setup()
{
  Serial.begin(9600);
  pinMode(7,INPUT);
}
void loop()
{
   duration=pulseIn(7,HIGH);
   Serial.println(duration);

}

What is connected to pin 7?
What is connected to pin 8?

Where are your code tags?

(And do you seriously think pulseIn doesn’t work?)

How often does it print zeros? My guess is there are no pulses on pin 7 or they are longer than 1 second so it's timing out.

Steve

slipstick: How often does it print zeros?

Whenever I run the code, it just prints zeros. And it doesn't work on any other pin on the Arduino. Can there be a problem In the Arduino ? (as my Arduino is a counterfeit). OR a problem in my code

Adivijaya: Whenever I run the code, it just prints zeros. And it doesn't work on any other pin on the Arduino.

But does it print a 50 zeros a second or one zero every 5 seconds or one zero then no more?

And exactly what are the pulses that you are trying to measure?

Steve

I should like to point out that the code now in code tags is not the code originally posted.

slipstick: But does it print a 50 zeros a second or one zero every 5 seconds or one zero then no more?

And exactly what are the pulses that you are trying to measure?

Steve

It prints a zero per second. I am trying to measure the digital INPUTS from one sound sensor

Provide a schematic. Provide a link to the sound sensor (preferably user manual or datasheet).

Adivijaya: It prints a zero per second. ...

That is definately "timeout" (ie there is no (digital , HIGH - LOW) signal present on pin).

Yes since the default timeout for pulseIn() is exactly one second that's pretty definitely what's happening.

So it seems that the "sound sensor" isn't creating a pulse. Exacty what "sound sensor" is it? And have you tried adjusting the sensitivity control that most of them have? It may either be too insensitive so it never fires at all or over sensitive so that the output is high all the time. Do you have a DMM so you can measure the voltage on that output?

Try changing the command to pulseIn(7, HIGH, 2500000) and report back if anything changes.

Steve

Or simply turn on a PWM pin with an analogWrite, and jumper to that.

slipstick: Do you have a DMM so you can measure the voltage on that output?

Try changing the command to pulseIn(7, HIGH, 2500000) and report back if anything changes.

Steve

I don't have a DMM to measure the voltage on the OUTPUT of pin '7'. I tried the same code on all digital pins on the Arduino with a simple switch but it didn't work on even a single one. I also tried pulseIn(7,HIGH, 2500000) but it didn't work as well. I guess there is a problem in my Arduino UNO and I have posted my problem in the Forum as well.

Adivijaya: I don't have a DMM

You really ought to get one then ;)

Adivijaya: I also tried pulseIn(7,HIGH, 2500000) but it didn't work as well.

The question was did it change anything...in particular did you get zeros printed more slowly, like every 2.5 seconds?

I also asked what type of sound sensor you had and if you had done any adjustments to any potentiometer it has. You didn't bother to answer that either. If you won't provide necessary information there's really no point in trying to help you.

Steve