i'm using two piezoelectic sensors (40 kHz) in order to measure the distance between them.
One sensor is the transmitter and the other one is the receiver.
In order to properly stimulate the transmitter i'm using the timer 1 as a PWM generator at frequency of 40 kHz.
About the receveir, i'm using the command pulseIn(), in particular:
I've noticed that if i use the digital pin the command gives me 25 microseconds every time, so i used the analog pin A0 as a digital input.
If i stimulate the trasmitter it creates a mechanical wave which activate the receiver but the signal is too low (maximum 2 V) so i realize a voltage divider just below 2.5 V (2 V).
In this case if i don't stimulate the transmitter with the PWM the input voltage remain at 2 V (LOW) and when i stimulate the transmitter it goes HIGH.
The problem is that the pulseIn command gives me low durations even if the sensors are quite distant and this values seem to be random.
Could you help me?
No code, no circuit diagram.
I've noticed that if i use the digital pin the command gives me 25 microseconds every time,
At 40 kHz? Imagine that!
so i used the analog pin A0 as a digital input.
So you want to sample a 40kHz signal with analogRead, that takes at least 100us?