Pages: [1]   Go Down
Author Topic: Pulsein on Analog Pins  (Read 413 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

is there an explanation why the pulsein() function doesn’t work on the analogpins?


Code:
int Pin = 14;  // Analog PIN 0

int pulse;  // store RC signal pulse length


void setup()
{
  Serial.begin(9600); //serial library start
 
  pinMode(Pin, INPUT); //Pin 14 as input

}


void loop()

  pulse = pulseIn(Pin, HIGH, 20000);
  Serial.print ("Pulse Time: ");
  Serial.println (pulse);

}
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What and how are you wiring what up to the analog input pin? Perhaps if it's a simple switch you have a floating input pin condition? Draw us the electrical hook-up your using for that pin.

Lefty
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 50
Posts: 2202
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pulsein is for the digital pins pins only

From the ref section for Pulseln()

Quote
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds.

It makes no sense to try to no this with an analog input.

Mark
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It makes no sense to try to no this with an analog input.
Code:
pinMode(Pin, INPUT); //Pin 14 as input
It isn't an analogue input.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


What is the output you get?
What did you expect?

Which version of the IDE are you using as in older versions there was at least one bug in the PulseIn() code...

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: