Hi im currently trying to attach a servo motor which is used to actuate a spray that I will attach but im currently stuck on how I can make the servo motor's output dependent on the on or off state of the vibration sensor that I have attached. The vibration sensor is set to countdown for 24hrs before trigerring the servo motor to actuate the spray if the reset button or off switch is pushed but what basically happens is that the servo motor is not actually applying the conditions that I have put for it to work. This is the code. I think there is something wrong with my servo commands so im not quite sure as im not quite familiar to the commands yet any input or feedback is much appriciated to direct me on the right track thanks 
C-like:
//declaration of variables
#include <Servo.h> //servo library
Servo servo1;
int servoPin = 5;
int pos = 0;
int vibr = 3;
int green = 12;
int red = 11;
int buzzer = 4;
int pb1 = 5;
int buttonState = 0;
void setup() {
servo1.attach(servoPin); // sets the servo motor PIN
pinMode(vibr,INPUT);
pinMode(green,OUTPUT);
pinMode(red,OUTPUT);
pinMode(pb1, INPUT_PULLUP);
}
void loop() {
int val;
val=digitalRead(vibr);
if(val==1)
{
digitalWrite(green,HIGH);
delay(0);
digitalWrite(red,HIGH);
delay(2000); // both green and red for 24 hours represent the "danger timing".
bool value = digitalRead(vibr);
if (value == 0) {
servo1.write(180);
delay(1000);
servo1.detach();
delay (3000);
servo1.attach (servoPin);
servo1.write(0);
delay (1000);
}
delay(1000);
pinMode(buzzer,OUTPUT);
delay(0);
tone(buzzer, 1000);
delay(1000); // for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // for 1sec
}
else
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
}