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 ...