door alarm uno

hi was wondering if someone can help me with the door alarm code
i have 2 doors,and each one have a reedswitch,in my code i have one
door working ,but how do i add the other one to the code..please help? =(heres what i
have already.

int door1 = 2;
int led1 = 13;

void setup()
{
pinMode(door1,INPUT);

pinMode(led1,OUTPUT);

}

void loop()
{
if (digitalRead(door1)== LOW)

{
digitalWrite(led1,LOW);

}
else
{
digitalWrite(led1,HIGH);

}

}

What do you want the second one to do, exactly the same as the first one or should the program do something only if they are triggered within a time period, or if the doors are both open at the same time ?

i want the arduino to sence each door seperatly

Put the door2 code immediately after the door1 code in the loop() function

start of loop
  read door1 sensor and act on it
  read door2 sensor and act on it
end of loop

i think i tried that it didnt work,is there any way you can show me by adding it to the code i put hereplease?

Better still, post your code that didn't work and we can discuss why and put it right.

ok sounds goodhere its and i have tried other ways also with no luck thank you..

int door1 = 2;
int door2 = 3;
int led1 = 13;

void setup()
{
pinMode(door1,INPUT);
pinMode(door2,INPUT);
pinMode(led1,OUTPUT);
}
void loop()
{
if (digitalRead(door1)== LOW)
if (digitalRead(door2)== LOW)
{
digitalWrite(led1,LOW);
}
else
{
digitalWrite(led1,HIGH);
}

}

Look more closely at the pseudo code that I posted. I suggested that you read one sensor and act on it THEN read the second one and act on it.

But now that we know that the same LED is to be lit if either door sensor is triggered you can do this

start of loop
  if door1 sensor activated OR door2 sensor activated
    turn on the LED
  end of if
  else
    turn off the LED
  end of else
end of loop

Your code is missing the OR (Note, it is not written like that in code)
See && - Arduino Reference for an example of how to do it.

What is the body of this code:

  if (digitalRead(door1)== LOW)

In other words, how much code will be executed if this statement evaluates to true? How much code will be skipped if this statement evaluates to false?

Think about the advice that we give people that says that if statements should always be followed by curly braces, even when the body of the if (or else) statement only contains one line of code.

im sorry i must be stupid but its not working ...you mean like this?

int door1 = 1;
int door2 = 2;
int led1 = 3;

void setup()
{
pinMode(door1,INPUT);
pinMode(door2,INPUT);
pinMode(led1,OUTPUT);
}

void loop()
{
if (digitalRead(door1) == HIGH || (digitalRead(door2)== HIGH;
{
digitalWrite(led1,HIGH);
}

else
{
digitalWrite(led1,LOW);

}
}

The test in the if statement must be fully enclosed by brackets. Brackets may also be used within the test to make it more obvious what is being tested, but there is never an semi-colon at the end of the if statement.

You are very close to getting it right. In its clearest form it would be

if (digitalRead(door1) == HIGH) || (digitalRead(door2) == HIGH)

Another piece of advice. Although you can put the action part of the if on the same line as the test if only one action statement will be carried out and you can then leave out the curly brackets, it is best to use the rule that the actions from an if must be within a pair of curly brackets and that each curly bracket must be on its own line as you have done in your code.

You really should not be using the Serial pins for input or output. You should be using them for debugging.

There is a menu item on the Tools menu, Auto Format, that you need to learn to love.

thanks for that tip...any more? as i am very new to this thanks.?