Beep once when LDR is activated or deactivated.

I had this working on an UNO but for some reason does not work on Attiny85 as it should. What am I doing wrong?

 int PIR_Sensor_Pin0 = 0;      // PIR_Sensor1_Pin from passive Infra red 1
 int PIR_Sensor_Pin1 = 1;      // PIR_Sensor2_Pin  from passive Infra red 2
 int Piezo_Pin = 2;
 int inputPin = A2;          //Pin 3, to read 0-5volts
 int inputValue = 0;         //the value of the LDR pin
 int val = 0;                // variable for reading the PIR_Sensor_Pin status
 int val1 = 0;               // variable for reading the PIR_Sensor_Pin status
 int LED3 = 3;               // On when Passives armed
 boolean alreadyBeepedon = false;
 boolean alreadyBeepedoff = false;
 
 void setup() {
  pinMode(Piezo_Pin, OUTPUT);             // declare Piezo_Pin as output
  pinMode(PIR_Sensor_Pin0, INPUT_PULLUP); // declare PIR_Sensor_Pin as input
  pinMode(PIR_Sensor_Pin1, INPUT_PULLUP); // declare PIR_Sensor_Pin as input
  pinMode(LED3, OUTPUT);
 }
 void loop(){
  inputValue = analogRead(inputPin);  
   if (inputValue < 380){      //380 default
    digitalWrite(LED3, HIGH);    
   }
    else {
      digitalWrite(LED3, LOW); 
         //BEEP WHEN ON//
   if(digitalRead(LED3) == HIGH ) 
   {
  if(!alreadyBeepedon){
   digitalWrite(Piezo_Pin, HIGH);    
   delay(80);
   digitalWrite(Piezo_Pin, LOW);
   delay(500);
   alreadyBeepedon = true;}  
 }
    else {
   alreadyBeepedon = false;}
           //BEEP WHEN OFF//
    if(digitalRead(LED3) == LOW )
   {
  if(!alreadyBeepedoff){
   digitalWrite(Piezo_Pin, HIGH);    
   delay(80);
   digitalWrite(Piezo_Pin, LOW);
   delay(500);
   alreadyBeepedoff = true;}  
 }
    else {
   alreadyBeepedoff = false;}    
   }
 ////////////BEEP WHEN PASSIVE ACTIVATED////////////
   inputValue = analogRead(inputPin);
   val = digitalRead(PIR_Sensor_Pin0);  
  if (val == HIGH && digitalRead(LED3) == HIGH) {           
  digitalWrite(Piezo_Pin, HIGH);    
  delay(80);
  digitalWrite(Piezo_Pin, LOW);
  delay(80);
  digitalWrite(Piezo_Pin, HIGH);    
  delay(80);
  digitalWrite(Piezo_Pin, LOW);
  delay(80);
  digitalWrite(Piezo_Pin, HIGH);   
  delay(80);
  digitalWrite(Piezo_Pin, LOW);
  delay(10000);
    } 
  val1 = digitalRead(PIR_Sensor_Pin1);  
  if (val1 == HIGH && digitalRead(LED3) == HIGH) {                                    
  digitalWrite(Piezo_Pin, HIGH);   
  delay(80);
  digitalWrite(Piezo_Pin, LOW);
  delay(80);
  digitalWrite(Piezo_Pin, HIGH);    
  delay(80);
  digitalWrite(Piezo_Pin, LOW);
  delay(10000);
   }  
}

Please define "does not work". What is the program supposed to do? What does it actually do?

Hi, this code I supposed to do the following:

-2 sensor pins are connected to Passive infrared sensors on NC loop circuit.(Hence the pullup)
-Piezo(Buzzer) connected to pin 2 of Attiny85.
-A2 Analog input pin is connected to daylight sensor, value set to 0 in setup
-When analog value drops below value of 380 LED 3 must switch on and piezo must beep once to indicate its now activated.
-When Analog value exceeds value 380 LED 3 must switch off and piezo beep once. Indicate now off.
-The idea is only when its dark detection by the Passive infra red will indicate 2 or 3 audible beeps depending if its zone 1 or 2, when triggered, and only while the LED is on.
-This code works 100% on an UNO but on the ATtiny gives a few long beeps and then stops responding.

Hope this makes sense,,
Thanx :o

Hi, Does Attiny85 support Boolean functions?

Hi, Does Attiny85 support Boolean functions?

Of course it does!

Can you please format that code to make it a little more readable. Use control-T.

 int inputPin = A2;          //Pin 3, to read 0-5volts
 int inputValue = 0;         //the value of the LDR pin

inputPin is a useless name. Something meaningful, like LDRPin, that describes WHAT is connected to the pin is far more useful.

The same applies to the value variable. What is it a value of? Clearly, it is an input, but that name is too lame for words.

   else {
      digitalWrite(LED3, LOW);
         //BEEP WHEN ON//
   if(digitalRead(LED3) == HIGH )
   {

After writing the pin LOW, is it REALLY possible that the pin will read HIGH?

Your indenting is piss-poor, and your inconsistent place of curly braces makes your code VERY hard to read. Too hard for me to bother.

Put EVERY { on a line BY ITSELF. Use Tools + Auto Format. Post your code again.