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!