Using Ping sensor-Arduino Uno -Wav Trigger

Hello, I'm new to posting on this forum and I'm having a heck of a time moving forward on my project so here's hoping someone has been before where I am now! I'm relatively new to Arduinos having worked on projects involving midi/ping sensors and blinking leds.

My latest project involves the Robertsonics Wav Trigger, using a Ping sensor and Arduino Uno to trigger wav files loaded onto the Wav Trigger. I've successfully uploaded the code in the tutorial on "Arduino serial control" Help – robertsonics. I've been trying to patch together some code by combining the code from the tutorial and the Ping example code in the Arduino library. However I can't dig out the relevant parts from the Robertsonics tutorial for my project. I feel I need an even simpler version of the code to be able to make sense of it. I very simply want to have the Ping sensor trigger a multitude of sounds whenever people move past the sensors at various distances.

Has anyone ever used the Wav Trigger in this way? Is there a simpler code to work with than what the tutorial provides to get me started?

I’m including the code that I have figured out so far. Right now my problem is that I have trigger number 1 looping constantly until the sensor senses something near it. This is what I want!! However once the sensor is activated and Trigger 1 is deactivated, I would like Trigger 14 to be activated and begin looping until there is nothing in from of the sensor, and Trigger one goes back to looping.

Any suggestions for what I’m doing wrong?

The circuit:
  - +V connection of the PING))) attached to +5V
  - GND connection of the PING))) attached to ground
  - SIG connection of the PING))) attached to digital pin 7
  - GND of WAv Trigger to GND of Arduino
  - TX of Arduino to RX of Wav Trigger
  - PIN 11 of Arduino to  T1 on WAV Trigger
  - PIN 4 of Arduino to PIN 14 on WAV Trigger

  
*/

// *******************************************************************************************************


#define fP 7 //Pin the ping sensor is connected to


void setup() {
 pinMode(11, OUTPUT);  
 pinMode(4, OUTPUT);  
}

void loop() {
  
  if (ping() >100) {
   digitalWrite(11, LOW);          // set the PIN 11 off
   digitalWrite(14, HIGH);           // set the PIN 14 on
 
   }
 else {
   digitalWrite(11, HIGH);         // set the PIN on
   digitalWrite(14, LOW);          // set the PIN 14 off
 }


}
   

int ping() //Get CM to obstacle in front of the sensor
{
 long duration;
 pinMode(fP, OUTPUT);
 digitalWrite(fP, LOW);
 delayMicroseconds(2);
 digitalWrite(fP, HIGH);
 delayMicroseconds(15);
 digitalWrite(fP, LOW);
 delayMicroseconds(20);
 pinMode(fP, INPUT);
 duration = pulseIn(fP, HIGH);
 return duration / 29.0 / 2.0;
}

Right now my problem is that I have trigger number 1 looping constantly

No idea what “trigger 1” is.

However once the sensor is activated and Trigger 1 is deactivated

No idea what that means, either.

What ultrasonic sensor are you using? Most of them use separate trigger and echo pins.

Thank you PaulS for your response.

When I am referring to Trigger 1, I am referring to the trigger labelled T1 on the Wavtrigger. I am using a 3 pin Ping sensor from Parallax. I think you are referring to a 4 pin Ping which uses separate trigger and echo pins.

Basically I want to assign one trigger to be repeating tracks 1-14 on random until the ping sensor senses a person at a designated distance. In response I would like T1 on the WavTrigger (the trigger playing tracks 1-14 on random) to turn off and have T16 on the Wavtrigger turn on and repeat until the sensor no longer senses a person in the designated range...setting up the function of T1 all over again.

I’ve finally solved the code for my project!

     Uno           WAV Trigger
     ===           ===========
     GND  <------> GND
     Pin9 <------> RX


    The circuit for the 3 pin PING:
    - +V connection of the PING))) attached to +5V
    - GND connection of the PING))) attached to ground
    - SIG connection of the PING))) attached to digital pin 7 */

// ****************************************************************************

#include <AltSoftSerial.h>    // Arduino build environment requires this
#include <wavTrigger.h>

// this constant won't change.  It's the pin number
// of the sensor's output:
const int pingPin = 7;

wavTrigger wTrig;             // Our WAV Trigger object


// ****************************************************************************

void setup() {
  
  // Serial monitor
  Serial.begin(9600);

  // If the Arduino is powering the WAV Trigger, we should wait for the WAV
  //  Trigger to finish reset before trying to send commands.
  delay(1000);

  // WAV Trigger startup at 57600
  wTrig.start();
  delay(10);
  
  // Send a stop-all command and reset the sample-rate offset, in case we have
  //  reset while the WAV Trigger was already playing.
  wTrig.stopAllTracks();
  wTrig.samplerateOffset(0);  
}

// ****************************************************************************

void loop() {

  // establish variables for duration of the ping, and the distance result
  // in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH pulse
  // whose duration is the time (in microseconds) from the sending of the ping
  // to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);



   if (cm >= 10 && cm <= 30) {
   wTrig.trackPlayPoly(16);               // Start Track 16 poly
   delay(10000);
}  
    
   else {  
   wTrig.trackPlayPoly(2);               // Play 1st note
   delay(1000);
   wTrig.trackPlayPoly(3);               // Play 2nd note
   delay(1000);
   wTrig.trackPlayPoly(4);               // Play 3rd note
   delay(1000);  
   
  }

}

long microsecondsToInches(long microseconds) {
  // According to Parallax's datasheet for the PING))), there are 73.746
  // microseconds per inch (i.e. sound travels at 1130 feet per second).
  // This gives the distance travelled by the ping, outbound and return,
  // so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the object we
  // take half of the distance travelled.
  return microseconds / 29 / 2;
}