Programação TCC - 2 sensores HC-SR04 - Problemas - URGENTE

Hello people are you okay?

My name is Pedro and I am studying the 4th and last module of my mechatronics technician.

I am developing an electronic cane for my tcc that is able to detect objects ahead and warn the person who uses it with a beep and a vibracall indicating the distance

There are two sensors, one below the cane (sensor1) and the other one in the middle (sensor2)

When sensor1 detects objects it emits a beep

When sensor2 detects objects it triggers vibracall

The two sensors use their own delay

PROBLEMS: In practice when there is a delay in the sensor1 there will also be a delay in the sensor2 and vice versa, thus preventing the beep and / or the vibracall from working individually.

SOLUTION: Make the sensors work individually, but how?

Following the schedule:

// Ultrasonic - Version: Latest
#include <Ultrasonic.h>

#define vibra 3
#define bip 4

#define pino_trigger 6
#define pino_trigger2 8

#define pino_echo 5
#define pino_echo2 7

Ultrasonic ultrasonic(pino_trigger, pino_echo);//sensor 1
Ultrasonic ultrasonic2(pino_trigger2, pino_echo2);//sensor 2

float s1;
float s2;

void setup()

{
Serial.begin(9600);
Serial.println("Start");
}

void loop()
{
//Le as informacoes do sensor 1
long microsec = ultrasonic.timing();
s1 = ultrasonic.convert(microsec, Ultrasonic::CM);

//Le as informacoes do sensor 2
long microsec2 = ultrasonic2.timing();
s2 = ultrasonic2.convert(microsec2, Ultrasonic::CM);
delay(10);

if (s1 < 10)

{
digitalWrite(vibra, HIGH); //liga bip
}

else if ((s1 > 9)&&(s1 < 130))

{
digitalWrite(vibra, HIGH);
delay(2*(s1-10));
digitalWrite(vibra, LOW);
delay(2*(s1-10));
}

else if ((s1 > 129)&&(s1 < 300))

{
digitalWrite(vibra, HIGH);
delay(5);
digitalWrite(vibra, LOW);
delay(1600);
}

else if (s1 > 299)

{
digitalWrite(vibra, LOW);
}

//////////////////////////////////////////////////////////////////////////

if (s2 < 10)

{
digitalWrite(bip, HIGH);
}

else if ((s2 > 9)&&(s2 < 130))

{
digitalWrite(bip, HIGH);
delay(2*(s2-10));
digitalWrite(bip, LOW);
delay(2*(s2-10));
}

else if ((s2 > 129)&&(s2 < 300))

{
digitalWrite(bip, HIGH);
delay(5);
digitalWrite(bip, LOW);
delay(1600);
}

else if (s2 > 299)

{
digitalWrite(bip, LOW);
}

Serial.print(" Sensor 1: ");
Serial.print(s1);
Serial.print(" - Sensor 2: ");
Serial.print(s2);
delay(10);

}

I ask the help of those who can help, I am a beginner and thank you from now on!

Welcome to the Forum. Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Many questions can be answered by reading the documentation which is provided with the IDE, available under the help tab, or online here.

There are many other things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. One is to provide the entire code, not just a snippet. Use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Use blank lines sparingly, no more than one at a time. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Another is to give things descriptive names. Use descriptive variable names, for example "temperature" instead of "t". Don't use "magic numbers". Use compiler math to compute values so you can see where they came from (or at least document them). For example, if you see the number 73, you would be hard put to explain the significance of it. But if you see "daysPerYear/5", it is obvious. One more thing. When you work on program continuously, you become familiar with it. So many things seem obvious even if they are not spelled out explicitly. But try looking at your own code six months later. It will be as if a stranger wrote it. So write for strangers, not yourself.