stuck with my project please help

i am using raspberry pi and arduino to create a project on iot. now when i make a gpio pin of pi high it also make a pin of arduino low....which is connected to the 4 channel relay board. now the problem is...i am using 3 of 4 relays. but cant on the 3 relays at a time...to on the third one i need to keep one of the 3 relays off...i am using external power supply for relay...

fan_light.ino (1.48 KB)

Your thoughts are hard to follow. Care to slow down, show more information in the post, give a clearer description of your circuit, and don't attach a short sketch. Read the post called How to use this forum - please read. It will help you get the best possible help from the crowd here.

    if(state_gpio1==HIGH)
      {
        if(f1==0)
        {
          digitalWrite(9,LOW);
          f1=1;
        }
        else
        {
        }
      } 
    else if(state_gpio1==LOW)
     {
        digitalWrite (9,HIGH); 
        f1=0;
     }

Empty else blocks are useless. Exercise your right to delete them.

What this code is doing is setting f1 to state_gpio1 and writing the opposite state to pin 9.

It would require a lot less code to just do that.

   f1 = state_gpio1;
   digitalWrite(9, !f1);

Of course, it is not clear why you need two copies of the state of a pin, when both go out of scope at the end of loop(), so that snippet of your code could really be:

   digitalWrite(9, !digitalRead(4));

In fact, your whole loop function could be:

void loop()
{
   digitalWrite(9, !digitalRead(4));
   digitalWrite(10, !digitalRead(5));
   digitalWrite(11, !digitalRead(6));
}

We really do need to see a schematic, because it appears that you have a hardware problem in addition to way too much code.