Skip to content

Instantly share code, notes, and snippets.

@joe-speedboat
Last active August 8, 2018 06:54
Show Gist options
  • Save joe-speedboat/6a1c36016e12563de303e6534201b355 to your computer and use it in GitHub Desktop.
Save joe-speedboat/6a1c36016e12563de303e6534201b355 to your computer and use it in GitHub Desktop.
Ultrasonic pest repeller
int speaker = 0; // speaker pin (pwm)
long int pick_freq = 22000;
int duration = 100; // ms to play tone
int led = 13; // led operating status pin
void setup() {
pinMode(speaker, OUTPUT);
Serial.begin(9600);
Serial.println("ATMEGA BOOTING...");
}
void loop() {
pick_freq = random(22000, 64000);
duration = random(100, 3000);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.print("Tone: Freq: "); Serial.print(pick_freq); Serial.print(" / Duration: "); Serial.println(duration);
tone(speaker, pick_freq);
delay(duration);
noTone(speaker);
digitalWrite(led, LOW); // turn the LED off (LOW is the voltage level)
delay(duration * 0.1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment