how do i include a "main" switch function

Hi all! , so i have been programming this but i ran unit some issue, what i am trying to do is to program a code for "automatic door with heat sensor to open/close the door.
The door itself has a main switch (button which will be pressed down to simulate the door is closed),which tells my program if the door is close or open.

#include <VirtualWire.h>
//define constant for the pin the sensor is connected to const int sensorPin = A1;

//room temperature in Celsius
const float threshold = 512;  //light sensor

const int sensorPin = A0; //for Temp sensor
const int sensorPin2 = A1; // for temp sensor 2nd
const int buttonPin = 5; //the "switch" or button for the door
int buttonState = 0; //for button state

const float baselineTemp = 26.0; //sensor temp base line

void setup()
{
  //Initialize the IO and ISR
  vw_setup(2000); // Bits per sec

  Serial.begin(9600);
  //open a serial connection to display values Serial.begin(9600);
  pinMode(buttonPin, INPUT); //push button for door

}

void loop()
{
  //read the value on Analog-in pin 0 and store it in a variable int sensorVal = analogRead(sensorPin);
  int sensorVal;

  int sensorTemp = analogRead(sensorPin); //created sensortemp to scan

  buttonState = digitalRead(buttonPin); //read the current button state

  //send the 10-bit sensor value to the serial port
  Serial.print("\n\nsensor value:");
  Serial.print(sensorVal);

  delay(1000);

  Serial.print("\n sensor value = ");
  Serial.print(sensorTemp);

  delay(1000);

  //convert thev sensor reading (0-1024) to voltage float voltage = (sensorVal/1024.0)*5.0;
  float voltage = (voltage - 0.5) * 100;
  float voltage2 = (voltage - 0.5) * 100;

  //send the voltage level to the serial port
  Serial.print("\n, Volts = ");
  Serial.print(voltage);
  delay(1000);

  Serial.print("\n, Temp Sensor Volts :");
  Serial.print(voltage2);
  Serial.print("\n, Degree C = ");
  float temperature = voltage * 50;
  Serial.print(temperature);
  delay(3000);

  if (buttonState == HIGH) //door is ini closed <<---
  {

    if (temperature < baselineTemp)
    {
      //send("0");
      Serial.println(", Doors Stays Close. ");
      delay(1000);
    }
    else if (temperature >= baselineTemp)
    {
      send("1");
      Serial.println(", Doors Opening ");
      delay(1000);
    }
    delay(1000);

  }
  else if (buttonState == LOW)
  {
    delay(3000); //delay for the door to close itself 4000-6000 4-6 sec
    if (temperature < baselineTemp)
    {
      send("0");
      Serial.println(" Doors Closing ");
      delay(1000);
    }
    else if (temperature >= baselineTemp)
    {
      //send("1");
      Serial.println("Doors Opening");
      delay(1000);
    }
    delay(1000);
  }

}
void send (char *message)
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // wait until the whole message is gone
}

transmitter.ino (2.37 KB)

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

Please explain exactly what you mean by “i ran unit some issue”.

i updated the code. sorry its my 1st time

Ok. Please answer the last question posed by @pert. What is the issue you are having? Don't just say it doesn't work. Describe the symptoms.

The Buttonstate does't seem to be working how i want it to, since its a "button switch" i was thinking if it was pressed down it will simulate the door is close. but from what i am testing the codes now, what i am getting is not "dependent" on the main switch (Buttonstate).

p.s this is the same button i am using "https://www.arduino.cc/en/tutorial/button"

PulseLeo:
The Buttonstate does't seem to be working how i want it to, since its a "button switch" i was thinking if it was pressed down it will simulate the door is close. but from what i am testing the codes now, what i am getting is not "dependent" on the main switch (Buttonstate).

p.s this is the same button i am using "https://www.arduino.cc/en/tutorial/button"

Say what? No, don't describe what you think the code is doing. Describe the symptom. Like "I think if the button is pushed down then the door should close but the door isn't closing" or something like that. What did you expect to happen and how does that differ from what actually happened.

pinMode(buttonPin, INPUT); //push button for door

I notice you don't use the internal pull-ups, so do you have an external pull-up or pull-down resistor on this button?
http://www.gammon.com.au/switches

I also notice that you’ve got a lot of delay calls in the code, so don’t expect it to be very responsive. You might have to hold the button for a long time before it gets back around to reading it again.

Delta_G:

pinMode(buttonPin, INPUT); //push button for door

I notice you don't use the internal pull-ups, so do you have an external pull-up or pull-down resistor on this button?
Gammon Forum : Electronics : Microprocessors : Switches tutorial

i do have a pull-down resistor connected to GND for my switch.As for the delay i will remove some of it.