This program make toggle between two frequency based on whether you touched the sensor
Connect buzzer’s red wire to Arduino 5v and black wire to GND
#include<NewPing.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(12,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int val=digitalRead(2);
Serial.println(val);
if(val==1)
{
digitalWrite(12,HIGH);
tone(9,2000,100);
}
else
{
digitalWrite(12,LOW);
tone(9,3000,10);
}
delay(1000);
}

