help in my project ...

hi everybody
my project is ... 3 ultrasonic with 4 pins... and three 8 ohm speakers (0.25W)...
I wrote the code but I want to know which pin I can put the third speaker???
is this code right with the correct pins?
I just used 100 ohm for each speaker...how to make the speakers loud ? or how can I control the volume ( if that possible)?
the code....

//define the pins for ultrasonic sensor here
#define trigPin 12
#define echoPin 13
#define trigPin 10
#define echoPin 11
#define trigPin 8
#define echoPin 9



//setup trig is output and echo is input for the sound. Read serial fastest possible speed
void setup() {
    Serial.begin (115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

//below methods for beep speed
void beepFast(){
   // play a note on pin 7&6 for 200 ms:
  tone(7, 440, 200);
  delay(50);
tone(6, 494, 500);
  delay(50);

  // turn off tone function for pin 7&6:
  noTone(7);
  delay(300);
  noTone(6);
  delay(300);

}

void beepSlow(){
  tone(7, 440, 200);
  delay(500);
  noTone(7);
  delay(300);

tone(6, 494, 500);
  delay(500);
  noTone(6);
  delay(300);

}

void beepMedium(){
  tone(7, 440, 200);
  delay(200);
  noTone(7);
  delay(300);


tone(6, 494, 500);
  delay(200);
  noTone(6);
  delay(300);

}

//no beep here
void beepNo(){
  noTone(7);
  delay(300);
  noTone(6);
  delay(300);

}

//send a pulse and calculate how long it took to travel
void loop() { 
   int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

//then check the distance and beep if it is in the range
   if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
  }
  else if (distance >=0 && distance <=30){
    beepFast();
    Serial.print(distance);
    Serial.println(" cm");
  }
else if (distance >=31 && distance <=60) {
  Serial.print(distance);
    Serial.println(" cm");
beepMedium();
}
else if (distance >=61 && distance <= 90){
  Serial.print(distance);
    Serial.println(" cm");
beepSlow();
}
else {
   beepNo();
     Serial.print(distance);
    Serial.println(" cm");
}

}

thanks in advanced ...

#define trigPin 12
#define echoPin 13
#define trigPin 10 Use different names
#define echoPin 11 -------------------
#define trigPin 8 -------------------
#define echoPin 9 -------------------

//setup trig is output and echo is input for the sound. Read serial fastest possible speed
void setup() {
Serial.begin (115200);
pinMode(trigPin, OUTPUT); I believe you have more than two pins
** pinMode(echoPin, INPUT);**
}

tone(7, 440, 200); I'm pretty sure you need to turn one off before turning another one on
delay(50);
tone(6, 494, 500);
delay(50);

you r right but I want all the speakers works at the same time .... they are with different tones ... bcoz of my project idea ...
&
my project is ... 3 ultrasonic with 4 pins... and three 8 ohm speakers (0.25W)...
I wrote the code but I want to know which pin I can put the third speaker??? can I put it in pin 5?
is this code right with the correct pins?
I just used 100 ohm for each speaker...how to make the speakers loud ? or how can I control the volume ( if that possible)?

You cant have all the speakers work at the same time, the best you can do is switch between them very fast.
Also Pin 5 should be fine.

ok thanks I did a (300) delay... will try pin5 today
and how can i make the speaker loud? can I control the volume?

You would need to make an amplifying circuit. Some TLC272 or 386 OP Amps should work nicely.

ok there is no easier way?... coz I don't have all the components... :frowning:

Radio shack

OK THANKS A LOT .. :slight_smile: