Turning on a Transducer

Hello everybody,

im currently working on a project, which is basically trying to build an acoustic levitator, using 2 ultrasonic transducers. ive got my arduino connected to an h-bridge which is connected to my two transducers. as for the code, im using this:

int EnPin = 2;
int DirPin = 3;
const int EnTime = 2.5;
const int DirTime = 10;

void setup() {
  pinMode(EnPin, OUTPUT);
  pinMode(DirPin, OUTPUT);
}

void loop() { 
    digitalWrite(EnPin, HIGH);
    delayMicroseconds (EnTime);
    digitalWrite(EnPin, LOW);
    delayMicroseconds (DirTime);
    digitalWrite(DirPin, HIGH); 
    digitalWrite(EnPin, HIGH);
    delayMicroseconds (EnTime);
    digitalWrite(EnPin, LOW);
    delayMicroseconds (DirTime);
    digitalWrite(DirPin, LOW); 
}

the "DirPin" is attached to the Direction Pin on the h-bridge, and the "EnPin" to the Enable Pin on the h-bridge
now when i turn on the programm, it does actually make a sound, but i can still hear it, which obviously means, that my transducers are not running on 40khz which they should. my question is where did i make a mistake? is it because of the h-bridge or because of my programming? thanks for any kind of help :slight_smile:

const int EnTime = 2.5;

An integer does not have decimal points!!!!!

Paul

Paul_KD7HB:
const int EnTime = 2.5;

An integer does not have decimal points!!!!!

Paul

oh well i didnt know that since im very very new to programming :x
thanks for letting me know :]
i now changed the times and the best results i can get is by setting both times to 10. but i can still clearly hear the sound, and by trying to measure the frequency, im getting around 17kHz. which makes no sense to me, since with those numbers i should get around 25kHz...

Are you sure about your ultrasonic transducers ?

-Most are designed to run at one single frequency.

  • you probably can’t hear above 17khz.