#define trigPin 12 #define echoPin 11 #define motorPin 3 #define buzzerPin 9 void setup() { Serial.begin (9600); pinMode(echoPin,INPUT); pinMode(buzzerPin,OUTPUT); pinMode(trigPin,OUTPUT); } void loop() { int duration, distance; digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; Serial.print(distance); Serial.println(" cm"); delay(2000); int dist=map(distance,0,400,255,0); analogWrite(motorPin,dist); //tone change of peizo buzzer done..how to //control its volume through the obstacle detected? analogWrite(buzzerPin,dist); delay(800); analogWrite(buzzerPin,LOW); delay(300);} /*vibrator output is coming as expected. but not buzzer..the hc sr04 has an echo output. which has to be read both by the vibrator and accordingly generate its output as mentioned above in the text.tried with both buzzer and motor connected to the same pin(STUPIDLY) andconfigured it as OUTPUT pin.. didn't work too.*/ A complete newcomer to arduino world.suggest changes asap