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);
}