Trying to trigger two audio file with two different ultrasonic sensor

I am trying to trigger two audio file with two different ultrasonic sensor. I use MicroSd Card module & two sonar sensor. Condition is when sonar 1 get objects less then 50cm “1.wav” aduio will play. When sonar 2 get objects less then 20cm then “2.wav” aduio will play.

But the problem is when any of Sonar gets objects on it’s range . Arduino play two audio (1.wav & 2.wav) at same time.

Whats its the problem ?

Connection between Micro SD Card Module and Arduino UNO:

//4 >>>>>>>>>>> CS

//11 >>>>>>>>>> MOSI

//12 >>>>>>>>>> MISO

//13 >>>>>>>>>> SCK

//5v >>>>>>>>>> 5v

//Gnd >>>>>>>> Gnd

//9 >>>>>>>>> PWM Audio Out (Speaker)

(Sonar 1)

Tring - 2
Echo - 3

(Sonar 2)

Tring - 6
Echo - 7

Here is the Code:

#include <SD.h> //include SD module library
#include <TMRpcm.h> //include speaker control library
#include <SPI.h>
#include <Ultrasonic.h>

Ultrasonic ultrasonic1(12, 13); //Sonar 1
int distance1;
Ultrasonic ultrasonic2(7, 6); //Sonar 2
int distance2;

#define SD_ChipSelectPin 4 //define CS pin

TMRpcm tmrpcm; //crete an object for speaker library

void setup() {

tmrpcm.speakerPin=9;
// start the serial console
Serial.begin(9600);

if(!SD.begin(SD_ChipSelectPin))
{
Serial.println(“SD fail”);
return;
}
tmrpcm.setVolume(5);
tmrpcm.play(“1.wav”);
tmrpcm.play(“2.wav”);
tmrpcm.pause();

}

void loop() {

if (distance1 < 50)

{

Serial.println (" Person Detected ");

Serial.print (" Distance= ");

Serial.println (distance1);

digitalWrite;
tmrpcm.play(“1.wav”);

delay (1500);

}

if (distance2 <= 20)

{

Serial.println (" Person Detected ");

Serial.print (" Distance= ");

Serial.println (distance2);

digitalWrite;
tmrpcm.play(“2.wav”);

delay (1500);

}

else {

Serial.println (" No One There ");

Serial.print (" Distance= ");

Serial.println (distance1);

}

}

Forum_post.ino (1.51 KB)

Please edit your post to add code tags ("</>" button).

You don’t appear to read either distance1 or distance2.

They are therefore both zero.

@TheMemberFormerlyKnownAsAWOL

why brother? I use Ultrasonic library .

What is the possible solution? Plz help i am noob in arduino.

You’re not reading either sensor, so both distance1 and distance2 remain with their default values of zero.

Zero is less than fifty, and zero is less than twenty.

ThisdigitalWrite; does absolutely nothing.

(I’m pretty certain you’re not my brother - he isn’t at all interested in electronics)

Plz help i am noob in arduino.

A good way to get started is by reading and following the directions in the "How to use this forum" post.