how to set output pins to low at start?I use this code but it does not works...

int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;
int relay5 = 6;
int relay6 = 7;
int relay7 = 8;
int relay8 = 9;
void setup()
{
Serial.begin(9600);
Serial.flush();
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
pinMode(relay1, OUTPUT);//set relay pins as an output means arduino pin 2 give output...
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);

}
void loop()
{

while (Serial.available()){
delay(10);

char bt = Serial.read();
switch (bt)
{
case 'C':
digitalWrite(relay1, HIGH);
break;
case'c':
digitalWrite(relay1,LOW);
break;
case 'B':
digitalWrite(relay3,HIGH);
break;
case'b':
digitalWrite(relay3,LOW);
break;
case 'A':
digitalWrite(relay2,HIGH);
break;
case'a':
digitalWrite(relay2,LOW);
break;
case 'I':
digitalWrite(relay4,HIGH);
break;
case'i':
digitalWrite(relay4,LOW);
break;
case 'D':
digitalWrite(relay5,HIGH);
break;
case'd':
digitalWrite(relay5,LOW);
break;
case 'F':
digitalWrite(relay6,HIGH);
break;
case'f':
digitalWrite(relay6,LOW);
break;
case'G':
digitalWrite(relay7,HIGH);
break;
case'g':
digitalWrite(relay7,LOW);
break;
case'E':
digitalWrite(relay8,HIGH);
break;
case'e':
digitalWrite(relay8,LOW);
break;
case'H':
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
break;
case'h':
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
break;
case'X':
digitalWrite(relay1,HIGH);
digitalWrite(relay4,HIGH);
break;
case'x':
digitalWrite(relay1,LOW);
digitalWrite(relay4,LOW);
break;
case'Y':
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay8,HIGH);
break;
case'y':
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay8,LOW);
break;
case'l':
digitalWrite(relay2,LOW);
digitalWrite(relay7,LOW);
case'L':
digitalWrite(relay2,HIGH);
digitalWrite(relay7,HIGH);
break;

bt="";
}
delay(100);
}
}

Describe what is wrong run you run the code

Define the pins as OUTPUT before you set them as high or low.

When arduino power its output pins set HIGH. I want to set these pins LOW when Arduino starts.Also I try above code but its not working and also the same result show arduino output means digitalWrite again set to HIGH.Thats my problem.I dont know how to solve this problem.

what Arduino? all Arduinos with Atmel chips have pins set to INPUT at start. perhaps the relay modules switch on at LOW signal.

Try pulldowns on the outputs.

Please remember to use code tags when posting code

I'd bet your relay board is "low true", meaning the relays are energized when the pin is LOW instead of HIGH and you have your load connected to NC instead of NO, am I right?

Noo...... relay board is ON when digitalWrite(x,HIGH), and I connected the wire to Normally open (NO) not to the NC.... :o :confused:

Are you using individual relays or a relay module? Please post a link to either and a wiring diagram.

There is no any problem with wire connections just I face the problem in programming.I have 8 channel relay module.The schematic is such as each single wire is connected to the NO and I give 220VAC to the common.In short its not the issue of wiring. Just I need is to set arduino with no outputs to HIGH until I command it .Just it Thanks.

 void setup() 
 {
  Serial.begin(9600);
  Serial.flush();
  digitalWrite(relay1,LOW); 
 digitalWrite(relay2,LOW); 
 digitalWrite(relay3,LOW); 
 digitalWrite(relay4,LOW); 
 digitalWrite(relay5,LOW); 
 digitalWrite(relay6,LOW); 
 digitalWrite(relay7,LOW); 
 digitalWrite(relay8,LOW);

Rather than faff about turning off the pull-ups, why not make the pins outputs as soon as possible?

Or use external pull-downs.
I believe I've already mentioned this.

What is the state of the relays after startup and before you type a character? How is the relay module powered? Not from the Arduino's 5V pin I hope.

Actually I am not aware to" pull up "But your code is works but know I face another problem.The problem is when I give command to HIGH.It remains LOW.Because I use this code,can you tell what should I do now?

//home_automation
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;
int relay5 = 6;
int relay6 = 7;
int relay7 = 8;
int relay8 = 9;
void setup()
{
Serial.begin(9600);
Serial.flush();
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);

}
void loop()
{

while (Serial.available()){
delay(10);

char bt = Serial.read();
switch (bt)
{
case 'C':
digitalWrite(relay1, HIGH);
break;
case'c':
digitalWrite(relay1,LOW);
break;
case 'B':
digitalWrite(relay3,HIGH);
break;
case'b':
digitalWrite(relay3,LOW);
break;
case 'A':
digitalWrite(relay2,HIGH);
break;
case'a':
digitalWrite(relay2,LOW);
break;
case 'I':
digitalWrite(relay4,HIGH);
break;
case'i':
digitalWrite(relay4,LOW);
break;
case 'D':
digitalWrite(relay5,HIGH);
break;
case'd':
digitalWrite(relay5,LOW);
break;
case 'F':
digitalWrite(relay6,HIGH);
break;
case'f':
digitalWrite(relay6,LOW);
break;
case'G':
digitalWrite(relay7,HIGH);
break;
case'g':
digitalWrite(relay7,LOW);
break;
case'E':
digitalWrite(relay8,HIGH);
break;
case'e':
digitalWrite(relay8,LOW);
break;
case'H':
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
break;
case'h':
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
break;
case'X':
digitalWrite(relay1,HIGH);
digitalWrite(relay4,HIGH);
break;
case'x':
digitalWrite(relay1,LOW);
digitalWrite(relay4,LOW);
break;
case'Y':
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay8,HIGH);
break;
case'y':
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay8,LOW);
break;
case'l':
digitalWrite(relay2,LOW);
digitalWrite(relay7,LOW);
case'L':
digitalWrite(relay2,HIGH);
digitalWrite(relay7,HIGH);
break;

bt="";
}
delay(100);
}
}

So you're saying that setting them low turns the relay off - it just doesn't happen immediately when your sketch runs? That's expected, because during the time right after a reset, the bootloader runs, and during that time, the pins are INPUT. If the relay board has them connected to the gate of a mosfet (not unreasonable) the pins are floating and will pick up noise from the environment, potentially going high. To prevent this, use a pulldown resistor (10k should be fine, but really anything within an order of magnitude of that is fine) between the relay pins and ground, this will hold the pin in a defined state when it's not being driven.

You really need to start using code tags.
My scrolling thumb hurts :frowning:

You still didn't get that you must set pinMode first, before using digitalWrite