I am new to this and i have started with HC-sr04 to detect object , it does work but when i leave it for a while i can see spikes, please check the attached picture.
I also looking for a way to add temperature compensation if possible if there is an example that will be great.
Have you tried it in a sound-proof room? I'm afraid there is no way to prevent your sensor from hearing ambient noises in the 40 kHz range. Try jingling some keys and see if you can induce spikes.
You can use a formula for speed-of-sound values:
You may also want to compensate for humidity and barometric pressure.
Thanks a lot Johnwasser, yes it might be the noise, by the way i placed the sensor inside a very closed plastic (its a valve) however i think it might be the noise so i might try to use different sensor for measuring.