Waterdispenser with 2 supersonic sensors

Hello,

How do i combine 2 Arduino sketches for the supersonic sensor?
Theire are 2 senors that do the same thing only in diffrent places
1 sensor is left other sensor is 50 cm to the right

This is 1 sketch:

#define trigger 9
#define echo 8
#define LED 13
#define MOSFET 12

float time=0,distance=0;

void setup()
{
Serial.begin(9600);

pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(LED,OUTPUT);
pinMode(MOSFET,OUTPUT);

delay(1000);
}

void loop()
{
measure_distance();

if(distance<5)
{
digitalWrite(LED,HIGH);digitalWrite(MOSFET,HIGH);
delay(10000);
digitalWrite(LED,LOW);digitalWrite(MOSFET,LOW);
delay(1000);
}
else
{
digitalWrite(LED,LOW);digitalWrite(MOSFET,LOW);
}

delay(500);
}

void measure_distance()
{
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;

}

This is the second sketch:

#define trigger 7
#define echo 6
#define LED 13
#define MOSFET 12

float time=0,distance=0;

void setup()
{
Serial.begin(9600);

pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(LED,OUTPUT);
pinMode(MOSFET,OUTPUT);

delay(1000);
}

void loop()
{
measure_distance();

if(distance<5)
{
digitalWrite(LED,HIGH);digitalWrite(MOSFET,HIGH);
delay(25000);
digitalWrite(LED,LOW);digitalWrite(MOSFET,LOW);
delay(1000);
}
else
{
digitalWrite(LED,LOW);digitalWrite(MOSFET,LOW);
}

delay(500);
}

void measure_distance()
{
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;

}

Thanks in advance!

please take a minute and read How To Use This Forum
it can be found as a sticky post at the top of every forum
pay attention to #7 about how to use Code Tags

then come back, and on the bottom right of your post is the modify button
then put your code into code tags.

#2) can you post a link to the supersonic sensors ?

ASSUMING, that your code is working......

this is not working code, but the general idea.
you need to identify each part.

what is not done is the actual loop()

#define triggerleft 9
#define echoleft 8
#define LEDleft 13
#define MOSFET 12
#define triggeright 7
#define echoright 6
#define LEDright 13
//  #define MOSFET 12  // this is the same MOSFET for both

float timeR=0,distanceR=0;
float timeL=0,distanceL=0;

void setup()
{
Serial.begin(9600);

pinMode(triggerleft,OUTPUT);
pinMode(echoleft,INPUT);
pinMode(LEDleft,OUTPUT);
pinMode(triggerright,OUTPUT);
pinMode(echoright,INPUT);
pinMode(LEDright,OUTPUT);
pinMode(MOSFET,OUTPUT);
//  pinMode(MOSFET,OUTPUT);


delay(1000);
}


void loop() {
   void measure_distance();

//  your logic needs to go here

}

void measure_distance()
{
digitalWrite(triggerleft,LOW);
delayMicroseconds(2);
digitalWrite(triggerleft,HIGH);
delayMicroseconds(10);
digitalWrite(triggerleft,LOW);
delayMicroseconds(2);
timeL=pulseIn(echoleft,HIGH);
distanceL=timeL*340/20000;

digitalWrite(triggerright,LOW);
delayMicroseconds(2);
digitalWrite(triggerright,HIGH);
delayMicroseconds(10);
digitalWrite(triggerright,LOW);
delayMicroseconds(2);
timeR=pulseIn(echo,HIGH);
distanceright=timeR*340/20000;

}
void loop() {
   void measure_distance();

Putting a function prototype there is doing nothing at all useful.

Air temperature is the major factor in the speed of sound. It is faster on a hot day than in a cool night for instance.

No, density doesn't make the difference and humidity is a magnitude less factor than temperature. Check with NASA.

You could benefit by learning about arrays of variables.

I wonder if supersonic sensors produce a sonic boom when they pass by.

The more common ultrasound sensors don't.