i want to dsign an ultrasonic insect repeller.
i want frquancies from 40 to 75 , someone helped me designing the following code:
int value,micro;
void setup() {
// put your setup code here, to run once:
pinMode(7,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
value=analogRead(0);
// using the following rule --> frequency (Hz) =1 /( time(second ) * 2)
this code must produce frequencies from 40 to 75 kHz, which electronic can i use to produce this frequency.
i want something that can cover 100m^2 for example.
75KHz is a period of 13.333 microseconds (uS)
analogRead takes 110uS.
digitalWrite takes 4uS, and loop takes several uS (I think I've measured 12), and the map function will add more.
So I think you will want some code that runs in a while loop inside of the main loop,
add a push button to interrrupt and read the analog and set the delayMicroseconds value, and use Direct Port Manipulation to toggle the IO pin instead of digitalWrite.
void loop(){
while (1){
delayMicroseconds(micro); // 4 is minimum
PORTD = PORTD & ob011111111; // output D7 low - try PIND = 0b10000000; also
delayMicroseconds (micro);
PORTD = PORTD | 0b10000000; // output D7 high - try PIND = 0b10000000; also
} // end while
} // end loop
My toneAC library was designed to work at very high frequencies, 2.66 MHz even! As a bonus, it will also drive the two ultrasonic leads in a push/pull manor which will generate much louder output (almost twice as loud). So, you'll be able to scare those little buggers from further away.
Here's an example sketch that will loop from 40 kHz to 75 kHz. You would connect your speaker leads to pins 9 & 10 if you're using an Arduino Uno. If you're using different hardware, you should check the toneAC website to see what pins to use. You'll also (obviously) need a transducer that can generate sufficient output in this frequency range (I have some that are designed to peak at 40 kHz and 60 kHz).
#include <toneAC.h>
void setup() {}
void loop() {
for (unsigned long freq = 40000; freq <= 75000; freq += 20) {
toneAC(freq); // Play the frequency (40 kHz to 75 kHz in 20 Hz steps).
delay(2); // Wait 2 ms so it will generate output.
}
}