Problems with upload of code from Arduino to ATtiny85

I am using the Arduino UNO as a programmer to program the ATtiny85 , but upon pressing the upload button the error message avrdude: stk500_getsync(): not in sync: resp=0x00 appears.

Here is my code:

//pin definitions
#define pingPin 3
#define buzzerPin 0
//constant definitions
#define DELAY_BEFORE_INITIAL 5000
#define ALARM_DISTANCE 35
#define BUZZER_FREQ 500
//variables
#include <Arduino.h>
#include <WProgram.h>
boolean alarm = false;
long currentDistance;
const int buttonPin1 = 4;
const int buttonPin2 = 2;
const int buttonPin3 = 1;
int buttonState;
int lastButtonState = LOW;

long lastDebounceTime = 0;
long debounceDelay = 50;

void setup() {
  //setup pins
  pinMode(buttonPin1,INPUT);
  pinMode(buttonPin2,INPUT);
  pinMode(buttonPin3,INPUT);
  pinMode(buzzerPin,OUTPUT);
  //delay before beginning loop
  delay(DELAY_BEFORE_INITIAL);
}

void loop()
{ 
   pinMode(pingPin, OUTPUT);
  if(!alarm)
  {
    
  //check distance
  long duration, distance;
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  pinMode(pingPin,INPUT);
  digitalWrite(pingPin, LOW);
  duration = pulseIn(pingPin, HIGH);
  distance = (duration/2) / 29.1;  
  //if distance is greater than ALARM_DISTANCE begin alarm
  if(distance>=ALARM_DISTANCE)
    alarm=true;
  }
  else{
    delay(BUZZER_FREQ);
    digitalWrite(buzzerPin, HIGH);
    delay(BUZZER_FREQ);
    digitalWrite(buzzerPin,LOW);
  }
}

That is usually a sign that there is a problem communicating with the target device. Have you set the fuses (burn the bootloader)? How have you got it connected up?

Does that code compile? I've never seen both Arduino.h and WProgram.h used simultaneously before. One is for IDE pre 1.0, the other for 1.0 and onwards.

in some case, you may need to trick the arduino and computer to work nicely with each other.

i've seen this on a few board; when you press the compile+upload button, press the reset button on the micro-controller.. after a few attempts and getting your timing right, you'll find it will upload. it also helps to have your verbose setting on for upload so you can see what is going on.. after you've connected once, you should not need to do the trick again for that session.

@dannable it does compile

@ardiri I can't seem to get the timing right is it reset 1st then upload or upload 1st then reset? Also not sure how to enable verbose.