I cannot find the bug in my code

So, I am trying to controll two 230V lamps (connected to relays) with two ultrasonic sensors seperatly.

#define trigPin A0 //Define the HC-SE04 triger on pin 6 on the arduino
#define echoPin A1 //Define the HC-SE04 echo on pin 5 on the arduino

#define trigPin1 A3 //Define the HC-SE04 triger on pin 6 on the arduino
#define echoPin1 A2 

#define bulb 9 //Define the relay signal on pin 9 on the arduino
#define bulb1 3 //Define the relay signal on pin 3 on the arduino

void setup()
{
Serial.begin (9600); //Start the serial monitor
pinMode(trigPin, OUTPUT); //set the trigpin to output
pinMode(echoPin, INPUT); //set the echopin to input
pinMode (bulb, OUTPUT); //set the bulb on pin 9 to output

pinMode (trigPin1, OUTPUT); //set the trigpin to output
pinMode (echoPin1, INPUT); //set the echopin to input
pinMode (bulb1, OUTPUT); //set the bulb on pin 3 to output
}

void loop()
{
  int duration, distance; //Define two intregers duration and distance to be used to save data
  int duration1, distance1;
  
  digitalWrite(trigPin, HIGH); //write a digital high to the trigpin to send out the pulse
  delayMicroseconds(500); //wait half a millisecond
  digitalWrite(trigPin, LOW); //turn off the trigpin
 
  digitalWrite(trigPin1, HIGH); //write a digital high to the trigpin to send out the pulse
  delayMicroseconds(500); //wait half a millisecond
  digitalWrite(trigPin1, LOW); //turn off the trigpin
  {
    duration = pulseIn(echoPin, HIGH); //measure the time using pulsein when the echo receives a signal set it to high
    distance = (duration/2) / 29.1; //cm
  
    duration1 = pulseIn(echoPin1, HIGH);
    distance1  = (duration1/2) / 29.1;

    if (distance < 13) //if the distance is less than 13 CM
    {
      digitalWrite(bulb, LOW); //turn on the light
    }
    else
    {
      digitalWrite(bulb, HIGH); //turn off the light
    }
    
    if (distance1 < 13)
    {
      digitalWrite(bulb1, LOW); //turn on the light
    }
    else
    {
      digitalWrite(bulb1, HIGH); //turn off the light
    }
  }
  {
  Serial.print(distance1); //Dispaly the distance on the serial monitor
  Serial.println(" CM"); //in centimeters
  delay(500); //delay half a second
  }
}

Where is trigPin declared in the sketch ?

It is there I accedentaly fergot to copy it here.

The best way to copy a sketch to the forum is to use Edit/Copy for Forum in the IDE. It even adds the code tags for you

Try it now and copy the whole sketch into a new reply. What are the symptoms of the bug ?

That's the thing it should be working there is no default, the lights are just not working when they should be.

I see that instead of posting the revised sketch in a new reply as I suggested, you have updated your first post thus making nonsense of my comments on it

Thankx for the help!

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