Getting seemingly random numbers in the Serial Monitor

I'm trying to build an ultrasonic detector and data logger that I can deploy in the field to tell me if any bats are making ultrasonic noise in a cave at night. I'm fairly new at this, so I hope you'll be patient with me.

I'm using an Arduino Nano and a Kobitone 40khz transducer

int inputPin = A0;
int val = 0;

void setup() {
pinMode(inputPin, INPUT);


void loop() {
val = analogRead(inputPin);

There's no info that I could find online about it, but since it only has two pins, I assume one is ground, one is signal. But when I plug it in, I get seemingly random numbers on the monitor and continue to get random numbers after the transducer is unplugged.

Maybe I misunderstood what the two pins actually are for?

Thanks for your help!

No amplification?

Nope, wasn't sure if I needed it. Is it because the current generated by the tiny vibrating speaker isn't large enough to be detected by the arduino board without amplification? I figured if that was the case then the serial monitor would just read 0 over and over again...

Maybe you've got very loud bats.
Which particular species emits at 40kHz?

I though bat echolocation was in the 100 kHz+ range, not 40 kHz.

The major problem with your setup is that the Arduino's analogRead function takes over 100 us to complete. That gives an absolute absolute maximum of less than 10,000 reading per second if you do NOTHING ELSE besides analogReads. According to the Nyquist sampling theorem, your sampling frequency needs to be at least twice the highest frequency you're trying to measure. Bat echolocation being as high as it is, you stand no chance of measuring its frequency with an Arduino. You will need some external hardware, and likely a better transducer. Your transducer only has a 3 kHz bandwidth. You will probably need a very wideband transducer to detect bat frequencies.

I'd search for a good transducer first, and put everything else off until you find a good one. Your transducer is EVERYTHING.

This isn’t my specialty, but I think several species use frequencies in the 40khz range, including several myotis species and brazilian free tails. they use frequency sweeps that can cover around 20khz. I don’t necessarily need to record what frequencies are present (as we have an AnaBat unit that does that very accurately). I just need a unit that detects spikes in ultrasonic noise so that we can deploy it in a cave overnight and see if bats are present.

Any other ideas why these random numbers get spit out, even when theres no sensor connected?

Floating input, maybe? I'm not sure how those transducers work, exactly.

EDIT: You'll need external hardware attached to the transducer, for sure. An amplifier at a minimum, and maybe a frequency discriminator of some kind. An Arduino Nano is going to have a very hard time trying to measure 40 kHz frequencies on its own, especially if there's background noise. You'll need a sampling rate of 80,000 Hz at a bare minimum in order to sample that properly. The ATmega328P datahsheet recommends a maximum ADC sampling frequency of about 15 kHz. Any more and you start losing accuracy in the reading, which will make it harder to discriminate the frequency you are looking for.