Problem using ultrasound sensor

Hello Guys,
So I was asked to make a small system that detects ultrasound waves and read them in arduino. So I looked up in the forum and found a topic that helped me:

jremington:
Perhaps you could replace the MEMS microphone on a typical microphone module with one of the transducers.

Most MEMS microphones are useless above 20 kHz. The HC-SR04 transducers are resonant at about 40 kHz, so they will be most sensitive to frequencies near that. It is not possible to change the resonant frequency.

So I did that and I think it works but still I don’t know how to extract informations from the results.
Here is what I get when there is no source of 40kHz wave:

Here is what I get when I put the source(HC-SR04) in range:

My goal in the assignement is to be able to get a graph showing the 40kHz frequency when the wave is present. But if I can get a digital value instead of the values shown in the images above that would be enough.

The sketch code is in attachements.
Thanks

UltrasoundTest.ino (609 Bytes)

Please post your code and a schematic.

TheMemberFormerlyKnownAsAWOL:
Please post your code and a schematic.

Thanks for your reply. The schematic is very easy I just connected every pin to its port(I don't know how to make schematics as I am new in arduino things).
Here is the code:

/* Constantes pour les broches */
const byte TRIGGER_PIN = 2; // Broche TRIGGER

void setup() {
 pinMode(A0,INPUT);
/* Initialise le port série */
 Serial.begin(9600);
  
 /* Initialise les broches */
 pinMode(TRIGGER_PIN, OUTPUT);
 digitalWrite(TRIGGER_PIN, LOW); // La broche TRIGGER doit être à LOW au repos
}

void loop() {
 digitalWrite(TRIGGER_PIN, HIGH);
 delayMicroseconds(10);
 digitalWrite(TRIGGER_PIN, LOW);
 int SensorData=analogRead(A0);
 Serial.println(SensorData);
 delay(50);
}

What is connected to pin A0?

Please remember to use code tags when posting code

A0 is connected to the Analog output of the sound sensor(KY-038) that has the receiver transducer that I removed from HC-SR04

thanks I will use them next time.

The HC-SR04 sends only a very short burst of ultrasonic waves when triggered.

A single analogRead() probably will not capture anything useful, especially when followed by a very slow Serial.print(). In any case, analogRead() is far too slow to measure signals at ultrasonic frequencies.

40kHz is one cycle every 25 microseconds.
An SR04, when triggered, typically produces a pulse train of 8 cycles, or 200 microseconds. With ringing, maybe another 100 or so microseconds.
What do you expect to achieve by taking a single sample?

jremington:
The HC-SR04 sends only a very short burst of ultrasonic waves when triggered.

A single analogRead() probably will not capture anything useful, especially when followed by a very slow Serial.print(). In any case, analogRead() is far too slow to measure signals at ultrasonic frequencies.

Thanks for the reply.
What do you suggest I do?

TheMemberFormerlyKnownAsAWOL:
40kHz is one cycle every 25 microseconds.
An SR04, when triggered, typically produces a pulse train of 8 cycles, or 200 microseconds. With ringing, maybe another 100 or so microseconds.
What do you expect to achieve by taking a single sample?

Thanks for your reply.
I want to get just the frequency at each pulse.

WalidMogo:
Thanks for your reply.
I want to get just the frequency at each pulse.

The frequency will be 40kHz.

TheMemberFormerlyKnownAsAWOL:
The frequency will be 40kHz.

Yes I know, How would I show it somehow? or atleast get a digital output when there are waves?

To capture 40 kHz waves, you need a much more sophisticated circuit. You would need at minimum an amplifier capable of responding to ultrasonic frequencies, most likely followed by a precision rectifier and peak detector, or fast digital sampling of the amplified signal.

jremington:
To capture 40 kHz waves, you need a much more sophisticated circuit. You would need at minimum an amplifier capable of responding to ultrasonic frequencies, most likely followed by a precision rectifier and peak detector, or fast digital sampling of the amplified signal.

Thank you so much for your reply.
Okay I will try to do that. Let's suppose that it worked, now how would I get exactly the frequency? because the whole purpose of this project is to get different kinds of ultrasonic waves and identify them by frequency, the 40kHz pulses from HC-SR04 are just for testing.

Hack a bat detector?