Use of 2 ultrasonic sensors that send signals via Bluetooth to notify through an android application

Hello, I have a problem with the ultrasonic sensors that when I want to use 2 within this same program and send everything via Bluetooth to an already created application, one works individually but the other when activated sends the signal to the two sensors, I don't even know if there is any option to be able to make them work individually and have the application detect both, since I tried several ways and this is the closest result I have gotten

My code is this

const int trigPin = 3;
const int echoPin = 2;
long duration, cm;
const int trigPinn = 4;
const int echoPinn = 5;
long durationn, cmm;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
  pinMode(trigPinn, OUTPUT);
  pinMode(echoPinn, INPUT);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  cm = (duration / 2) / 29.1;

  digitalWrite(trigPinn, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPinn, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPinn, LOW);

  durationn = pulseIn(echoPinn, HIGH);

  cmm = (durationn / 2) / 29.1;

  if (cm < 10) {
    Serial.print("b");

  }   else {
      if (cmm > 10) {
      Serial.print("a");

  }   else {
      Serial.print("c");
  }
  }
  delay(400);
}
const int trigPin = 3;
const int echoPin = 2;
long duration, cm, durationn, cmm;
const int trigPinn = 4;
const int echoPinn = 5;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(trigPinn, OUTPUT);
  pinMode(echoPinn, INPUT);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  cm = (duration / 2) / 29.1;
  if (cm > 0) {
    if (cm < 10)Serial.print("a");
    else Serial.print("b");
  }
  delay(200);

  digitalWrite(trigPinn, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPinn, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPinn, LOW);
  durationn = pulseIn(echoPinn, HIGH);
  cmm = (durationn / 2) / 29.1;
  if (cmm > 0) {
    if (cmm < 10 )Serial.print("c");
    else Serial.print("d");
  }
  delay(200);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.