pushbutton permanently stops alarm

here´s my code,

int inPin1 = 7;
int inPin2 = 8;
int relayPin = 12;
int sensorPin = 2;
void setup() {
   pinMode(sensorPin, INPUT);
  pinMode(inPin1, INPUT);
  pinMode(inPin2, INPUT);
  pinMode(relayPin, OUTPUT);
}

void loop() {
  if (digitalRead(sensorPin) == HIGH)
  {
    digitalWrite(relayPin, HIGH);
  }
  if (digitalRead(inPin1 )== HIGH)
  {
    digitalWrite(relayPin, LOW);
  }
  if (digitalRead(inPin2) == HIGH)
  {
    digitalWrite(relayPin, HIGH);
  }
else
digitalWrite(relayPin, LOW);
}/code]

When I press inPin1 it momentarily stops the alarm but when I release the button it starts again. I want it to stop when I press inPin1 and start when I press inPin2...

You need a variable (let's call it alarmPermitted) which is nomally true. When you press the button your code will change it to false.

The alarm is only allowed to work if the variable is true.

...R

Stop posting new threads.

Read the answer I gave you in your last thread.
I told you it would not do what you wanted it to do.

Your problem is that the else only applies to the last if statement not to them all. Use braces to make the else cope with the states you want.

Stop crying to mom just because you don’t like the answer you get from dad.

Would this work?

const int inPin1 = 7;
const int inPin2 = 8;
const int relayPin = 12;
const int sensorPin = 2;

void setup() {
  // buttonpins as input
  pinMode(inPin1, INPUT);
  pinMode(inPin2, INPUT);
  // relay as output
  pinMode(relayPin, OUTPUT);
  //sensor as input
  pinMode(sensorPin, INPUT);
  // serial communications:
  Serial.begin(9600);
}

void loop() {
  // value of sensor
  int analogValue = digitalRead(sensorPin);
  int digitalValueA = digitalRead(inPin1);
  int digitalValueB = digitalRead(inPin2);

  // if sensor is turned on turn on alarm
  if (analogValue, HIGH)
  {
    delay(15000);
    digitalWrite(relayPin, HIGH);}
  else if (digitalValueA, HIGH && digitalValueB, LOW)
    digitalWrite(relayPin, LOW);
  else
    digitalWrite(relayPin, LOW);
  }[code]

@po2us: please stop posting the same stuff over again.
Thread locked