Arduino code:
#include "NewPing.h"
#define TRIGGER_PIN12 12
#define ECHO_PIN13 13
#define MAX_DISTANCE 366 // 366 IS 12FT
#define TRIGGER_PIN10 10
#define ECHO_PIN11 11
#define TRIGGER_PIN8 8
#define ECHO_PIN9 9
#define TRIGGER_PIN7 7
#define ECHO_PIN6 6
NewPing sonar(TRIGGER_PIN12, ECHO_PIN13, MAX_DISTANCE);
NewPing sonar1(TRIGGER_PIN10, ECHO_PIN11, MAX_DISTANCE);
NewPing sonar2(TRIGGER_PIN8, ECHO_PIN9, MAX_DISTANCE);
NewPing sonar3(TRIGGER_PIN7, ECHO_PIN6, MAX_DISTANCE);
float fgDurationFront;
float fgDurationBack;
float fgDurationRight;
float fgDurationLeft;
float fgFront;
float fgBack;
float fgRight;
float fgLeft;
int iIterations = 5;
void setup() {
Serial.begin(9600);
}
void loop() {
fgDurationFront = sonar.ping_median(iIterations);
fgDurationBack = sonar1.ping_median(iIterations);
fgDurationRight = sonar2.ping_median(iIterations);
fgDurationLeft = sonar3.ping_median(iIterations);
// determin distance from duration
// 343 metres per second is speed of sound
fgFront = (fgDurationFront / 2) * 0.0343;
fgBack = (fgDurationBack / 2) * 0.0343;
fgRight = (fgDurationRight / 2) * 0.0343;
fgLeft = (fgDurationLeft / 2) * 0.0343;
//send values to App e.g. 10.11|20.22|30.33|40.44\n
Serial.print(fgFront, 2);
Serial.print("|");
Serial.print(fgBack, 2);
Serial.print("|");
Serial.print(fgRight, 2);
Serial.print("|");
Serial.print(fgLeft, 2);
Serial.println();
delay(1000);
}